Skip to content

Instantly share code, notes, and snippets.

@theshock
Last active March 28, 2016 15:48
Show Gist options
  • Save theshock/9b8e50a0140bd1e2507b to your computer and use it in GitHub Desktop.
Save theshock/9b8e50a0140bd1e2507b to your computer and use it in GitHub Desktop.
// from
[UPDATE_ENTITY_EDITABLE_LOADING]: (state, { data: { entityId, editableFieldName }}) => ({
items: state.items.map(item => item.Id === entityId
? { ...item, [`loading${editableFieldName}`]: true }
: item),
error: null
})
// to
[UPDATE_ENTITY]: (state, { data: { filterItemCallback, field, value }}) => ({
items: state.items.map(item =>
filterItemCallback(item)
? { ...item, [field]: value }
: item),
error: null
})
// or, maybe:
[UPDATE_ENTITY]: (state, { data: { searchParams, changes }}) => ({
items: state.items.map(item =>
_.isMatch(searchParams, item) // https://lodash.com/docs#isMatch
? { ...item, ...changes }
: item),
error: null
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment