You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To request a <a>functional event</a> dispatch to a [=/service worker=], specifications *may* invoke <a>Handle Functional Event</a> algorithm with its [=/service worker registration=]<var ignore>registration</var> and the algorithm |callbackSteps| as the arguments.
2150
-
2151
-
Specifications *may* define an algorithm |callbackSteps| where the corresponding <a>functional event</a> can be created and fired with specification specific objects. The algorithm is passed <var ignore>globalObject</var> (a {{ServiceWorkerGlobalScope}} object) at which it *may* fire its <a>functional events</a>. This algorithm is called on a <a>task</a><a lt="queue a task">queued</a> by <a>Handle Functional Event</a> algorithm.
2152
-
2153
-
Note: See an <a href="https://notifications.spec.whatwg.org/#activating-a-notification">example</a> hook defined in <a biblio data-biblio-type="informative" lt="notifications">Notifications API</a>.
2149
+
To request a <a>functional event</a> dispatch to the [=service worker registration/active worker=] of a [=/service worker registration=], specifications *may* invoke <a>fire a functional event</a>.
<h3 id="fire-functional-event-algorithm"><dfn export>Fire a Functional Event</dfn></h3>
2817
2813
2818
2814
: Input
2819
-
:: |event|, an {{ExtendableEvent}} object
2815
+
:: |eventName|, a DOMString
2816
+
:: |eventConstructor|, an event constructor that extends {{ExtendableEvent}}
2820
2817
:: |registration|, a [=/service worker registration=]
2821
-
:: |callbackSteps|, an algorithm
2818
+
:: |initializationSteps|, optional steps to initialise |event|, constructed from |eventConstructor|
2819
+
:: |postDispatchSteps|, optional steps to run on the [=service worker registration/active worker=]'s event loop, with |dispatchedEvent| set to the instance of |eventConstructor| that was [=dispatched=].
2822
2820
: Output
2823
2821
:: None
2824
2822
2825
-
1. Assert: <a>scope to registration map</a> contains a value equal to |registration|.
2826
-
1. Assert: |registration|'s <a>active worker</a> is not null.
2827
-
1. Let |activeWorker| be |registration|'s <a>active worker</a>.
2828
-
1. If |activeWorker|'s <a>set of event types to handle</a> does not [=set/contain=] |event|'s {{Event/type}}, then:
2829
-
1. Return and continue running these steps <a>in parallel</a>.
2830
-
1. If the time difference in seconds calculated by the current time minus |registration|'s <a>last update check time</a> is greater than 86400, invoke <a>Soft Update</a> algorithm with |registration|.
2823
+
1. Assert: [=scope to registration map=] contains a value equal to |registration|.
2824
+
1. Assert: |registration|'s [=active worker=] is not null.
2825
+
1. Let |activeWorker| be |registration|'s [=active worker=].
2826
+
1. If |activeWorker|'s [=set of event types to handle=] does not [=set/contain=] |eventName|, then return and run the following steps [=in parallel=]:
2827
+
1. If the time difference in seconds calculated by the current time minus |registration|'s [=last update check time=] is greater than 86400, invoke [=Soft Update=] algorithm with |registration|.
2831
2828
1. Abort these steps.
2832
2829
2833
2830
Note: To avoid unnecessary delays, the Handle Functional Event enforces early return when no event listeners have been deterministically added in the service worker's global during the very first script execution.
2834
2831
2835
-
1. If |activeWorker|'s <a>state</a> is *activating*, wait for |activeWorker|'s <a>state</a> to become *activated*.
2836
-
1. Invoke <a>Run Service Worker</a> algorithm with |activeWorker| as the argument.
2837
-
1. <a>Queue a task</a> |task| to run these substeps:
2838
-
1. Invoke |callbackSteps| with |activeWorker|'s [=service worker/global object=] as its argument.
2832
+
1. If |activeWorker|'s [=state=] is *activating*, wait for |activeWorker|'s [=state=] to become *activated*.
2833
+
1. Invoke [=Run Service Worker=] algorithm with |activeWorker| as the argument.
2834
+
1. [=Queue a task=] |task| to run these substeps:
2835
+
1. Let |event| be the result of [=creating an event=] with |eventConstructor| and the [=relevant realm=] of |activeWorker|'s [=service worker/global object=].
2836
+
1. If |initializationSteps| is not null, then initialize |event| with |initializationSteps|.
2837
+
1. [=Dispatch=] |event| on |activeWorker|'s [=service worker/global object=].
2839
2838
1. Invoke [=Update Service Worker Extended Events Set=] with |activeWorker| and |event|.
2839
+
1. If |postDispatchSteps| is not null, then run |postDispatchSteps| passing |event| as |dispatchedEvent|.
2840
2840
2841
-
The |task| *must* use |activeWorker|'s <a>event loop</a> and the <a>handle functional event task source</a>.
2841
+
The |task| *must* use |activeWorker|'s [=event loop=] and the [=handle functional event task source=].
2842
2842
2843
2843
1. Wait for |task| to have executed or been discarded.
2844
-
1. If the time difference in seconds calculated by the current time minus |registration|'s <a>last update check time</a> is greater than 86400, invoke <a>Soft Update</a> algorithm with |registration|.
2844
+
1. If the time difference in seconds calculated by the current time minus |registration|'s [=last update check time=] is greater than 86400, invoke [=Soft Update=] algorithm with |registration|.
2845
+
2846
+
<div class="example">
2847
+
To fire an "`amazingthing`" event (which is of type `AmazingThingEvent`) on a particular |serviceWorkerRegistration|, and initialize the event object's properties, the prose would be:
2848
+
2849
+
1. [=Fire a functional event=] named "`amazingthing`" using `AmazingThingEvent` on |serviceWorkerRegistration| with the following properties:
2850
+
: propertyName
2851
+
:: value
2852
+
: anotherPropertyName
2853
+
:: anotherValue
2854
+
2855
+
Then run the following steps with |dispatchedEvent|:
2856
+
2857
+
1. Do whatever you need to with |dispatchedEvent|.
2858
+
2859
+
Note that the initialization steps and post-dispatch steps are optional. If they aren't needed, the prose would be:
2860
+
2861
+
1. [=Fire a functional event=] named "`whatever`" using {{ExtendableEvent}} on |serviceWorkerRegistration|.
0 commit comments