Last active
February 11, 2019 19:01
-
-
Save aigoncharov/68148695ddaf0ef61d7ed34f3a4d566e 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' | |
const reducerJediInitialState = { | |
loading: false, | |
// List of our jedi | |
data: [], | |
error: undefined, | |
} | |
const reducerJedi = (state = reducerJediInitialState, action) => { | |
switch (action.type) { | |
case actionTypeJediCreateInit: | |
return { | |
...state, | |
loading: true, | |
} | |
case actionTypeJediCreateSuccess: | |
return { | |
loading: false, | |
data: [...state.data, action.payload], | |
error: undefined, | |
} | |
case actionTypeJediCreateError: | |
return { | |
...state, | |
loading: false, | |
error: action.payload, | |
} | |
default: | |
return state | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment