Skip to content

Commit 5f50faa

Browse files
authored
Merge pull request #144 from canjs/143-assignDeep
assign deep should work recursively
2 parents 8bebe49 + 044ed8e commit 5f50faa

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

reflections/shape/shape-test.js

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -688,6 +688,21 @@ QUnit.test("each loops without needing `this`", function(){
688688
QUnit.ok(true, "no error");
689689
});
690690

691+
QUnit.test("assignDeepList", function(){
692+
var justin = {name: "Justin", age: 35},
693+
payal = {name: "Payal", age: 35};
694+
695+
var people = [justin, payal];
696+
shapeReflections.assignDeep(people, [
697+
{age: 36}
698+
]);
699+
700+
QUnit.deepEqual(people, [
701+
{name: "Justin", age: 36},
702+
{name: "Payal", age: 35}
703+
], "assigned right");
704+
});
705+
691706

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

reflections/shape/shape.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,12 @@ function updateDeepList(target, source, isAssign) {
319319
if( typeReflections.isPrimitive(curVal) || typeReflections.isPrimitive(newVal) || shouldUpdateOrAssign(curVal) === false ) {
320320
addPatch(patches, {index: index, deleteCount: 1, insert: [newVal]});
321321
} else {
322-
this.updateDeep(curVal, newVal);
322+
if(isAssign === true) {
323+
this.assignDeep(curVal, newVal);
324+
} else {
325+
this.updateDeep(curVal, newVal);
326+
}
327+
323328
}
324329
}, this);
325330
// add items at the end

0 commit comments

Comments
 (0)