diff --git a/can-stache-key-test.js b/can-stache-key-test.js index 8a66ad4..7e8610e 100644 --- a/can-stache-key-test.js +++ b/can-stache-key-test.js @@ -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}); +}); diff --git a/can-stache-key.js b/can-stache-key.js index 586b3ba..8b13eb8 100644 --- a/can-stache-key.js +++ b/can-stache-key.js @@ -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; } - } } ],