Skip to content

Commit

Permalink
Merge pull request #221 from WearyMonkey/roam7
Browse files Browse the repository at this point in the history
Passing correct remove parameter down in merge.
  • Loading branch information
daffl committed Jan 4, 2013
2 parents 8272947 + d67dccc commit 8d751dd
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
4 changes: 2 additions & 2 deletions observe/observe.js
Expand Up @@ -822,7 +822,7 @@ steal('can/util','can/construct', function(can) {
self = this,
newVal;
Observe.startBatch();
this.each(function(curVal, prop, toRemove){
this.each(function(curVal, prop){
newVal = props[prop];

// If we are merging...
Expand All @@ -843,7 +843,7 @@ steal('can/util','can/construct', function(can) {
self._set(prop, newVal)
}
else if ( canMakeObserve(curVal) && canMakeObserve(newVal) ) {
curVal.attr(newVal, toRemove)
curVal.attr(newVal, remove)
} else if ( curVal != newVal ) {
self._set(prop, newVal)
}
Expand Down
27 changes: 26 additions & 1 deletion observe/observe_test.js
Expand Up @@ -140,11 +140,36 @@ test("attr does not blow away old observable", function(){
}
});
var oldCid = state.attr("properties.brand")._cid;
state.attr({properties:{brand:[]}});
state.attr({properties:{brand:[]}}, true);
same(state.attr("properties.brand")._cid, oldCid, "should be the same observe, so that views bound to the old one get updates")
equals(state.attr("properties.brand").length, 0, "list should be empty");
});

test("sub observes respect attr remove parameter", function() {
var bindCalled = 0,
state = new can.Observe({
monkey : {
tail: 'brain'
}
});

state.bind("change", function(ev, attr, how, newVal, old){
bindCalled++;
equals(attr, "monkey.tail");
equals(old, "brain");
equals(how, "remove");
});

state.attr({monkey: {}});
equals("brain", state.attr("monkey.tail"), "should not remove attribute of sub observe when remove param is false");
equals(0, bindCalled, "remove event not fired for sub observe when remove param is false");

state.attr({monkey: {}}, true);

equals(undefined, state.attr("monkey.tail"), "should remove attribute of sub observe when remove param is false");
equals(1, bindCalled, "remove event fired for sub observe when remove param is false");
});

test("remove attr", function(){
var state = new can.Observe({
properties : {
Expand Down

0 comments on commit 8d751dd

Please sign in to comment.