Skip to content

Commit

Permalink
fix(vue): onScopeDispose not working
Browse files Browse the repository at this point in the history
  • Loading branch information
johnsoncodehk committed Oct 5, 2024
1 parent 600937c commit 2a6ff9f
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions unstable/vue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,19 @@ export function effect(fn: () => void) {
return new ReactiveEffect(fn);
}

class VueEffectScope extends EffectScope {
onDispose: (() => void)[] = [];

stop() {
super.stop();
for (const cb of this.onDispose) {
cb();
}
}
}

export function effectScope() {
return new EffectScope();
return new VueEffectScope();
}

export function triggerRef(ref: ShallowRef) {
Expand Down Expand Up @@ -89,12 +100,11 @@ export class ReactiveEffect extends Effect {
for (const cb of this.onDispose) {
cb();
}
this.onDispose.length = 0;
}
}

export function onScopeDispose(cb: () => void) {
if (currentEffectScope instanceof ReactiveEffect) {
if (currentEffectScope instanceof VueEffectScope) {
currentEffectScope.onDispose.push(cb);
}
}

0 comments on commit 2a6ff9f

Please sign in to comment.