Last active
January 29, 2017 15:08
-
-
Save Darmikon/248dea24d2c7b166b17088eb91640e66 to your computer and use it in GitHub Desktop.
How to update deep nested structures in redux without headache with https://github.com/kolodny/immutability-helper
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
var src = { | |
obj: { | |
nestedArr: [ | |
{ | |
string: 'str_before' | |
} | |
] | |
}, | |
arr: [ | |
{ | |
num: 2 | |
} | |
] | |
} | |
console.log(update(src,{ | |
arr: { | |
0: { | |
num: { | |
$set: src.arr[0].num + 666 | |
} | |
} | |
}, | |
obj: { | |
nestedArr: { | |
0: { | |
string: { | |
$set: src.obj.nestedArr[0].string + '_after' | |
} | |
} | |
} | |
} | |
})); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment