Skip to content

Instantly share code, notes, and snippets.

@mweststrate
Created January 9, 2018 08:28
Show Gist options
  • Save mweststrate/2bcc533b5a928971a4c86023447c05ec to your computer and use it in GitHub Desktop.
Save mweststrate/2bcc533b5a928971a4c86023447c05ec to your computer and use it in GitHub Desktop.
immer-producer-3
// Shortened, based on: https://github.com/reactjs/redux/blob/master/examples/shopping-cart/src/reducers/products.js
const byId = (state, action) => {
switch (action.type) {
case RECEIVE_PRODUCTS:
return {
...state,
...action.products.reduce((obj, product) => {
obj[product.id] = product
return obj
}, {})
}
default:
return state
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment