Skip to content

Commit

Permalink
refactor: remove updateDirtyFlag and expose checkDirty
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Jan 24, 2025
1 parent 3a6b0bd commit 430fa2b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
13 changes: 6 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ interface WriteableSignal<T> {
const {
link,
propagate,
updateDirtyFlag,
checkDirty,
startTracking,
endTracking,
processEffectNotifications,
Expand Down Expand Up @@ -175,12 +175,11 @@ function notifyEffect(e: Effect) {
const flags = e.flags;
if (flags & SubscriberFlags.Dirty) {
runEffect(e);
} else if (flags & SubscriberFlags.Pending) {
if (updateDirtyFlag(e, flags)) {
runEffect(e);
} else {
processPendingInnerEffects(e);
}
} else if (checkDirty(e.deps!)) {
runEffect(e);
} else {
e.flags = flags & ~SubscriberFlags.Pending;
processPendingInnerEffects(e);
}
}

Expand Down
20 changes: 1 addition & 19 deletions src/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -237,25 +237,7 @@ export function createReactiveSystem({
}
sub.flags &= ~SubscriberFlags.Tracking;
},
/**
* Updates the dirty flag for the given subscriber based on its dependencies.
*
* If the subscriber has any pending computeds, this function sets the Dirty flag
* and returns `true`. Otherwise, it clears the PendingComputed flag and returns `false`.
*
* @param sub - The subscriber to update.
* @param flags - The current flag set for this subscriber.
* @returns `true` if the subscriber is marked as Dirty; otherwise `false`.
*/
updateDirtyFlag(sub: Subscriber, flags: SubscriberFlags): boolean {
if (checkDirty(sub.deps!)) {
sub.flags = flags | SubscriberFlags.Dirty;
return true;
} else {
sub.flags = flags & ~SubscriberFlags.Pending;
return false;
}
},
checkDirty,
/**
* Updates the computed subscriber if necessary before its value is accessed.
*
Expand Down

0 comments on commit 430fa2b

Please sign in to comment.