From b264551c9be5ff62e41e220e57e77e15a8e11c54 Mon Sep 17 00:00:00 2001 From: zhangenming <282126346@qq.com> Date: Wed, 22 Sep 2021 01:03:09 +0800 Subject: [PATCH] refactor(reactivity): reuse computed getter check (#4623) --- packages/reactivity/src/computed.ts | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index b3292588..11af231b 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -78,7 +78,8 @@ export function computed( let getter: ComputedGetter let setter: ComputedSetter - if (isFunction(getterOrOptions)) { + const onlyGetter = isFunction(getterOrOptions) + if (onlyGetter) { getter = getterOrOptions setter = __DEV__ ? () => { @@ -90,11 +91,7 @@ export function computed( setter = getterOrOptions.set } - const cRef = new ComputedRefImpl( - getter, - setter, - isFunction(getterOrOptions) || !getterOrOptions.set - ) + const cRef = new ComputedRefImpl(getter, setter, onlyGetter || !setter) if (__DEV__ && debugOptions) { cRef.effect.onTrack = debugOptions.onTrack