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

Editorial: add "add an event listener" hook #596

Merged
merged 4 commits into from
Mar 14, 2018

Conversation

annevk
Copy link
Member

@annevk annevk commented Mar 13, 2018

This hook ensures that any special casing in addEventListener() is shared with event handler attributes.

Helps with w3c/ServiceWorker#1004.


Preview | Diff

This hook ensures that any special casing in addEventListener() is shared with event handler attributes.

Helps with w3c/ServiceWorker#1004.
@domenic
Copy link
Member

domenic commented Mar 13, 2018

Since event handlers don't have options, maybe this should accept a few booleans instead of a dictionary-or-boolean (with good defaults that make sense for event handlers)?

@annevk
Copy link
Member Author

annevk commented Mar 13, 2018

I'd rather not make this an ever expanding set of arguments. I'd be okay with making the last argument optional to make the HTML caller slightly less ugly, but I'm not sure it's worth it.

@domenic
Copy link
Member

domenic commented Mar 13, 2018

The issue is that for anyone that calls it except for the addEventListener() definition, they have to manually assemble an AddEventListenerOptions dict, which feels like it should be specific to the addEventListener API and to JS consumers of it.

@annevk
Copy link
Member Author

annevk commented Mar 13, 2018

I guess you're considering a third caller we haven't decided on adding thus far. I guess if that might not use AddEventListenerOptions we should make that argument optional for now and not pass it from HTML. Then whenever this third caller comes around we can restructure this without having to change HTML.

@domenic
Copy link
Member

domenic commented Mar 13, 2018

@annevk
Copy link
Member Author

annevk commented Mar 13, 2018

Hmm, I suppose we could use that signature, requiring the caller to create an event listener concept wrapper.

@annevk
Copy link
Member Author

annevk commented Mar 13, 2018

I pushed a more elaborate change here that also integrates with Infra better and basically does the above comment. The only thing I wonder about is whether service workers throw before returning if callback is null, but that was already a problem of sorts.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Only editorial issues; the approach looks good.

@@ -328,7 +328,7 @@ method, passing the same arguments.
{{Event}} interface (or a derived interface). In the example above
<var ignore>ev</var> is the <a>event</a>. It is
passed as argument to
<a>event listener</a>'s <b>callback</b>
<a>event listener</a>'s <a for="event listener">callback</a>
Copy link
Member

Choose a reason for hiding this comment

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

Yesss I've been wanting this for a while.

dom.bs Outdated
The <var>options</var> argument sets listener-specific options. For compatibility this can be just
a boolean, in which case the method behaves exactly as if the value was specified as
<p>The <var>options</var> argument sets listener-specific options. For compatibility this can be a
boolean, in which case the method behaves exactly as if the value was specified as
<var>options</var>' <code>capture</code> member.
Copy link
Member

Choose a reason for hiding this comment

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

While here you could make all these <code>s link to the dictionary member definitions, as is done in the algorithms below.

dom.bs Outdated
<a>event</a>'s {{Event/eventPhase}} attribute value is {{Event/CAPTURING_PHASE}}. Either way,
<b>callback</b> will be invoked if <a>event</a>'s {{Event/eventPhase}} attribute value is
{{Event/AT_TARGET}}.
<p>When set to true, <var>options</var>' <code>capture</code> member prevents
Copy link
Member

Choose a reason for hiding this comment

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

While here you could consistify to use "options's" per https://wiki.whatwg.org/wiki/Style#Grammar

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought there was still an exception when the word is plural?

Copy link
Member

Choose a reason for hiding this comment

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

We've had this discussion before :). options is not a class of values; it is a single JS value. So it's not really plural in the grammatical sense that would trigger leaving off the s, where capture belongs to a collection of options.

Stated another way, here "options" is short for "options variable", which is not plural.

A case where it would be plural is "the stock options' combined value was a billion dollars."

dom.bs Outdated
<p>The
<dfn method for=EventTarget><code>addEventListener(<var>type</var>, <var>callback</var>, <var>options</var>)</code></dfn>
method, when invoked, must run these steps:
<p>To <dfn export>add an event listener</dfn> given an <code>EventTarget</code> object
Copy link
Member

Choose a reason for hiding this comment

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

{{EventTarget}} instead of just code

dom.bs Outdated
</ol>

<p class=note>The <a>add an event listener</a> concept exists to ensure
<a>event handler attributes</a> use the same code path. [[HTML]]
Copy link
Member

Choose a reason for hiding this comment

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

This link is not working

@annevk
Copy link
Member Author

annevk commented Mar 14, 2018

I think I addressed the feedback, but I ended up touching some unrelated sections since it seemed good to make those suggested editorial changes consistently throughout.

Copy link
Member

@domenic domenic left a comment

Choose a reason for hiding this comment

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

Lovely stuff

@annevk annevk merged commit 2bdabb1 into master Mar 14, 2018
annevk added a commit to whatwg/html that referenced this pull request Mar 14, 2018
This hook was provided whatwg/dom#596 and event handlers need to use it to fix whatwg/dom#365 and w3c/ServiceWorker#1004 properly. Tests will be added as part of resolving those issues.
@annevk annevk deleted the annevk/add-an-event-listener branch March 14, 2018 09:24
alice pushed a commit to alice/html that referenced this pull request Jan 8, 2019
This hook was provided whatwg/dom#596 and event handlers need to use it to fix whatwg/dom#365 and w3c/ServiceWorker#1004 properly. Tests will be added as part of resolving those issues.
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.

2 participants