Skip to content

Instantly share code, notes, and snippets.

@weslleyaraujo
Created December 21, 2016 17:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save weslleyaraujo/d0e8063e6082c7ec5c26483aecc0e394 to your computer and use it in GitHub Desktop.
Save weslleyaraujo/d0e8063e6082c7ec5c26483aecc0e394 to your computer and use it in GitHub Desktop.
const lightenPad = createAction(LIGHTEN_PAD);
const lightenOffPad = createAction(LIGHTEN_OFF_PAD);
lightenPad({ id: 'green' }); // { type: 'LIGHTEN_PAD', payload: { id: 'green' } };
lightenOffPad(); // { type: 'LIGHTEN_OFF_PAD', payload: {} };
function pads(state, action) {
const { type, payload } = action;
switch(type) {
case LIGHTEN_PAD:
return state.map(b => ({
...b,
active: payload.id === b.id,
}));
case LIGHTEN_OFF_PAD:
return state.map(b => ({
...b,
active: false,
}));
default:
return state;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment