Skip to content

Conversation

HowGraceU
Copy link

I think I may have found a bug #10705

effect function will be called more than once when Array.prototype.shift be called

 it('should observe iteration', () => {
    let dummy
    const list = reactive(['Hello'])
    const fn = jest.fn(() => (dummy = list.join(' ')));
    effect(fn)

    expect(fn).toHaveBeenCalledTimes(1) // normal

    expect(dummy).toBe('Hello')
    list.push('World!')
    expect(dummy).toBe('Hello World!')

    expect(fn).toHaveBeenCalledTimes(2) // normal

    list.shift()
    expect(dummy).toBe('World!')

    expect(fn).toHaveBeenCalledTimes(5) // It depends on list.length
  })

should cache effect funtion, like Watch Object in Vue 2, and trigger it nexttick?

@yyx990803
Copy link
Member

yyx990803 commented Oct 16, 2019

Raw effect will be called many times synchronously by default unless you provide a scheduler. Public APIs like watchers & component re-renders are buffered with a scheduler just like Vue 2.

@yyx990803 yyx990803 closed this Oct 16, 2019
@HowGraceU
Copy link
Author

I find it, thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants