Created
January 9, 2019 13:18
-
-
Save fxlrnrpt/ea6916d17f771ed2d8035825eb3c1739 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) { | |
| return { | |
| type: this.constructor.type, | |
| payload, | |
| 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