From a72652f6e66151b23abece080abc2dea56d19132 Mon Sep 17 00:00:00 2001 From: Tidyzq Date: Wed, 16 Oct 2019 13:58:11 +0800 Subject: [PATCH] refactor(reactivity): immediate return (#301) --- packages/reactivity/src/effect.ts | 47 ++++++++++++++++--------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index 3350bc1a..fac7180d 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -128,29 +128,30 @@ export function track( return } const effect = activeReactiveEffectStack[activeReactiveEffectStack.length - 1] - if (effect) { - if (type === OperationTypes.ITERATE) { - key = ITERATE_KEY - } - let depsMap = targetMap.get(target) - if (depsMap === void 0) { - targetMap.set(target, (depsMap = new Map())) - } - let dep = depsMap.get(key!) - if (dep === void 0) { - depsMap.set(key!, (dep = new Set())) - } - if (!dep.has(effect)) { - dep.add(effect) - effect.deps.push(dep) - if (__DEV__ && effect.onTrack) { - effect.onTrack({ - effect, - target, - type, - key - }) - } + if (!effect) { + return + } + if (type === OperationTypes.ITERATE) { + key = ITERATE_KEY + } + let depsMap = targetMap.get(target) + if (depsMap === void 0) { + targetMap.set(target, (depsMap = new Map())) + } + let dep = depsMap.get(key!) + if (dep === void 0) { + depsMap.set(key!, (dep = new Set())) + } + if (!dep.has(effect)) { + dep.add(effect) + effect.deps.push(dep) + if (__DEV__ && effect.onTrack) { + effect.onTrack({ + effect, + target, + type, + key + }) } } }