In the past, our reducers were created like this before the createReducer
helper method was introduced:
export function reducer(state: AppState, action: Action) {
switch (action.type) {
case "[Category List] Add Category":
return { ...state, categories: [...state.categories, action.payload] };
default:
return baseReducer;
}
}
The default case covers actions that are common to all modules.
export function baseReducer(state, action){
//... COMMON CASES
}
Now, with the helper method, we can simplify it like this:
export const reducer = createReducer(
initialState,
on(addCategoryRequest, (state, { payload }) => {
return {
...state,
categories: payload
};
//HOW DO WE HANDLE DEFAULT TYPES NOW?
}
}
Any suggestions on handling default types?