Created
May 30, 2014 23:35
-
-
Save sebmarkbage/005c81e6f2f5ddac443f to your computer and use it in GitHub Desktop.
Deep Immutable Mutation Using Spread Operator
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
// Mutative | |
company.users.push({ name: 'New User' }); | |
return company; | |
// Immutable | |
return { ...company, users: [ ...company.users, { name: 'New User' } ] }; | |
// Implicit identifier | |
return { ...company, users: [ ... , { name: 'New User' } ] }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment