Skip to content

Commit

Permalink
Refactor needsToRecompute
Browse files Browse the repository at this point in the history
Use an early return for delicious byte savings.
  • Loading branch information
jviide committed Oct 7, 2022
1 parent f9d61d1 commit 5975777
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -306,8 +306,11 @@ function needsToRecompute(target: Computed | Effect): boolean {
// Check the dependencies for changed values. The dependency list is already
// in order of use. Therefore if multiple dependencies have changed values, only
// the first used dependency is re-evaluated at this point.
let node = target._sources;
while (node !== undefined) {
for (
let node = target._sources;
node !== undefined;
node = node._nextSource
) {
// If there's a new version of the dependency before or after refreshing,
// or the dependency has something blocking it from refreshing at all (e.g. a
// dependency cycle), then we need to recompute.
Expand All @@ -316,13 +319,12 @@ function needsToRecompute(target: Computed | Effect): boolean {
!node._source._refresh() ||
node._source._version !== node._version
) {
break;
return true;
}
node = node._nextSource;
}
// If none of the dependencies have changed values since last recompute then the
// there's no need to recompute.
return node !== undefined;
return false;
}

function prepareSources(target: Computed | Effect) {
Expand Down

0 comments on commit 5975777

Please sign in to comment.