Skip to content

Commit

Permalink
Simplify logic to check for dependency changes during awake
Browse files Browse the repository at this point in the history
  • Loading branch information
mbest committed Oct 1, 2017
1 parent 195cdea commit 3949c3e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 13 deletions.
6 changes: 1 addition & 5 deletions spec/pureComputedBehaviors.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,6 @@ describe('Pure Computed', function() {
});

it('Should wake with the correct value when a chained pure computed has side effects for its awake event', function () {

var observableToUpdateOnAwake = ko.observable(null),
computed1 = ko.pureComputed(observableToUpdateOnAwake),
computed2 = ko.pureComputed(computed1);
Expand All @@ -396,11 +395,8 @@ describe('Pure Computed', function() {
// ignore side-effects from the awake callback of chained pure computeds
computed2();

computed2.subscribe(function () {
});

computed2.subscribe(function () {});
expect(computed2()).toEqual('foo');

});

describe('Should maintain order of subscriptions', function () {
Expand Down
13 changes: 5 additions & 8 deletions src/subscribables/dependentObservable.js
Original file line number Diff line number Diff line change
Expand Up @@ -435,14 +435,11 @@ var pureComputedOverrides = {
subscription._version = dependency._version;
state.dependencyTracking[id] = subscription;
});
}

// Repeat check since waking dependencies may have triggered effects
if (computedObservable.haveDependenciesChanged()) {
state.dependencyTracking = null;
state.dependenciesCount = 0;
if (computedObservable.evaluateImmediate()) {
computedObservable.updateVersion();
// Waking dependencies may have triggered effects
if (computedObservable.haveDependenciesChanged()) {
if (computedObservable.evaluateImmediate()) {
computedObservable.updateVersion();
}
}
}

Expand Down

0 comments on commit 3949c3e

Please sign in to comment.