refactor(reactivity): use NOOP for readonly computed setter in production

This commit is contained in:
Evan You 2019-10-09 12:22:08 -04:00
parent 530be302fc
commit 8f1475b8dd

View File

@ -1,6 +1,6 @@
import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect' import { effect, ReactiveEffect, activeReactiveEffectStack } from './effect'
import { Ref, refSymbol, UnwrapNestedRefs } from './ref' import { Ref, refSymbol, UnwrapNestedRefs } from './ref'
import { isFunction } from '@vue/shared' import { isFunction, NOOP } from '@vue/shared'
export interface ComputedRef<T> extends Ref<T> { export interface ComputedRef<T> extends Ref<T> {
readonly value: UnwrapNestedRefs<T> readonly value: UnwrapNestedRefs<T>
@ -28,11 +28,11 @@ export function computed<T>(
? (getterOrOptions as (() => T)) ? (getterOrOptions as (() => T))
: (getterOrOptions as WritableComputedOptions<T>).get : (getterOrOptions as WritableComputedOptions<T>).get
const setter = isReadonly const setter = isReadonly
? __DEV__
? () => { ? () => {
if (__DEV__) {
console.warn('Write operation failed: computed value is readonly') console.warn('Write operation failed: computed value is readonly')
} }
} : NOOP
: (getterOrOptions as WritableComputedOptions<T>).set : (getterOrOptions as WritableComputedOptions<T>).set
let dirty = true let dirty = true