perf(reactivity): avoid triggering Map.has twice on non-reactive keys (#1972)
This commit is contained in:
parent
d5c4f6ed4d
commit
97bc30edad
@ -436,5 +436,16 @@ describe('reactivity/collections', () => {
|
|||||||
map.set('b', 1)
|
map.set('b', 1)
|
||||||
expect(spy).toHaveBeenCalledTimes(3)
|
expect(spy).toHaveBeenCalledTimes(3)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should trigger has only once for non-reactive keys', () => {
|
||||||
|
const map = new Map()
|
||||||
|
const spy = jest.fn()
|
||||||
|
map.has = spy
|
||||||
|
|
||||||
|
let proxy = reactive(map)
|
||||||
|
proxy.has('k')
|
||||||
|
|
||||||
|
expect(spy).toBeCalledTimes(1)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -59,7 +59,9 @@ function has(this: CollectionTypes, key: unknown, isReadonly = false): boolean {
|
|||||||
!isReadonly && track(rawTarget, TrackOpTypes.HAS, key)
|
!isReadonly && track(rawTarget, TrackOpTypes.HAS, key)
|
||||||
}
|
}
|
||||||
!isReadonly && track(rawTarget, TrackOpTypes.HAS, rawKey)
|
!isReadonly && track(rawTarget, TrackOpTypes.HAS, rawKey)
|
||||||
return target.has(key) || target.has(rawKey)
|
return key === rawKey
|
||||||
|
? target.has(key)
|
||||||
|
: target.has(key) || target.has(rawKey)
|
||||||
}
|
}
|
||||||
|
|
||||||
function size(target: IterableCollections, isReadonly = false) {
|
function size(target: IterableCollections, isReadonly = false) {
|
||||||
|
Loading…
Reference in New Issue
Block a user