Skip to content

Commit

Permalink
Mark computed as dirty after notifying beforeChange.
Browse files Browse the repository at this point in the history
  • Loading branch information
mbest committed Dec 29, 2013
1 parent 8c2a003 commit 27cac34
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
6 changes: 4 additions & 2 deletions spec/asyncBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,8 @@ describe('Rate-limited', function() {
var observable = ko.observable().extend({rateLimit:500});
var notifySpy = jasmine.createSpy('notifySpy');
observable.subscribe(notifySpy);
var beforeChangeSpy = jasmine.createSpy('beforeChangeSpy');
var beforeChangeSpy = jasmine.createSpy('beforeChangeSpy')
.andCallFake(function(value) {expect(observable()).toBe(value); });
observable.subscribe(beforeChangeSpy, null, 'beforeChange');

// Observable is changed, but notification is delayed
Expand Down Expand Up @@ -380,7 +381,8 @@ describe('Rate-limited', function() {
var computed = ko.computed(function () { evalSpy(observable()); return observable(); }).extend({rateLimit:500});
var notifySpy = jasmine.createSpy('notifySpy');
computed.subscribe(notifySpy);
var beforeChangeSpy = jasmine.createSpy('beforeChangeSpy');
var beforeChangeSpy = jasmine.createSpy('beforeChangeSpy')
.andCallFake(function(value) {expect(computed()).toBe(value); });
computed.subscribe(beforeChangeSpy, null, 'beforeChange');

// Observable is changed, but notification is delayed
Expand Down
7 changes: 2 additions & 5 deletions src/subscribables/dependentObservable.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ ko.dependentObservable = function (evaluatorFunctionOrOptions, evaluatorFunction
}

function evaluatePossiblyAsync() {
_needsEvaluation = true;
var throttleEvaluationTimeout = dependentObservable['throttleEvaluation'];
if (throttleEvaluationTimeout && throttleEvaluationTimeout >= 0) {
clearTimeout(evaluationTimeoutInstance);
Expand All @@ -56,10 +55,6 @@ ko.dependentObservable = function (evaluatorFunctionOrOptions, evaluatorFunction
return;
}

if (!_needsEvaluation) {
return;
}

if (disposeWhen && disposeWhen()) {
// See comment below about _suppressDisposalUntilDisposeWhenReturnsFalse
if (!_suppressDisposalUntilDisposeWhenReturnsFalse) {
Expand Down Expand Up @@ -190,6 +185,8 @@ ko.dependentObservable = function (evaluatorFunctionOrOptions, evaluatorFunction
dependentObservable._evalRateLimited = function() {
dependentObservable._rateLimitedBeforeChange(_latestValue);

_needsEvaluation = true; // Mark as dirty

// Pass the observable to the rate-limit code, which will access it when
// it's time to do the notification.
dependentObservable._rateLimitedChange(dependentObservable);
Expand Down

0 comments on commit 27cac34

Please sign in to comment.