DEV Community

loading...

Discussion on: Reusing ngrx reducers using higher-order functions

Collapse
alejojm profile image
Alejo Jm

hello this was awesome thanks... but when i publish the prod app i get this error:


Consider changing the function expression into an exported function.

the reducer:

export function reducerWithName(name: string) {
  return function reducer(state: State, action: ComponentActions): State {
    return ... do something using name 
  };
}

the module:

imports: [
     StoreModule.forFeature('user', fromReducer.reducerWithName('user')),
]

I'm unable to compile de prod project :-(
Thanks

Collapse
joanllenas profile image
Joan Llenas Masó Author

Have a look at this modified stackblitz example where I'm using InjectionToken to inject the reducers: stackblitz.com/edit/angular-3yguzm...
Interesting files are: reducers.ts and app.module.ts

Hope this fixes the issue.
Cheers!

Collapse
alejojm profile image
Alejo Jm

Yeah !!!! cheers awesome