Created
January 13, 2018 14:10
-
-
Save johnsylvain/bb0fee8d9e1e960d97acce8559c48cb2 to your computer and use it in GitHub Desktop.
Shallow `Object.assign` fill-in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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