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

Enable an event listener to be invoked just once #207

Merged
merged 1 commit into from
Apr 15, 2016
Merged

Enable an event listener to be invoked just once #207

merged 1 commit into from
Apr 15, 2016

Conversation

annevk
Copy link
Member

@annevk annevk commented Apr 8, 2016

No description provided.

@annevk
Copy link
Member Author

annevk commented Apr 8, 2016

I wasn't able to find the original request for this (I thought there was even an issue), but if you search for "addeventlistener once" you'll find some Stack Overflow threads requesting this.

@ArkadiuszMichalski
Copy link
Contributor

@annevk
Copy link
Member Author

annevk commented Apr 8, 2016

You're amazing, marked the bug "MOVED".

@RByers
Copy link
Contributor

RByers commented Apr 8, 2016

This makes sense to me. I don't know if people would choose to use this (with feature detection / polyfill for the next several years) over just writing the remove code themselves. But it seems like a nice easy little feature to have - even just planning for the far future when developers can depend on it being there.

@dtapuska / @tkent-google, what do you think? Pretty trivial to add, right?

@tkent-google
Copy link
Collaborator

This looks a useful flag. LGTM.

@josh
Copy link

josh commented Apr 11, 2016

Spiked out a polyfill implementation for this https://github.com/josh/event-listener-options-polyfill/pull/1

(edit: d'oh, looks like @RByers is already working this)

@annevk annevk merged commit e002d78 into master Apr 15, 2016
@annevk annevk deleted the once branch April 15, 2016 13:30
@Daniel15
Copy link

Daniel15 commented Apr 18, 2016

The spec should clarify what happens if the callback throws an exception. Based on my interpretation of this:

When set to true, options’s once member indicates that the callback will only be invoked once after which the event listener will be removed

It sounds like the event listener will be removed even if it doesn't run to completion, but it would be good to clarify this 👍

@annevk
Copy link
Member Author

annevk commented Apr 19, 2016

Callbacks throwing never really does anything to event dispatch. (The exceptions are reported per https://dom.spec.whatwg.org/#concept-event-listener-inner-invoke.) Where would you expect to see this clarified?

@Daniel15
Copy link

Good catch, I missed that part of the spec.

@cvrebert
Copy link
Member

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

Successfully merging this pull request may close these issues.

7 participants