Created
October 6, 2016 16:24
-
-
Save kirilloid/04f37b3b83276dc53b794f87bfb5b148 to your computer and use it in GitHub Desktop.
Revisions
-
kirilloid created this gist
Oct 6, 2016 .There are no files selected for viewing
This file contains hidden or 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 charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,21 @@ function assingImmutable(obj, toAdd) { if (!_.isObjectLike(toAdd)) { return toAdd; } key = _.first(path); if (_.isArray(obj)) { copy = _.slice(obj); toAdd.forEach(function (value, idx) { copy[idx] = assingImmutable(obj[idx], value); }); return copy; } else if (_.isObject(obj)) { copy = _.clone(obj); Object.keys(toAdd).forEach(function (key) { copy[key] = assingImmutable(obj[key], toAdd[key]); }); return copy; } else { return toAdd; } }