Last active
January 9, 2019 13:18
-
-
Save fxlrnrpt/1cdc495fff27e8dc0359fd8f5048332e 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
| class ActionStandard { | |
| get static type () { | |
| return `prefix/${this.name}` | |
| } | |
| constructor(payload) { | |
| this.type = this.constructor.type | |
| this.payload = payload | |
| this.error = payload instanceof Error | |
| } | |
| } | |
| class CatsGetInit extends ActionStandard {} | |
| class CatsGetSuccess extends ActionStandard {} | |
| class CatsGetError extends ActionStandard {} | |
| const reducerCatsInitialState = { | |
| error: undefined, | |
| data: undefined, | |
| loading: false, | |
| } | |
| const reducerCats = (state = reducerCatsInitialState, action) => { | |
| switch (action.type) { | |
| case CatsGetInit.type: | |
| return { | |
| ...state, | |
| loading: true, | |
| } | |
| case CatsGetSuccess.type: | |
| return { | |
| error: undefined, | |
| data: action.payload, | |
| loading: false, | |
| } | |
| case CatsGetError.type: | |
| return { | |
| ...data, | |
| error: action.payload, | |
| loading: false, | |
| } | |
| default: | |
| return state | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment