perf(reactivity): add existing index or non-integer prop on Array should not trigger length dependency (#1969)

This commit is contained in:
xxgjzftd
2020-08-26 23:28:58 +08:00
committed by GitHub
parent 6df0e738cb
commit d5c4f6ed4d
4 changed files with 42 additions and 10 deletions

View File

@@ -99,6 +99,33 @@ describe('reactivity/reactive/Array', () => {
expect(fn).toHaveBeenCalledTimes(1)
})
test('add existing index on Array should not trigger length dependency', () => {
const array = new Array(3)
const observed = reactive(array)
const fn = jest.fn()
effect(() => {
fn(observed.length)
})
expect(fn).toHaveBeenCalledTimes(1)
observed[1] = 1
expect(fn).toHaveBeenCalledTimes(1)
})
test('add non-integer prop on Array should not trigger length dependency', () => {
const array = new Array(3)
const observed = reactive(array)
const fn = jest.fn()
effect(() => {
fn(observed.length)
})
expect(fn).toHaveBeenCalledTimes(1)
// @ts-ignore
observed.x = 'x'
expect(fn).toHaveBeenCalledTimes(1)
observed[-1] = 'x'
expect(fn).toHaveBeenCalledTimes(1)
})
describe('Array methods w/ refs', () => {
let original: any[]
beforeEach(() => {