Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
14 changes: 10 additions & 4 deletions reflections/shape/shape.js
Original file line number Diff line number Diff line change
Expand Up @@ -813,18 +813,24 @@ shapeReflections = {
return target;
},
assignDeepMap: function(target, source) {

var hasOwnKey = fastHasOwnKey(target);
var getKeyValue = target[getKeyValueSymbol] || shiftedGetKeyValue;
var setKeyValue = target[setKeyValueSymbol] || shiftedSetKeyValue;

shapeReflections.eachKey(source, function(newVal, key){
if(!hasOwnKey(key)) {
// set no matter what
getSetReflections.setKeyValue(target, key, newVal);
// Plain objects needs to be serialized to make sure
// newVal is copied not referenced #150
if (typeReflections.isMapLike(newVal) && !typeReflections.isObservableLike(newVal)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This won't solve the original issue since it was using a DefineMap. Is that being handled somewhere else?

getSetReflections.setKeyValue(target, key, shapeReflections.serialize(newVal));
} else {
// set no matter what
getSetReflections.setKeyValue(target, key, newVal);
}
} else {
var curVal = getKeyValue.call(target, key);

// if either was primitive, no recursive update possible
if(newVal === curVal) {
// do nothing
Expand Down