Skip to content

Commit

Permalink
Fix for #1975. Issue occurs when a computed is changed when awakening…
Browse files Browse the repository at this point in the history
… that dependent sleeping computed observables don't know that it was changed.
  • Loading branch information
mbest committed Jan 15, 2016
1 parent b3f24b1 commit eb88065
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions spec/asyncBindingBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,29 @@ describe("Deferred bindings", function() {
}).not.toThrow();
expect(observable()).not.toBeUndefined(); // The spec doesn't specify which of the two possible values is actually set
});

it('Should get latest value when conditionally included', function() {
// Test is based on example in https://github.com/knockout/knockout/issues/1975

testNode.innerHTML = "<div data-bind=\"if: show\"><div data-bind=\"text: status\"></div></div>";
var value = ko.observable(0),
is1 = ko.pureComputed(function () { return value() == 1; }),
status = ko.pureComputed(function () { return is1() ? 'ok' : 'error'; }),
show = ko.pureComputed(function () { return value() > 0 && is1(); });

ko.applyBindings({ status: status, show: show }, testNode);
expect(testNode.childNodes[0]).toContainHtml('');

value(1);
jasmine.Clock.tick(1);
expect(testNode.childNodes[0]).toContainHtml('<div data-bind="text: status">ok</div>');

value(0);
jasmine.Clock.tick(1);
expect(testNode.childNodes[0]).toContainHtml('');

value(1);
jasmine.Clock.tick(1);
expect(testNode.childNodes[0]).toContainHtml('<div data-bind="text: status">ok</div>');
});
});
1 change: 1 addition & 0 deletions src/subscribables/dependentObservable.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,7 @@ var pureComputedOverrides = {
state.dependenciesCount = 0;
state.isStale = true;
computedObservable.evaluateImmediate();
computedObservable.updateVersion();
} else {
// First put the dependencies in order
var dependeciesOrder = [];
Expand Down

0 comments on commit eb88065

Please sign in to comment.