Skip to content

Commit

Permalink
improves performance for #36
Browse files Browse the repository at this point in the history
  • Loading branch information
justinbmeyer committed Jun 19, 2018
1 parent 807da50 commit 7458bfc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
9 changes: 9 additions & 0 deletions can-stache-key-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,3 +310,12 @@ QUnit.test("objHasKeyAtIndex doesn't handle non-object types correctly (#33)", f
QUnit.equal(result.parent, 47);
QUnit.equal(result.parentHasKey, true);
});

QUnit.test("write to an object", function(){
var obj = {};
observeReader.write(obj,"value",1);
QUnit.deepEqual(obj,{value: 1});
obj = {value: null};
observeReader.write(obj,"value",1);
QUnit.deepEqual(obj,{value: 1});
});
5 changes: 2 additions & 3 deletions can-stache-key.js
Original file line number Diff line number Diff line change
Expand Up @@ -252,15 +252,14 @@ observeReader = {
write: function(base, prop, newVal){
var propValue = base[prop];
// if newVal is observable object, lets try to update
if(canReflect.isMapLike(propValue) && newVal && typeof newVal === "object") {
if(newVal != null && typeof newVal === "object" && canReflect.isMapLike(propValue) ) {
dev.warn("can-stache-key: Merging data into \"" + prop + "\" because its parent is non-observable");
canReflect.update(propValue, newVal);
} else if(canReflect.isValueLike(propValue) && canReflect.isObservableLike(propValue)){
} else if(propValue != null && propValue[setValueSymbol] !== undefined){
canReflect.setValue(propValue, newVal);
} else {
base[prop] = newVal;
}

}
}
],
Expand Down

0 comments on commit 7458bfc

Please sign in to comment.