Skip to content

Instantly share code, notes, and snippets.

View dpalita's full-sized avatar

David Palita dpalita

View GitHub Profile
@dpalita
dpalita / medium-ngrx-reducer-class.ts
Last active August 2, 2018 20:33
Use a Injectable() class as a factory for your reducers
@Injectable()
export class AccountReducer {
// with real DI inside
constructor (private usefulService: UsefulService) {}
createReducer() {
// handle specific action with the help of your injected service and return new states, this is the pure reducer function
return (state: AccountState, action: Action) => {
if(action.type === 'SomethingUseful' /* or better still action instanceof SomethingUsefulAction, but this makes for another post ;-)*/) {
return {...state, {useful: this.usefulService.something(action.payload)}}
@dpalita
dpalita / medium-ngrx-reducer-provider.ts
Last active August 2, 2018 20:37
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)
i18n.ActivityStatus={value, select, other {unknown}\
COMPLETED {Completed}\
DUE_TODAY {Due today}\
OVERDUE {Overdue}\
PENDING {Pending}\
}
# Usage : {{'i18n.ActivityStatus' | translate:{value: activity.status} }}