fix(reactivity): accept subtypes of collections (#1864)

This commit is contained in:
ᴜɴвʏтᴇ
2020-08-18 00:17:46 +08:00
committed by GitHub
parent 6ccd9ac2bc
commit d005b578b1
2 changed files with 46 additions and 13 deletions

View File

@@ -44,6 +44,24 @@ describe('reactivity/reactive', () => {
expect(isReactive(observed.array[0])).toBe(true)
})
test('process subtypes of collections properly', () => {
class CustomMap extends Map {
count = 0
set(key: any, value: any): this {
super.set(key, value)
this.count++
return this
}
}
const testMap = new CustomMap()
const observed = reactive(testMap)
expect(observed.count).toBe(0)
observed.set('test', 'value')
expect(observed.count).toBe(1)
})
test('observed value should proxy mutations to original (Object)', () => {
const original: any = { foo: 1 }
const observed = reactive(original)