Last active
August 2, 2018 20:37
-
-
Save dpalita/401df5f840d28f644d2c33ed0941d1ed to your computer and use it in GitHub Desktop.
Use an injection token to provide your DI enabled reducer function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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