Created
February 11, 2019 19:02
-
-
Save fxlrnrpt/d87e5d0ce53a62648ef9d3b321d797b3 to your computer and use it in GitHub Desktop.
Reducer organization - taking a step further
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
| const actionTypeJediCreateInit = 'jedi-app/jedi-create-init' | |
| const actionTypeJediCreateSuccess = 'jedi-app/jedi-create-success' | |
| const actionTypeJediCreateError = 'jedi-app/jedi-create-error' | |
| class ReducerJedi { | |
| initialState = { | |
| loading: false, | |
| data: [], | |
| error: undefined, | |
| } | |
| @Action(actionTypeJediCreateInit) | |
| startLoading(state) { | |
| return { | |
| ...state, | |
| loading: true, | |
| } | |
| } | |
| @Action(actionTypeJediCreateSuccess) | |
| addNewJedi(state, action) { | |
| return { | |
| loading: false, | |
| data: [...state.data, action.payload], | |
| error: undefined, | |
| } | |
| } | |
| @Action(actionTypeJediCreateError) | |
| error(state, action) { | |
| return { | |
| ...state, | |
| loading: false, | |
| error: action.payload, | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment