Skip to content

Commit

Permalink
fix(effect): should not trigger inner effect when resolve maybe dirty
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 9, 2024
1 parent 310bda1 commit 958e696
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
6 changes: 3 additions & 3 deletions lib/computed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ export class Computed<T = any> implements Dependency, Subscriber {
if (dirtyLevel === DirtyLevels.MaybeDirty) {
Subscriber.resolveMaybeDirty(this);
if (this.versionOrDirtyLevel === DirtyLevels.Dirty) {
return this.run();
return this.update();
}
} else if (dirtyLevel === DirtyLevels.Dirty) {
return this.run();
return this.update();
}
return this.cachedValue!;
}

run() {
update() {
const lastActiveSub = Subscriber.startTrack(this);
const oldValue = this.cachedValue;
const newValue = this.getter(oldValue);
Expand Down
10 changes: 5 additions & 5 deletions lib/system.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface Dependency {
subs: Link | undefined;
subsTail: Link | undefined;
subVersion: number;
run?(): void;
update?(): void;
}

export interface Subscriber {
Expand Down Expand Up @@ -328,8 +328,8 @@ export namespace Subscriber {
link = dep.deps;

continue top;
} else if (depDirtyLevel === DirtyLevels.Dirty) {
dep.run!();
} else if (depDirtyLevel === DirtyLevels.Dirty && dep.update !== undefined) {
dep.update();

if ((sub.versionOrDirtyLevel as DirtyLevels) === DirtyLevels.Dirty) {
break;
Expand All @@ -352,8 +352,8 @@ export namespace Subscriber {
const prevLink = subSubs.prevSubOrUpdate;

if (prevLink !== undefined) {
if (dirtyLevel === DirtyLevels.Dirty) {
sub.run!();
if (dirtyLevel === DirtyLevels.Dirty && sub.update !== undefined) {
sub.update();
}

subSubs.prevSubOrUpdate = undefined;
Expand Down

0 comments on commit 958e696

Please sign in to comment.