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

Modifier once for v-on #4267

Merged
merged 5 commits into from Nov 30, 2016
Merged

Modifier once for v-on #4267

merged 5 commits into from Nov 30, 2016

Conversation

KingMario
Copy link
Contributor

@KingMario KingMario commented Nov 21, 2016

Modifier once for v-on is added.

onceFlags[randomKey] = false
const oldHandler = handler
handler = () => {
if (!onceFlags[randomKey]) {
Copy link
Member

@defcc defcc Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not just remove the event handle after invoked?

Copy link
Contributor Author

@KingMario KingMario Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good question.

Actually, some bugs were found and the pr is way not completed. I'm still working on it.

</div>
`,
methods: {
foo () { numberPushed.push(1) }
Copy link
Member

@defcc defcc Nov 21, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you could create a jasmine.createSpy(), and use expect(spy).not.toHaveBeenCalled() to check it.

Copy link
Contributor Author

@KingMario KingMario Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait for it, sir.

Copy link
Contributor Author

@KingMario KingMario Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made changes to this pr locally, but while running the unit test, encountered with some problem:

    triggerEvent(vm.$el, 'click')
    expect(spy).toHaveBeenCalled()
    triggerEvent(vm.$el, 'click')
    expect(spy).not.toHaveBeenCalled()

The second assertion fails.

Will the second assertion be misjudged by the first call?

  it('should support capture and once', () => {
    const callOrder = []
    vm = new Vue({
      el,
      template: `
        <div @click.capture.once="foo">
          <div @click="bar"></div>
        </div>
      `,
      methods: {
        foo () { callOrder.push(1) },
        bar () { callOrder.push(2) }
      }
    })
    triggerEvent(vm.$el.firstChild, 'click')
    expect(callOrder.toString()).toBe('1,2')
    triggerEvent(vm.$el.firstChild, 'click')
    expect(callOrder.toString()).toBe('1,2,2')
  })

Both of the assertions in this test success.

Copy link
Contributor Author

@KingMario KingMario Nov 22, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Figured out that, in this case, should use spy.calls.count().

cygeng added 3 commits Nov 22, 2016
… handler arguments passing, bug fix of modifier ordering problem
@KingMario
Copy link
Contributor Author

KingMario commented Nov 22, 2016

@defcc Finished. Please review again. Thanks.

@KingMario
Copy link
Contributor Author

KingMario commented Nov 29, 2016

Anybody home? Please review it. Thanks.

@KingMario
Copy link
Contributor Author

KingMario commented Nov 29, 2016

As in the commits, there is a bug fix for the removal of event handlers.

According to MDN,

Removal of a capturing listener does not affect a non-capturing version of the same listener, and vice versa.

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.

None yet

3 participants