Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

assignDeep copy plain objects values instead of reference #151

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
7 changes: 7 additions & 0 deletions reflections/shape/shape-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -711,6 +711,13 @@ QUnit.test("assignDeepList", function(){
], "assigned right");
});

QUnit.test("assignDeep copy #150", function() {
var obj = {};
var objMap = {prop: { foo: 'bar' }};
shapeReflections.assignDeep(obj, objMap);
QUnit.notEqual(obj.prop, objMap.prop, "copy without referencing");
});


/*QUnit.test("getAllEnumerableKeys", function(){

Expand Down
8 changes: 7 additions & 1 deletion reflections/shape/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,13 @@ shapeReflections = {
shapeReflections.eachKey(source, function(newVal, key){
if(!hasOwnKey(key)) {
// set no matter what
getSetReflections.setKeyValue(target, key, newVal);
if (typeReflections.isMapLike(newVal)) {
// newVal needs to be serialized to make sure
// the value is copied not referenced
getSetReflections.setKeyValue(target, key, shapeReflections.serialize(newVal));
} else {
getSetReflections.setKeyValue(target, key, newVal);
}
} else {
var curVal = getKeyValue.call(target, key);

Expand Down