Created
January 5, 2019 23:16
-
-
Save aigoncharov/8ff2ee921993751096f30f7d8d318afc 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 CatsGetInit {} | |
class CatsGetSuccess { | |
constructor(responseData) { | |
this.payload = responseData | |
} | |
} | |
class CatsGetError { | |
constructor(error) { | |
this.payload = error | |
this.error = true | |
} | |
} | |
const reducerCatsInitialState = { | |
error: undefined, | |
data: undefined, | |
loading: false, | |
} | |
const reducerCats = (state = reducerCatsInitialState, action) => { | |
switch (action.constructor) { | |
case CatsGetInit: | |
return { | |
...state, | |
loading: true, | |
} | |
case CatsGetSuccess: | |
return { | |
error: undefined, | |
data: action.payload, | |
loading: false, | |
} | |
case CatsGetError: | |
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