Created
January 5, 2019 23:16
-
-
Save fxlrnrpt/a64ad39c55e3b393b0c692b178c1a744 to your computer and use it in GitHub Desktop.
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 reducerLoading = (actionInit, actionSuccess, actionError) => ( | |
| state = false, | |
| action, | |
| ) => { | |
| switch (action.type) { | |
| case actionInit.type: | |
| return true | |
| case actionSuccess.type: | |
| return false | |
| case actionError.type: | |
| return false | |
| } | |
| } | |
| class CatsGetInit extends ActionStandard {} | |
| class CatsGetSuccess extends ActionStandard {} | |
| class CatsGetError extends ActionStandard {} | |
| const reducerCatsData = (state = undefined, action) => { | |
| switch (action.type) { | |
| case CatsGetSuccess.type: | |
| return action.payload | |
| default: | |
| return state | |
| } | |
| } | |
| const reducerCatsError = (state = undefined, action) => { | |
| switch (action.type) { | |
| case CatsGetError.type: | |
| return action.payload | |
| default: | |
| return state | |
| } | |
| } | |
| const reducerCats = combineReducers({ | |
| data: reducerCatsData, | |
| loading: reducerLoading(CatsGetInit, CatsGetSuccess, CatsGetError), | |
| error: reducerCatsError, | |
| }) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment