From 7a58f15d2bc8a21249f29e085b5a49ef928c7c9e Mon Sep 17 00:00:00 2001 From: limichange Date: Mon, 20 Apr 2020 21:50:07 +0800 Subject: [PATCH 1/2] refactor(reactivity): simplify if condition --- packages/reactivity/src/effect.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index aab4ae6db6a..8cba8dc3ca2 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -141,11 +141,11 @@ export function track(target: object, type: TrackOpTypes, key: unknown) { return } let depsMap = targetMap.get(target) - if (depsMap === void 0) { + if (!depsMap) { targetMap.set(target, (depsMap = new Map())) } let dep = depsMap.get(key) - if (dep === void 0) { + if (!dep) { depsMap.set(key, (dep = new Set())) } if (!dep.has(activeEffect)) { @@ -171,7 +171,7 @@ export function trigger( oldTarget?: Map | Set ) { const depsMap = targetMap.get(target) - if (depsMap === void 0) { + if (!depsMap) { // never been tracked return } @@ -179,7 +179,7 @@ export function trigger( const effects = new Set() const computedRunners = new Set() const add = (effectsToAdd: Set | undefined) => { - if (effectsToAdd !== void 0) { + if (effectsToAdd) { effectsToAdd.forEach(effect => { if (effect !== activeEffect || !shouldTrack) { if (effect.options.computed) { @@ -208,7 +208,7 @@ export function trigger( }) } else { // schedule runs for SET | ADD | DELETE - if (key !== void 0) { + if (key) { add(depsMap.get(key)) } // also run for iteration key on ADD | DELETE | Map.SET @@ -238,7 +238,7 @@ export function trigger( oldTarget }) } - if (effect.options.scheduler !== void 0) { + if (effect.options.scheduler) { effect.options.scheduler(effect) } else { effect() From 0ab3bc330ff83c988fd2c34bb920f9eba960a4a7 Mon Sep 17 00:00:00 2001 From: limichange Date: Tue, 21 Apr 2020 01:18:58 +0800 Subject: [PATCH 2/2] refactor(reactivity): reset if condition --- packages/reactivity/src/effect.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/reactivity/src/effect.ts b/packages/reactivity/src/effect.ts index 8cba8dc3ca2..4bb977337be 100644 --- a/packages/reactivity/src/effect.ts +++ b/packages/reactivity/src/effect.ts @@ -208,7 +208,7 @@ export function trigger( }) } else { // schedule runs for SET | ADD | DELETE - if (key) { + if (key !== void 0) { add(depsMap.get(key)) } // also run for iteration key on ADD | DELETE | Map.SET