Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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