Skip to content

Instantly share code, notes, and snippets.

@codeBelt
Last active November 18, 2019 20:45
Show Gist options
  • Save codeBelt/9d183e2be52885f65826042fc4f6c228 to your computer and use it in GitHub Desktop.
Save codeBelt/9d183e2be52885f65826042fc4f6c228 to your computer and use it in GitHub Desktop.
const dictionary = {};
// Add keys to the dictionary
dictionary['REQUEST_SHOW_FINISHED'] = (state, payload) => {
return {
...state,
show: payload,
}
};
dictionary['REQUEST_EPISODES_FINISHED'] = (state, payload) => {
return {
...state,
episodes: payload,
}
};
dictionary['REQUEST_CAST_FINISHED'] = (state, payload) => {
return {
...state,
actors: payload,
}
};
// Usage
const newState = dictionary[action.type](state, action.payload); // Warning: This will break if the action.type is not found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment