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

Add EventListenerOptions and passive event listeners #82

Closed
wants to merge 1 commit into from

Conversation

RByers
Copy link
Contributor

@RByers RByers commented Sep 22, 2015

My first crack at incorporating the ideas and discussion from my EventListenerOptions proposal into the spec. The result can be previewed here.

One thing I'm still not super happy with is the somewhat confusing defaults for mayCancel. On the one hand we agreed that we wanted the performance behavior (mayCancel:false) the be the default when using the new API form. But we of course can't change the existing behavior. Let's discuss that further here if desired.

@annevk
Copy link
Member

annevk commented Sep 22, 2015

How does this address e.g., WICG/EventListenerOptions#20? Also, it's very confusing to still have outstanding discussion elsewhere. Not really sure what to pay attention to now.

@annevk
Copy link
Member

annevk commented Sep 22, 2015

Basically, the way this is written I don't see much room for optimizations, unless you're doing something that's not allowed.

@RByers
Copy link
Contributor Author

RByers commented Sep 22, 2015

It's addressed by what @smaug--- said. I.e. whether or not a particular event is cancelable is not the purview of DOM, it's up to the individual specs. So a handler being added 'too late' is the same as other scenarios where a non-cancelable event is received by a handler, so already covered by the DOM spec. If we can get consensus here, then I'll add something to touch-events (w3c/touch-events/#6) that indicates that a TouchEvent may be uncancelable if, at the time it was first received, there are no mayCancel=true handlers for it. WDYT? Is there something more I should add here (perhaps expand on the note?).

Regarding discussion, I thought there were enough separate non-trivial issues (with non-trivial discussion history) that it was valuable to continue to use a separate issue tracker for them. But if you prefer I can try to close them all and merge all discussion into this PR. I don't have a preference on whether minor editorial discussion occurs here or in separate issues. But I defer to you on all of this - what's easiest for you at this stage?

@annevk
Copy link
Member

annevk commented Sep 23, 2015

Well, what I said in WICG/EventListenerOptions#20 (comment) is that what touch events do today doesn't require any changes in DOM. What you are suggesting here is that they observe listeners, which is something we want to avoid.

I don't really care where we settle on the design, but I'd like to settle on the design first. (I asked for the processing model before because the design wasn't clear. Now the processing model is clear, but the design seems wrong.)

@RByers
Copy link
Contributor Author

RByers commented Sep 23, 2015

Ok, I suggest we continue this conversation in WICG/EventListenerOptions#20 since it's (IMHO) a continuation of the same debate.

@annevk
Copy link
Member

annevk commented Nov 10, 2015

@RByers what is the plan for this feature?

@RByers
Copy link
Contributor Author

RByers commented Nov 10, 2015

@annevk Sorry for the delay, we're still working on it (I've just bee caught up in some other things). @dtapuska is actively working on the blink implementation. I expect to be able to make the spec work here my top priority in a couple weeks.

@RByers
Copy link
Contributor Author

RByers commented Nov 30, 2015

Ok @annevk, I've finally reworked this pull request according to your suggestions in WICG/EventListenerOptions#20. WDYT?

@RByers RByers changed the title Add EventListenerOptions Add EventListenerOptions and passive event listeners feature Dec 2, 2015
@RByers RByers changed the title Add EventListenerOptions and passive event listeners feature Add EventListenerOptions and passive event listeners Dec 2, 2015
just a boolean, in which case it determines the value of the <b>capture</b> option.

When set to true,
the <var>capture</var> option prevents <b>callback</b> from being invoked when
Copy link
Member

Choose a reason for hiding this comment

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

<var>capture</var> is no longer a variable so this seems wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How about the <b>capture</b> member of <var>options</var>? Or do you prefer simply the capture option?

Copy link
Member

Choose a reason for hiding this comment

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

I think "<var>options</var>' <code>capture</code> member" is what is typically used.

@RByers
Copy link
Contributor Author

RByers commented Dec 15, 2015

Thanks for the review! I've updated the pull request based on your feedback. I assume I should avoid squashing all the commits until the review is done and we're ready to merge.

@annevk
Copy link
Member

annevk commented Dec 16, 2015

Feel free to rebase and squash once you're confident it's in a good shape and I'll just do another pass. Might be easier.

@RByers
Copy link
Contributor Author

RByers commented Dec 16, 2015

Ok I think the only thing left is what exactly we want to cover in the "observing event listeners" section. Let's keep iterating on that, then once you're happy I'll rebase/squash (which I think will cause all the line-by-line discussions to disappear from GitHub :-( ).

{{Event/preventDefault()}} was invoked
while the {{Event/cancelable}} attribute
value is true, and false otherwise.
{{Event/preventDefault()}} was used successfully to indicate cancellation.
Copy link
Member

Choose a reason for hiding this comment

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

(Adding more nitpicky comments. Feel free to ignore for now.) s/used/invoked/ We don't want to omit mentioning when it returns false. The original text did that correctly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Whoops, must have lost this by accident somewhere along the line. Fixed.

<h3 id=observing-event-listeners>Observing event listeners</h3>

<p>In general, developers do not expect the presence of an <a>event listener</a> to be
observable. The impact of an <a>event listener</a> is determined by its <b>callback</b>.
Copy link
Member

Choose a reason for hiding this comment

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

Throughout, there should only be a single space after a period.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.


<li>Clear <var>event</var>'s <a>in passive listener flag</a>.

<li>If the call to {{EventListener/handleEvent()}} threw any exception, <a>report the exception</a>.
Copy link
Member

Choose a reason for hiding this comment

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

Are you sure this is correct? Reporting the exception is synchronous. Seems like you could circumvent the passive restriction by storing the event somewhere and then throwing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If reporting the exception is synchronous, then is it OK to just clear the passive listener flag afterwards (updated)? That would definitely be preferable, I was just thinking that wouldn't be possible.

Copy link
Member

Choose a reason for hiding this comment

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

As far as I can tell that's fine. Where do you think it would break?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I just wasn't thinking about it properly (thinking in terms of an algorithm with a 'throw' statement). Thanks for catching this, I agree it's better and I don't anticipate any implementation issue.

@annevk
Copy link
Member

annevk commented Jan 5, 2016

(Sorry, I was about to merge, but then I spotted that. Not sure why I didn't catch it earlier.)

@annevk
Copy link
Member

annevk commented Jan 5, 2016

The only other thing that looks a bit odd is the wrapping. I can clean that up I suppose.

@RByers
Copy link
Contributor Author

RByers commented Jan 5, 2016

The only other thing that looks a bit odd is the wrapping. I can clean that up I suppose.

Looks like the pattern is to use ~100 except in <pre> and <code> blocks, right? I'm fixing that now.

This introduces an EventListenerOptions dictionary which can
be used to explicitly specify options to addEventListener and
removeEventListener.

This also introduces a "passive" option, which disables the
ability for a listener to cancel the event.

See https://github.com/RByers/EventListenerOptions/blob/gh-pages/explainer.md
for a high-level overview, and
https://github.com/RByers/EventListenerOptions/issues?q=is%3Aissue
for most of the debate that went into the design.
@RByers
Copy link
Contributor Author

RByers commented Jan 5, 2016

Ok, re-wrapped all lines I touched to 100 columns (except <pre> and <code> blocks).

annevk pushed a commit that referenced this pull request Jan 6, 2016
This introduces an EventListenerOptions dictionary which can
be used to explicitly specify options for addEventListener()
and removeEventListener().

This also introduces a "passive" option, which disables the
ability for a listener to cancel the event.

See https://github.com/RByers/EventListenerOptions/blob/gh-pages/explainer.md
for a high-level overview, and
https://github.com/RByers/EventListenerOptions/issues?q=is%3Aissue
for most of the debate that went into the design.

PR: #82
@annevk
Copy link
Member

annevk commented Jan 6, 2016

Landed as 253a21b.

@annevk annevk closed this Jan 6, 2016
@annevk
Copy link
Member

annevk commented Jan 6, 2016

Thank you!

@RByers RByers deleted the event-listener-options branch September 27, 2016 16:28
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.

None yet

2 participants