Skip to content

Instantly share code, notes, and snippets.

@MeetMartin
Last active April 17, 2019 09:01
Show Gist options
  • Save MeetMartin/2789a476af780905b54f8102dcfc1c44 to your computer and use it in GitHub Desktop.
Save MeetMartin/2789a476af780905b54f8102dcfc1c44 to your computer and use it in GitHub Desktop.
// src/store/reducers.js
import match from 'conditional-expression';
const initialState = {
something: 'data',
somethingElse: 'also data'
};
const types = {
TRIGGER_ACTION: 'TRIGGER_ACTION'
}; // types could be in a separate file
const reducer = (state = initialState, action) =>
match(action.type)
.equals(types.TRIGGER_ACTION)
.then({...state, something: action.payload})
.equals(types.DIFFERENT_ACTION)
.then({...state, somethingElse: action.payload}
.else(state);
export {initialState, types, reducer};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment