Skip to content

Commit

Permalink
Computed observables used for bindings (identified by having a dispos…
Browse files Browse the repository at this point in the history
…eWhenNodeIsRemoved option) won't respond to "dirty" events. This prevents conflicting bindings from causing recursive updates.
  • Loading branch information
mbest committed Jun 4, 2015
1 parent 72d5c43 commit a0134f5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
7 changes: 4 additions & 3 deletions spec/asyncBindingBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,13 @@ describe("Deferred bindings", function() {
expect(testNode.childNodes[0].childNodes[targetIndex]).not.toBe(itemNode); // node was create anew so it's not the same
});

it('Should throw an exception for value binding on multiple select boxes', function() {
it('Should not throw an exception for value binding on multiple select boxes', function() {
testNode.innerHTML = "<select data-bind=\"options: ['abc','def','ghi'], value: x\"></select><select data-bind=\"options: ['xyz','uvw'], value: x\"></select>";
var observable = ko.observable();
ko.applyBindings({ x: observable }, testNode);
expect(function() {
ko.applyBindings({ x: observable }, testNode);
jasmine.Clock.tick(1);
}).toThrowContaining('Too much recursion');
}).not.toThrow();
expect(observable()).not.toBeUndefined(); // The spec doesn't specify which of the two possible values is actually set
});
});
9 changes: 9 additions & 0 deletions spec/defaultBindings/valueBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -510,6 +510,15 @@ describe('Binding: Value', function() {
expect(dropdown.selectedIndex).toEqual(2);
});

it('Should not throw an exception for value binding on multiple select boxes', function() {
testNode.innerHTML = "<select data-bind=\"options: ['abc','def','ghi'], value: x\"></select><select data-bind=\"options: ['xyz','uvw'], value: x\"></select>";
var observable = ko.observable();
expect(function() {
ko.applyBindings({ x: observable }, testNode);
}).not.toThrow();
expect(observable()).not.toBeUndefined(); // The spec doesn't specify which of the two possible values is actually set
});

describe('Using valueAllowUnset option', function () {
it('Should display the caption when the model value changes to undefined, null, or \"\" when using \'options\' binding', function() {
var observable = ko.observable('B');
Expand Down
2 changes: 1 addition & 1 deletion src/subscribables/dependentObservable.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ ko.computed = ko.dependentObservable = function (evaluatorFunctionOrOptions, eva
}

function subscribeToDependency(target) {
if (target._deferUpdates) {
if (target._deferUpdates && !disposeWhenNodeIsRemoved) {
var dirtySub = target.subscribe(markDirty, null, 'dirty'),
changeSub = target.subscribe(respondToChange);
return {
Expand Down

0 comments on commit a0134f5

Please sign in to comment.