mirror of
https://github.com/vuejs/vue.git
synced 2024-11-21 20:28:54 +00:00
parent
530b56a36e
commit
44ab1cda74
@ -69,7 +69,7 @@ function createReadonly(target: any, shallow: boolean) {
|
||||
return existingProxy
|
||||
}
|
||||
|
||||
const proxy = {}
|
||||
const proxy = Object.create(Object.getPrototypeOf(target))
|
||||
def(target, existingFlag, proxy)
|
||||
|
||||
def(proxy, ReactiveFlags.IS_READONLY, true)
|
||||
|
@ -499,4 +499,25 @@ describe('reactivity/readonly', () => {
|
||||
expect(obj.ror).toBe(true)
|
||||
expect(toRaw(obj).ror).not.toBe(ror) // ref successfully replaced
|
||||
})
|
||||
|
||||
test('compatiblity with classes', () => {
|
||||
const spy = vi.fn()
|
||||
class Foo {
|
||||
x = 1
|
||||
log() {
|
||||
spy(this.x)
|
||||
}
|
||||
change() {
|
||||
this.x++
|
||||
}
|
||||
}
|
||||
const foo = new Foo()
|
||||
const readonlyFoo = readonly(foo)
|
||||
readonlyFoo.log()
|
||||
expect(spy).toHaveBeenCalledWith(1)
|
||||
|
||||
readonlyFoo.change()
|
||||
expect(readonlyFoo.x).toBe(1)
|
||||
expect(`et operation on key "x" failed`).toHaveBeenWarned()
|
||||
})
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user