From 8f1475b8dd840962c8c170cfc5304836792c6431 Mon Sep 17 00:00:00 2001 From: Evan You Date: Wed, 9 Oct 2019 12:22:08 -0400 Subject: [PATCH] refactor(reactivity): use NOOP for readonly computed setter in production --- packages/reactivity/src/computed.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/reactivity/src/computed.ts b/packages/reactivity/src/computed.ts index b505e3015..9f2ede367 100644 --- a/packages/reactivity/src/computed.ts +++ b/packages/reactivity/src/computed.ts @@ -1,6 +1,6 @@ import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect' import { Ref, refSymbol, UnwrapNestedRefs } from './ref' -import { isFunction } from '@vue/shared' +import { isFunction, NOOP } from '@vue/shared' export interface ComputedRef extends Ref { readonly value: UnwrapNestedRefs @@ -28,11 +28,11 @@ export function computed( ? (getterOrOptions as (() => T)) : (getterOrOptions as WritableComputedOptions).get const setter = isReadonly - ? () => { - if (__DEV__) { + ? __DEV__ + ? () => { console.warn('Write operation failed: computed value is readonly') } - } + : NOOP : (getterOrOptions as WritableComputedOptions).set let dirty = true