Skip to content

Commit

Permalink
Modify dirty/stale logic so that we don't need to check both isDirty …
Browse files Browse the repository at this point in the history
…and isStale
  • Loading branch information
mbest committed Feb 10, 2017
1 parent 495a969 commit f5df3c2
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions src/subscribables/dependentObservable.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ ko.computed = ko.dependentObservable = function (evaluatorFunctionOrOptions, eva
var state = {
latestValue: undefined,
isStale: true,
isDirty: false,
isDirty: true,
isBeingEvaluated: false,
suppressDisposalUntilDisposeWhenReturnsFalse: false,
isDisposed: false,
Expand Down Expand Up @@ -46,7 +46,7 @@ ko.computed = ko.dependentObservable = function (evaluatorFunctionOrOptions, eva
} else {
// Reading the value
ko.dependencyDetection.registerDependency(computedObservable);
if (state.isStale || state.isDirty || (state.isSleeping && computedObservable.haveDependenciesChanged())) {
if (state.isDirty || (state.isSleeping && computedObservable.haveDependenciesChanged())) {
computedObservable.evaluateImmediate();
}
return state.latestValue;
Expand Down Expand Up @@ -172,7 +172,7 @@ var computedFn = {
},
isActive: function () {
var state = this[computedState];
return state.isStale || state.isDirty || state.dependenciesCount > 0;
return state.isDirty || state.dependenciesCount > 0;
},
respondToChange: function () {
// Ignore "change" events if we've already scheduled a delayed notification
Expand Down Expand Up @@ -332,7 +332,7 @@ var computedFn = {
peek: function () {
// Peek won't re-evaluate, except while the computed is sleeping or to get the initial value when "deferEvaluation" is set.
var state = this[computedState];
if ((state.isStale && !state.dependenciesCount) || (state.isSleeping && this.haveDependenciesChanged())) {
if ((state.isDirty && !state.dependenciesCount) || (state.isSleeping && this.haveDependenciesChanged())) {
this.evaluateImmediate();
}
return state.latestValue;
Expand All @@ -350,10 +350,9 @@ var computedFn = {
this._limitBeforeChange(this[computedState].latestValue);

// Mark as dirty
this[computedState].isDirty = true;
if (isChange) {
this[computedState].isStale = true;
} else {
this[computedState].isDirty = true;
}

// Pass the observable to the "limit" code, which will evaluate it when
Expand Down Expand Up @@ -397,7 +396,6 @@ var pureComputedOverrides = {
if (state.isStale || computedObservable.haveDependenciesChanged()) {
state.dependencyTracking = null;
state.dependenciesCount = 0;
state.isStale = true;
if (computedObservable.evaluateImmediate()) {
computedObservable.updateVersion();
}
Expand Down

0 comments on commit f5df3c2

Please sign in to comment.