Skip to content

Commit

Permalink
refactor(effectScope): restore scope after run
Browse files Browse the repository at this point in the history
  • Loading branch information
posva committed Mar 23, 2022
1 parent 6f947c3 commit 513cc8b
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions packages/reactivity/src/effectScope.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,6 @@ export class EffectScope {
* removal
*/
private index: number | undefined
/**
* activeEffectScope in context not died should be recorded
*/
private aliveEffectScope: EffectScope | undefined

constructor(detached = false) {
if (!detached && activeEffectScope) {
Expand All @@ -38,27 +34,24 @@ export class EffectScope {

run<T>(fn: () => T): T | undefined {
if (this.active) {
const currentEffectScope = activeEffectScope
try {
this.aliveEffectScope = activeEffectScope
activeEffectScope = this
return fn()
} finally {
activeEffectScope = this.aliveEffectScope
delete this.aliveEffectScope
activeEffectScope = currentEffectScope
}
} else if (__DEV__) {
warn(`cannot run an inactive effect scope.`)
}
}

on() {
this.aliveEffectScope = activeEffectScope
activeEffectScope = this
}

off() {
activeEffectScope = this.aliveEffectScope
delete this.aliveEffectScope
activeEffectScope = this.parent
}

stop(fromParent?: boolean) {
Expand Down

0 comments on commit 513cc8b

Please sign in to comment.