diff --git a/dom.bs b/dom.bs index ea0828c68..b1565101b 100644 --- a/dom.bs +++ b/dom.bs @@ -53,8 +53,8 @@ urlPrefix: https://w3c.github.io/ServiceWorker/#; spec: SERVICE-WORKERS text: script resource; for: service worker text: has ever been evaluated flag; for: service worker urlPrefix: https://tc39.github.io/ecma262/#; spec: ECMASCRIPT - text: Construct; url: sec-construct; type: abstract-op text: Realm; url: realm; type: dfn + text: SameValueZero; url: sec-samevaluezero; type: abstract-op
@@ -314,7 +314,7 @@ run these steps: Throughout the web platform events are dispatched to objects to signal an occurrence, such as network activity or user interaction. These objects implement the {{EventTarget}} interface and can therefore add event listeners to observe -events by calling {{EventTarget/addEventListener()}}: +events by calling {{EventTarget/addEventListener(type, callback, options)}}:@@ -913,6 +935,8 @@ when something has occurred.obj.addEventListener("load", imgFetched) @@ -325,10 +325,23 @@ function imgFetched(ev) { }-Event listeners can be removed -by utilizing the -{{EventTarget/removeEventListener()}} -method, passing the same arguments. +Event listeners can be removed by utilizing the +{{EventTarget/removeEventListener(type, callback, options)}} method, passing the same arguments. + +Once can also provide a group when adding an event listener. This can be any value, +including a simple string. Then later, the same group value can be provided to +{{EventTarget/removeEventListener(type, options)}} or {{EventTarget/removeEventListener(options)}}, +to remove all event listeners in that group: + ++oven.addEventListener("turnon", () => { … }, { group: "cookies" }) +oven.addEventListener("heat", () => { … }, { group: "cookies" }) +oven.addEventListener("turnoff", () => { … }, { group: "cookies" }) + +oven.removeEventListener({ group: "cookies" }) ++ +
Events are objects too and implement the {{Event}} interface (or a derived interface). In the example above @@ -879,7 +892,11 @@ for historical reasons. [Exposed=(Window,Worker)] interface EventTarget { void addEventListener(DOMString type, EventListener? callback, optional (AddEventListenerOptions or boolean) options); + void removeEventListener(DOMString type, EventListener? callback, optional (EventListenerOptions or boolean) options); + void removeEventListener(DOMString type, RemoveEventListenerGroupOptions options); + void removeEventListener(RemoveEventListenerGroupOptions options); + boolean dispatchEvent(Event event); }; @@ -891,9 +908,14 @@ dictionary EventListenerOptions { boolean capture = false; }; +dictionary RemoveEventListenerGroupOptions { + required any group; +}; + dictionary AddEventListenerOptions : EventListenerOptions { boolean passive = false; boolean once = false; + any group; };
capture
member.
+ options's {{EventListenerOptions/capture}} member.
- When set to true, options' capture
member prevents callback from
- being invoked when the event's {{Event/eventPhase}} attribute value is
+ When set to true, options's {{EventListenerOptions/capture}} member prevents
+ callback from being invoked when the event's {{Event/eventPhase}} attribute value is
{{Event/BUBBLING_PHASE}}. When false (or not present), callback will not be invoked when
event's {{Event/eventPhase}} attribute value is {{Event/CAPTURING_PHASE}}. Either way,
callback will be invoked if event's {{Event/eventPhase}} attribute value is
{{Event/AT_TARGET}}.
- When set to true, options' passive
member indicates that the
- callback will not cancel the event by invoking {{Event/preventDefault()}}. This is used to
- enable performance optimizations described in [[#observing-event-listeners]].
+ When set to true, options' {{AddEventListenerOptions/passive}} member indicates that
+ the callback will not cancel the event by invoking {{Event/preventDefault()}}. This is used
+ to enable performance optimizations described in [[#observing-event-listeners]].
+
+ When set to true, options's {{AddEventListenerOptions/once}} member indicates that the
+ callback will only be invoked once after which the event listener will be removed.
- 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.
+ When provided, options's {{AddEventListenerOptions/group}} member is stored so that
+ later calls to {{EventTarget/removeEventListener(type, options)}} or
+ {{EventTarget/removeEventListener(options)}} can remove all event listeners that provided the same
+ group value.
The event listener is appended to target's list of event listeners and is
not appended if it is a duplicate, i.e., having the same type, callback, and
capture values.
- target . removeEventListener(type, callback [, options])
- target . removeEventListener(type, callback [, options])
+ target . removeEventListener(type, { group })
+ target . removeEventListener({ group })
+ target . dispatchEvent(event)
If options is a boolean, set capture to options. -
If options is a dictionary, then set capture to options's
- {{EventListenerOptions/capture}}
.
+
If options is a dictionary, then set capture to + options["{{EventListenerOptions/capture}}"].
Return capture. @@ -1005,52 +1039,64 @@ steps:
Let capture be the result of flattening options. -
Let once and passive be false. +
Let once, passive, and is grouped be false, and let group be null. -
If options is a dictionary, then set passive to options's
- {{AddEventListenerOptions/passive}}
and once to options's
- {{AddEventListenerOptions/once}}
.
+
If options is a dictionary, then: +
Set passive to options["{{AddEventListenerOptions/passive}}"] and + once to options["{{AddEventListenerOptions/once}}"]. + +
If {{AddEventListenerOptions/group}} is present in options, set + is grouped to true and set group to + options["{{AddEventListenerOptions/group}}"]. +
Return capture, passive, and once. +
Return the tuple (capture, passive, once, is grouped, + group).
To perform a service worker check on eventTarget, +throw a {{TypeError}} if eventTarget's relevant global object is a +{{ServiceWorkerGlobalScope}} object and its associated service worker's +script resource's +has ever been evaluated flag is set. [[!SERVICE-WORKERS]] + +
To optimize storing the event types allowed for the service worker and to +avoid non-deterministic changes to the event listeners, invocation of certain {{EventTarget}} +methods is allowed only during the very first evaluation of the service worker script. + +
Two Web IDL values are equal for grouping purposes if, when +converted to ECMAScript values, the results are equivalent according to +SameValueZero. [[!ECMASCRIPT]] +
The
addEventListener(type, callback, options)
method, when invoked, must run these steps:
If context object's relevant global object is a {{ServiceWorkerGlobalScope}}
- object and its associated service worker's script resource's
- has ever been evaluated flag is set, then throw a
- TypeError
.
- [[!SERVICE-WORKERS]]
-
-
To optimize storing the event types allowed for the service worker and - to avoid non-deterministic changes to the event listeners, invocation of the method is allowed - only during the very first evaluation of the service worker script. +
If callback is null, then return. -
Let capture, passive, and once be the result of - flattening more options. +
Let (capture, passive, once, is grouped, + group) be the result of flattening more options.
If context object's associated list of event listener does not contain an event listener whose type is type, callback is callback, - and capture is capture, then append a new event listener to it, whose + capture is capture, is grouped is is grouped, and group + is equal to group, then append a new event listener to it, whose type is type, callback is callback, capture is - capture, passive is passive, and once is once. + capture, passive is passive, once is once, + is grouped is is grouped, and group is group.
The
removeEventListener(type, callback, options)
-method, when invoked, must, run these steps
+method overload, when invoked, must run these steps
If context object's relevant global object is a {{ServiceWorkerGlobalScope}}
- object and its associated service worker's script resource's
- has ever been evaluated flag is set, then throw a
- TypeError
. [[!SERVICE-WORKERS]]
+
Let capture be the result of flattening options. @@ -1060,6 +1106,31 @@ method, when invoked, must, run these steps the associated list of event listeners.
The
+removeEventListener(type, options)
+method overload, when invoked, must run these steps
+
+
Remove all event listeners in the associated list of event listeners whose + type is type, is grouped is true, and group is + equal for grouping purposes to + options["{{RemoveEventListenerGroupOptions/group}}"]. +
The
+removeEventListener(options)
+method overload, when invoked, must run these steps
+
+
Remove all event listeners in the associated list of event listeners whose + is grouped is true and group is equal for grouping purposes to + options["{{RemoveEventListenerGroupOptions/group}}"]. +
The dispatchEvent(event)
method, when
invoked, must run these steps: