Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save wesleygrimes/3cb221e1c0525bc09959327c3c2cb263 to your computer and use it in GitHub Desktop.
Save wesleygrimes/3cb221e1c0525bc09959327c3c2cb263 to your computer and use it in GitHub Desktop.
Entity Feature Store Module - Reducer
import { Actions, ActionTypes } from './actions';
import { featureAdapter, initialState, State } from './state';
export function featureReducer(state = initialState, action: Actions): State {
switch (action.type) {
case ActionTypes.LOAD_REQUEST: {
return {
...state,
isLoading: true,
error: null
};
}
case ActionTypes.LOAD_SUCCESS: {
return featureAdapter.addAll(action.payload.items, {
...state,
isLoading: false,
error: null
});
}
case ActionTypes.LOAD_FAILURE: {
return {
...state,
isLoading: false,
error: action.payload.error
};
}
default: {
return state;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment