Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(effect): vue-next effect function will be called more than once when Array.prototype.shift be called #10705 #311

Closed
wants to merge 1 commit into from

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