Skip to content

Commit 5975777

Browse files
committed
Refactor needsToRecompute
Use an early return for delicious byte savings.
1 parent f9d61d1 commit 5975777

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

packages/core/src/index.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -306,8 +306,11 @@ function needsToRecompute(target: Computed | Effect): boolean {
306306
// Check the dependencies for changed values. The dependency list is already
307307
// in order of use. Therefore if multiple dependencies have changed values, only
308308
// the first used dependency is re-evaluated at this point.
309-
let node = target._sources;
310-
while (node !== undefined) {
309+
for (
310+
let node = target._sources;
311+
node !== undefined;
312+
node = node._nextSource
313+
) {
311314
// If there's a new version of the dependency before or after refreshing,
312315
// or the dependency has something blocking it from refreshing at all (e.g. a
313316
// dependency cycle), then we need to recompute.
@@ -316,13 +319,12 @@ function needsToRecompute(target: Computed | Effect): boolean {
316319
!node._source._refresh() ||
317320
node._source._version !== node._version
318321
) {
319-
break;
322+
return true;
320323
}
321-
node = node._nextSource;
322324
}
323325
// If none of the dependencies have changed values since last recompute then the
324326
// there's no need to recompute.
325-
return node !== undefined;
327+
return false;
326328
}
327329

328330
function prepareSources(target: Computed | Effect) {

0 commit comments

Comments
 (0)