perf(reactivity): add existing index or non-integer prop on Array should not trigger length dependency (#1969)
This commit is contained in:
@@ -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(() => {
|
||||
|
||||
Reference in New Issue
Block a user