perf(reactivity): optimize effect stack

This commit is contained in:
Evan You
2019-12-13 23:06:55 -05:00
parent 49a50d3c9c
commit 46c5393224
2 changed files with 16 additions and 15 deletions

View File

@@ -1,4 +1,4 @@
import { effect, ReactiveEffect, effectStack } from './effect'
import { effect, ReactiveEffect, activeEffect } from './effect'
import { Ref, UnwrapRef } from './ref'
import { isFunction, NOOP } from '@vue/shared'
@@ -73,15 +73,14 @@ export function computed<T>(
}
function trackChildRun(childRunner: ReactiveEffect) {
if (effectStack.length === 0) {
if (activeEffect === undefined) {
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)
if (!dep.has(activeEffect)) {
dep.add(activeEffect)
activeEffect.deps.push(dep)
}
}
}