Platform: Add documentation on combineReducers

Created on 9 Jul 2018  路  7Comments  路  Source: ngrx/platform

Why there is no mention in documentation about combineReducers function?
Is it deprecated or what?
In redux world it seem to be quite popular approach to break complex reducers into smaller ones.
I know that there is ActionReducerMap but, if I'm not mistaken it is for combining feature reducers into root reducer. What I want to do is to break my feature reducer into smaller reducers, that handle slice of feature state.

Accepting PRs Docs Store

Most helpful comment

Its not deprecated but seems like using combineReducers hinders with AOT

All 7 comments

Hey @anth-git,
The combineReducers function is not depreciated. It is a common technique used in redux and explained in detail here.
The only difference in the function provided by @ngrx/store is, that it takes an initialState argument as second parameter.

Like @mgred mentioned the combineReducers function is not deprecated.
It's used internally within the ngrx/store when you use StoreModule.forRoot or StoreModule.forFeature, that's why you probably won't need it (and isn't documented).

For example:
If you declare your reducers as:

export const reducers = {
  foo: fooReducer,
  bar: barReducer,
};

And pass this reducer object when you import the store module:

StoreModule.forRoot(reducers),

The reducers object will be passed to the combineReducers function.

It is mentioned in the example app app.module.ts#L42.

As @timdeschryver mentioned, you probably won't need it. If you want to provide your own version of combineReducers, you can always override the built-in one with the reducerFactory configuration option which is not documented also.

Its not deprecated but seems like using combineReducers hinders with AOT

Hi there,
considering that I didn't find any example,
I post this simple one
`import { combineReducers } from '@ngrx/store';

import {
userAddressesReducer,
UserAddressesState,
initialUserAddressesState
} from './user-addresses.reducer';
import { userProfileReducer, UserProfileState, initialUserProfileState } from './user-profile.reducer';

export interface UserState {
addresses: UserAddressesState;
profile: UserProfileState;
}

export const initialUserState: UserState = {
addresses: initialUserAddressesState,
profile: initialUserProfileState,
};

export const userReducer = combineReducers(
{
addresses: userAddressesReducer,
profile: userProfileReducer
},
initialUserState
);
`

BTW what's better ActionReducerMap or combineReducers ?
Thanks in advance

I wonder why the documentation for combineReducers is missing? I need combineReducers for a two level structure, so some common code logic can be reused. CombineReducers is really important for more complex real world problems

It's really pity that this function has not been documented yet. In my app, I need a multilevel reducer tree, to break complex state handling into multiple reducers. This is not achievable via StoreModule.forFeature(), because it only lets to register top-level child reducers - this does not help with multilevel scenarios.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

dollyshah-02-zz picture dollyshah-02-zz  路  3Comments

brandonroberts picture brandonroberts  路  3Comments

Matmo10 picture Matmo10  路  3Comments

oxiumio picture oxiumio  路  3Comments

NathanWalker picture NathanWalker  路  3Comments