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
Modifier once for v-on #4267
Conversation
onceFlags[randomKey] = false | ||
const oldHandler = handler | ||
handler = () => { | ||
if (!onceFlags[randomKey]) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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) } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wait for it, sir.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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().
… handler arguments passing, bug fix of modifier ordering problem
…ring / once events for render function
@defcc Finished. Please review again. Thanks. |
Anybody home? Please review it. Thanks. |
As in the commits, there is a bug fix for the removal of event handlers. According to MDN,
|
Modifier once for v-on is added.