Skip to content

Instantly share code, notes, and snippets.

@codeBelt
Last active November 6, 2019 14:01
Show Gist options
  • Save codeBelt/d89eda0e80eca7274566cf3f484b5b38 to your computer and use it in GitHub Desktop.
Save codeBelt/d89eda0e80eca7274566cf3f484b5b38 to your computer and use it in GitHub Desktop.
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,
}
}
}
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