Skip to content

Instantly share code, notes, and snippets.

@johnsylvain
Created January 13, 2018 14:10
Show Gist options
  • Save johnsylvain/bb0fee8d9e1e960d97acce8559c48cb2 to your computer and use it in GitHub Desktop.
Save johnsylvain/bb0fee8d9e1e960d97acce8559c48cb2 to your computer and use it in GitHub Desktop.
Shallow `Object.assign` fill-in
const assign = (obj, ...props) => props.reduce((acc, prop) => {
for (let i in prop) acc[i] = prop[i]
return acc
}, obj)
// Usage
const state = {
todos: [
{ text: 'one' }
],
current: ''
}
const newState = assign(
{},
state,
{
todos: state.todos.concat({ text: 'two' })
}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment