)
function createGetter(isReadonly: boolean) {
- return function get(target: any, key: string | symbol, receiver: any) {
- const res = Reflect.get(target, key, receiver)
+ return function get(target: any, key: string | symbol) {
+ // not using Reflect.get here for perf reasons
+ const res = target[key]
if (isSymbol(key) && builtInSymbols.has(key)) {
return res
}
-import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect'
+import { effect, ReactiveEffect, effectStack } from './effect'
import { Ref, UnwrapRef } from './ref'
import { isFunction, NOOP } from '@vue/shared'
}
function trackChildRun(childRunner: ReactiveEffect) {
- const parentRunner =
- activeReactiveEffectStack[activeReactiveEffectStack.length - 1]
- if (parentRunner) {
- for (let i = 0; i < childRunner.deps.length; i++) {
- const dep = childRunner.deps[i]
- if (!dep.has(parentRunner)) {
- dep.add(parentRunner)
- parentRunner.deps.push(dep)
- }
+ if (effectStack.length === 0) {
+ return
+ }
+ const parentRunner = effectStack[effectStack.length - 1]
+ for (let i = 0; i < childRunner.deps.length; i++) {
+ const dep = childRunner.deps[i]
+ if (!dep.has(parentRunner)) {
+ dep.add(parentRunner)
+ parentRunner.deps.push(dep)
}
}
}
key: string | symbol | undefined
}
-export const activeReactiveEffectStack: ReactiveEffect[] = []
+export const effectStack: ReactiveEffect[] = []
export const ITERATE_KEY = Symbol('iterate')
if (!effect.active) {
return fn(...args)
}
- if (!activeReactiveEffectStack.includes(effect)) {
+ if (!effectStack.includes(effect)) {
cleanup(effect)
try {
- activeReactiveEffectStack.push(effect)
+ effectStack.push(effect)
return fn(...args)
} finally {
- activeReactiveEffectStack.pop()
+ effectStack.pop()
}
}
}
type: OperationTypes,
key?: string | symbol
) {
- if (!shouldTrack) {
- return
- }
- const effect = activeReactiveEffectStack[activeReactiveEffectStack.length - 1]
- if (!effect) {
+ if (!shouldTrack || effectStack.length === 0) {
return
}
+ const effect = effectStack[effectStack.length - 1]
if (type === OperationTypes.ITERATE) {
key = ITERATE_KEY
}