parent
30aae0b4df
commit
63a6563106
@ -26,6 +26,22 @@ describe('reactivity/collections', () => {
|
|||||||
expect(dummy).toBe(undefined)
|
expect(dummy).toBe(undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should observe mutations with observed value as key', () => {
|
||||||
|
let dummy
|
||||||
|
const key = reactive({})
|
||||||
|
const value = reactive({})
|
||||||
|
const map = reactive(new Map())
|
||||||
|
effect(() => {
|
||||||
|
dummy = map.get(key)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(dummy).toBe(undefined)
|
||||||
|
map.set(key, value)
|
||||||
|
expect(dummy).toBe(value)
|
||||||
|
map.delete(key)
|
||||||
|
expect(dummy).toBe(undefined)
|
||||||
|
})
|
||||||
|
|
||||||
it('should observe size mutations', () => {
|
it('should observe size mutations', () => {
|
||||||
let dummy
|
let dummy
|
||||||
const map = reactive(new Map())
|
const map = reactive(new Map())
|
||||||
|
@ -22,6 +22,19 @@ describe('reactivity/collections', () => {
|
|||||||
expect(dummy).toBe(false)
|
expect(dummy).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should observe mutations with observed value', () => {
|
||||||
|
let dummy
|
||||||
|
const value = reactive({})
|
||||||
|
const set = reactive(new Set())
|
||||||
|
effect(() => (dummy = set.has(value)))
|
||||||
|
|
||||||
|
expect(dummy).toBe(false)
|
||||||
|
set.add(value)
|
||||||
|
expect(dummy).toBe(true)
|
||||||
|
set.delete(value)
|
||||||
|
expect(dummy).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
it('should observe for of iteration', () => {
|
it('should observe for of iteration', () => {
|
||||||
let dummy
|
let dummy
|
||||||
const set = reactive(new Set() as Set<number>)
|
const set = reactive(new Set() as Set<number>)
|
||||||
|
@ -27,6 +27,22 @@ describe('reactivity/collections', () => {
|
|||||||
expect(dummy).toBe(undefined)
|
expect(dummy).toBe(undefined)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should observe mutations with observed value as key', () => {
|
||||||
|
let dummy
|
||||||
|
const key = reactive({})
|
||||||
|
const value = reactive({})
|
||||||
|
const map = reactive(new WeakMap())
|
||||||
|
effect(() => {
|
||||||
|
dummy = map.get(key)
|
||||||
|
})
|
||||||
|
|
||||||
|
expect(dummy).toBe(undefined)
|
||||||
|
map.set(key, value)
|
||||||
|
expect(dummy).toBe(value)
|
||||||
|
map.delete(key)
|
||||||
|
expect(dummy).toBe(undefined)
|
||||||
|
})
|
||||||
|
|
||||||
it('should not observe custom property mutations', () => {
|
it('should not observe custom property mutations', () => {
|
||||||
let dummy
|
let dummy
|
||||||
const map: any = reactive(new WeakMap())
|
const map: any = reactive(new WeakMap())
|
||||||
|
@ -23,6 +23,19 @@ describe('reactivity/collections', () => {
|
|||||||
expect(dummy).toBe(false)
|
expect(dummy).toBe(false)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should observe mutations with observed value', () => {
|
||||||
|
let dummy
|
||||||
|
const value = reactive({})
|
||||||
|
const set = reactive(new WeakSet())
|
||||||
|
effect(() => (dummy = set.has(value)))
|
||||||
|
|
||||||
|
expect(dummy).toBe(false)
|
||||||
|
set.add(value)
|
||||||
|
expect(dummy).toBe(true)
|
||||||
|
set.delete(value)
|
||||||
|
expect(dummy).toBe(false)
|
||||||
|
})
|
||||||
|
|
||||||
it('should not observe custom property mutations', () => {
|
it('should not observe custom property mutations', () => {
|
||||||
let dummy
|
let dummy
|
||||||
const set: any = reactive(new WeakSet())
|
const set: any = reactive(new WeakSet())
|
||||||
|
@ -63,6 +63,7 @@ function add(this: SetTypes, value: unknown) {
|
|||||||
|
|
||||||
function set(this: MapTypes, key: unknown, value: unknown) {
|
function set(this: MapTypes, key: unknown, value: unknown) {
|
||||||
value = toRaw(value)
|
value = toRaw(value)
|
||||||
|
key = toRaw(key)
|
||||||
const target = toRaw(this)
|
const target = toRaw(this)
|
||||||
const proto = getProto(target)
|
const proto = getProto(target)
|
||||||
const hadKey = proto.has.call(target, key)
|
const hadKey = proto.has.call(target, key)
|
||||||
@ -87,6 +88,7 @@ function set(this: MapTypes, key: unknown, value: unknown) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function deleteEntry(this: CollectionTypes, key: unknown) {
|
function deleteEntry(this: CollectionTypes, key: unknown) {
|
||||||
|
key = toRaw(key)
|
||||||
const target = toRaw(this)
|
const target = toRaw(this)
|
||||||
const proto = getProto(target)
|
const proto = getProto(target)
|
||||||
const hadKey = proto.has.call(target, key)
|
const hadKey = proto.has.call(target, key)
|
||||||
|
Loading…
Reference in New Issue
Block a user