Skip to content

Instantly share code, notes, and snippets.

@dpalita
Last active August 2, 2018 20:37
Show Gist options
  • Save dpalita/401df5f840d28f644d2c33ed0941d1ed to your computer and use it in GitHub Desktop.
Save dpalita/401df5f840d28f644d2c33ed0941d1ed to your computer and use it in GitHub Desktop.
Use an injection token to provide your DI enabled reducer function
export const ACCOUNT_REDUCER_TOKEN = new InjectionToken<ActionReducer<Map<string, Account>>>('Account state reducer')
export function accountReducerFactory(accountReducer: AccountReducer): ActionReducer<Map<string, Account>> {
// here you create a reducer function with access to other managed services
return accountReducer.createReducer()
}
@NgModule({
imports: [
StoreModule.forFeature('account', ACCOUNT_REDUCER_TOKEN)
],
providers: [
{
provide: ACCOUNT_REDUCER_TOKEN,
// here your AccountReducer class will be instantiated with its deps injected
deps: [AccountReducer],
useFactory: accountReducerFactory
}
]
})
export class AccountModule {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment