4

I'm trying to use this reducer from ReduxJs site with NgRx and Angular Cli:

function createFilteredReducer(reducerFunction, reducerPredicate) {
    return (state, action) => {
        const isInitializationCall = state === undefined;
        const shouldRunWrappedReducer = reducerPredicate(action) || isInitializationCall;
        return shouldRunWrappedReducer ? reducerFunction(state, action) : state;
    }
}

But I'm getting this error with prod build:

ERROR in app/app.module.ts(504,29): Error during template compile of 'AppModule' Function expressions are not supported in decorators in 'reducers' 'reducers' contains the error at app/reducers/index.ts(106,9) Consider changing the function expression into an exported function.

Do you have any ideas how can I achieve this functionality with a code that compiles in prod mode?

bucicimaci
  • 1,261
  • 1
  • 9
  • 17

1 Answers1

0

Solved it with help of a friend. try :

export function createFilteredReducer(reducerFunction, reducerPredicate) {

at app.module

import { StoreModule, ActionReducerMap, State } from '@ngrx/store';
import { StoreDevtoolsModule } from '@ngrx/store-devtools';
import { createFilteredReducer} from './redux/reducer';


imports: [
    ...
    StoreModule.forRoot({ createFilteredReducer}),
    StoreDevtoolsModule.instrument({
      maxAge: 25 //  Retains last 25 states
    })
  ]
Tzvi Gregory Kaidanov
  • 3,080
  • 3
  • 26
  • 33