|
@@ -8,7 +8,13 @@ export class EffectScope {
|
|
|
effects: ReactiveEffect[] = []
|
|
effects: ReactiveEffect[] = []
|
|
|
cleanups: (() => void)[] = []
|
|
cleanups: (() => void)[] = []
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * only assinged by undetached scope
|
|
|
|
|
+ */
|
|
|
parent: EffectScope | undefined
|
|
parent: EffectScope | undefined
|
|
|
|
|
+ /**
|
|
|
|
|
+ * record undetached scopes
|
|
|
|
|
+ */
|
|
|
scopes: EffectScope[] | undefined
|
|
scopes: EffectScope[] | undefined
|
|
|
/**
|
|
/**
|
|
|
* track a child scope's index in its parent's scopes array for optimized
|
|
* track a child scope's index in its parent's scopes array for optimized
|
|
@@ -28,11 +34,12 @@ export class EffectScope {
|
|
|
|
|
|
|
|
run<T>(fn: () => T): T | undefined {
|
|
run<T>(fn: () => T): T | undefined {
|
|
|
if (this.active) {
|
|
if (this.active) {
|
|
|
|
|
+ const currentEffectScope = activeEffectScope
|
|
|
try {
|
|
try {
|
|
|
activeEffectScope = this
|
|
activeEffectScope = this
|
|
|
return fn()
|
|
return fn()
|
|
|
} finally {
|
|
} finally {
|
|
|
- activeEffectScope = this.parent
|
|
|
|
|
|
|
+ activeEffectScope = currentEffectScope
|
|
|
}
|
|
}
|
|
|
} else if (__DEV__) {
|
|
} else if (__DEV__) {
|
|
|
warn(`cannot run an inactive effect scope.`)
|
|
warn(`cannot run an inactive effect scope.`)
|