Last active
November 6, 2019 14:01
-
-
Save codeBelt/d89eda0e80eca7274566cf3f484b5b38 to your computer and use it in GitHub Desktop.
This file contains 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
export default class ShowsReducer extends BaseReducer { | |
initialState = { | |
currentShowId: '74', | |
show: null, | |
episodes: [], | |
actors: [], | |
}; | |
[ShowsAction.REQUEST_SHOW_FINISHED](state, action) { | |
return { | |
...state, | |
show: action.payload, | |
} | |
} | |
[ShowsAction.REQUEST_EPISODES_FINISHED](state, action) { | |
return { | |
...state, | |
episodes: action.payload, | |
} | |
} | |
[ShowsAction.REQUEST_CAST_FINISHED](state, action) { | |
return { | |
...state, | |
actors: action.payload, | |
} | |
} | |
} |
This file contains 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
export default class BaseReducer { | |
initialState = {}; | |
reducer = (state = this.initialState, action) => { | |
const method = this[action.type]; | |
if (!method || action.error) { | |
return state; | |
} | |
return method.call(this, state, action); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment