Subscribe on changes!

a proxy call isReactive returns true and call isReadonly returns true

avatar
Jan 6th 2021

Version

3.0.5

Reproduction link

https://jsfiddle.net/a147v8hx/1/

Steps to reproduce

let proxy = readonly(reactive({})) console.log(isReactive(proxy)) // true console.log(isReadonly(proxy))// true

What is expected?

isReactive(proxy) returns false isReadonly(proxy) returns true

What is actually happening?

isReactive(proxy) returns true isReadonly(proxy) returns true


the same proxy call isReactive returns true, call isReadonly returns true, this make me confused

avatar
Jan 6th 2021

the reactive means that it will collect effects as dependencies, the readonly means that its value cannot be modified. When reading a readonly data, it can still collect effects, in this scenario, it is both reactive and readonly.

Consider this:

const a = reactive({ foo: 1 })
const b = readonly(a)

effect(() => {
  console.log(b.foo)
})

setTimeout(() => {
  a.foo = 2
}, 1000)