Slide 28
Slide 28 text
Grouped Reducer
standard way
const featureReducer = createReducer (
initialState,
on(loadNominees, (state) ({ …state, loading: LoadingState. LOADING, error: null })),
on(nomineesLoaded, (state, { nominees }) ({ …state, loading: LoadingState.SUCCESSFUL, nominees })),
on(nomineesLoadFailed, (state, { error }) ({ …state, loading: LoadingState.FAILED, error }))
);
export function nomineeReducer(state: NomineeState, action: Action): NomineeState {
return featureReducer(state, action);
}
grouped reducer
const successReducer = createReducer (
initialState,
on(nomineesLoaded, (state, { nominees }) ({ …state, loading: LoadingState.SUCCESSFUL, nominees })));
export function nomineeReducer(state: NomineeState, action: Action): NomineeState {
return createGroupedReducer(initialState, actions, { successReducer })(state, action);
}
@meeroslav