Created
May 30, 2018 18:20
-
-
Save wesleygrimes/3cb221e1c0525bc09959327c3c2cb263 to your computer and use it in GitHub Desktop.
Entity Feature Store Module - Reducer
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
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