Skip to content

Commit

Permalink
fix(reactivity): should not trigger length dependency on Array delete
Browse files Browse the repository at this point in the history
close #774
  • Loading branch information
yyx990803 committed Mar 6, 2020
1 parent 689d45f commit a306658
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions packages/reactivity/__tests__/reactiveArray.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,17 @@ describe('reactivity/reactive/Array', () => {
expect(index).toBe(1)
})

test('delete on Array should not trigger length dependency', () => {
const arr = reactive([1, 2, 3])
const fn = jest.fn()
effect(() => {
fn(arr.length)
})
expect(fn).toHaveBeenCalledTimes(1)
delete arr[1]
expect(fn).toHaveBeenCalledTimes(1)
})

describe('Array methods w/ refs', () => {
let original: any[]
beforeEach(() => {
Expand Down
2 changes: 1 addition & 1 deletion packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ export function trigger(
// also run for iteration key on ADD | DELETE | Map.SET
if (
type === TriggerOpTypes.ADD ||
type === TriggerOpTypes.DELETE ||
(type === TriggerOpTypes.DELETE && !isArray(target)) ||
(type === TriggerOpTypes.SET && target instanceof Map)
) {
const iterationKey = isArray(target) ? 'length' : ITERATE_KEY
Expand Down

0 comments on commit a306658

Please sign in to comment.