refactor(reactivity): reuse computed getter check (#4623)

This commit is contained in:
zhangenming 2021-09-22 01:03:09 +08:00 committed by GitHub
parent 5addef8ecd
commit b264551c9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,7 +78,8 @@ export function computed<T>(
let getter: ComputedGetter<T>
let setter: ComputedSetter<T>
if (isFunction(getterOrOptions)) {
const onlyGetter = isFunction(getterOrOptions)
if (onlyGetter) {
getter = getterOrOptions
setter = __DEV__
? () => {
@ -90,11 +91,7 @@ export function computed<T>(
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