Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to register single reducer using StoreModule.forFeature with ngrx 8.0.0 beta

in my feature module, im using the createReducer method to create my reducer as follow:

export const reducer = createReducer(
new InitState(),
on(loadData, state => {
return {
...state,
isLoading: true
};
})
);

but when i register the above reducer in the module class as following:

StoreModule.forFeature('my-module', reducer),

im getting the following error when compiling the project:

ERROR myModule.module.ts(38,47): Error during template compile of 'MyModuleModule' Function calls are not supported in decorators but 'createReducer' was called in 'reducer' 'reducer' calls 'createReducer' at myreducer.reducer.ts(14,24).

Does anyone know what might go wrong? or how do i register single reducer, because all the examples i have seen are using combineReducers with multiple reducers, and i wonder if for just one reducer, how do we do it?

Thank you much!

like image 337
Long Avatar asked Jan 23 '26 12:01

Long


1 Answers

You need to wrap your reducer so that it is compatible with AOT compilation:

export function myAOTSafeReducer(
    state: State | undefined,
    action: Action
) {
    return reducer(state, action);
}

Then refer to this exported named function in the state.

like image 171
codephobia Avatar answered Jan 26 '26 02:01

codephobia