Skip to content

Instantly share code, notes, and snippets.

@maxired
Last active August 5, 2017 11:21
Show Gist options
  • Save maxired/52997a622aa912e8b6c5071697882327 to your computer and use it in GitHub Desktop.
Save maxired/52997a622aa912e8b6c5071697882327 to your computer and use it in GitHub Desktop.
immutable reducer
switch (action.type) {
case ADD_NEW_AVAILABLE_COLOR_TO_CAR:{
const { color, model, manufacturer } = action.payload
return {...state, manufacturer: {
...state.manufacturer, [manufacturer]:
{...state.manufacturers[manufacturers], models:
{...state.manufacturers[manufacturers].models, [model]:
{...state.manufacturers[manufacturers].models[model], options:
{...state.manufacturers[manufacturers].models[model].options, colors:
{...state.manufacturers[manufacturers].models[model].options.colors, [color]: true}
}
}
}
}
}
default: return state
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment