effect,
stop,
ref,
- WritableComputedRef
+ WritableComputedRef,
+ isReadonly
} from '../src'
import { mockWarn } from '@vue/shared'
'Write operation failed: computed value is readonly'
).toHaveBeenWarnedLast()
})
+
+ it('should be readonly', () => {
+ let a = { a: 1 }
+ const x = computed(() => a)
+ expect(isReadonly(x)).toBe(true)
+ expect(isReadonly(x.value)).toBe(false)
+ expect(isReadonly(x.value.a)).toBe(false)
+ const z = computed<typeof a>({
+ get() {
+ return a
+ },
+ set(v) {
+ a = v
+ }
+ })
+ expect(isReadonly(z)).toBe(false)
+ expect(isReadonly(z.value.a)).toBe(false)
+ })
})
import { TriggerOpTypes, TrackOpTypes } from './operations'
import { Ref } from './ref'
import { isFunction, NOOP } from '@vue/shared'
+import { ReactiveFlags } from './reactive'
export interface ComputedRef<T = any> extends WritableComputedRef<T> {
readonly value: T
})
computed = {
__v_isRef: true,
+ [ReactiveFlags.IS_READONLY]:
+ isFunction(getterOrOptions) || !getterOrOptions.set,
+
// expose effect so computed can be stopped
effect: runner,
get value() {