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 the [=service worker registration/active worker=] of a [=/service worker registration=], specifications *may* invoke <a>fire a functional event</a>.
2149
+
To request a [=functional event=] dispatch to the [=service worker registration/active worker=] of a [=/service worker registration=], specifications *may* invoke [=Fire Functional Event=].
:: |eventConstructor|, an event constructor that extends {{ExtendableEvent}}
2817
2817
:: |registration|, a [=/service worker registration=]
2818
-
:: |initializationSteps|, optional steps to initialise |event|, constructed from |eventConstructor|
2818
+
:: |initialization|, optional property initialization for |event|, constructed from |eventConstructor|
2819
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=].
1. Invoke [=Run Service Worker=] algorithm with |activeWorker| as the argument.
2834
2834
1. [=Queue a task=] |task| to run these substeps:
2835
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|.
2836
+
1. If |initialization| is not null, then initialize |event| with |initialization|.
2837
2837
1. [=Dispatch=] |event| on |activeWorker|'s [=service worker/global object=].
2838
2838
1. Invoke [=Update Service Worker Extended Events Set=] with |activeWorker| and |event|.
2839
2839
1. If |postDispatchSteps| is not null, then run |postDispatchSteps| passing |event| as |dispatchedEvent|.
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
2848
2849
-
1. [=Fire a functional event=] named "`amazingthing`" using `AmazingThingEvent` on |serviceWorkerRegistration| with the following properties:
2849
+
1. [=Fire Functional Event=] "`amazingthing`" using `AmazingThingEvent` on |serviceWorkerRegistration| with the following properties:
2850
2850
: propertyName
2851
2851
:: value
2852
2852
: anotherPropertyName
2853
2853
:: anotherValue
2854
2854
2855
2855
Then run the following steps with |dispatchedEvent|:
2856
2856
2857
-
1. Do whatever you need to with |dispatchedEvent|.
2857
+
1. Do whatever you need to with |dispatchedEvent| on the service worker's event loop.
2858
2858
2859
2859
Note that the initialization steps and post-dispatch steps are optional. If they aren't needed, the prose would be:
2860
2860
2861
-
1. [=Fire a functional event=] named "`whatever`" using {{ExtendableEvent}} on |serviceWorkerRegistration|.
2861
+
1. [=Fire Functional Event=] "`whatever`" using {{ExtendableEvent}} on |serviceWorkerRegistration|.
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.
2077
-
2078
-
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.
2079
-
2080
-
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>.
2076
+
To request a [=functional event=] dispatch to the [=service worker registration/active worker=] of a [=/service worker registration=], specifications *may* invoke [=Fire Functional Event=].
:: |eventConstructor|, an event constructor that extends {{ExtendableEvent}}
2679
2676
:: |registration|, a [=/service worker registration=]
2680
-
:: |callbackSteps|, an algorithm
2677
+
:: |initialization|, optional property initialization for |event|, constructed from |eventConstructor|
2678
+
:: |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=].
2681
2679
: Output
2682
2680
:: None
2683
2681
2684
-
1. Assert: <a>scope to registration map</a> contains a value equal to |registration|.
2685
-
1. Assert: |registration|'s <a>active worker</a> is not null.
2686
-
1. Let |activeWorker| be |registration|'s <a>active worker</a>.
2687
-
1. If |activeWorker|'s <a>set of event types to handle</a> does not [=set/contain=] |event|'s {{Event/type}}, then:
2688
-
1. Return and continue running these steps <a>in parallel</a>.
2689
-
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|.
2682
+
1. Assert: [=scope to registration map=] contains a value equal to |registration|.
2683
+
1. Assert: |registration|'s [=active worker=] is not null.
2684
+
1. Let |activeWorker| be |registration|'s [=active worker=].
2685
+
1. If |activeWorker|'s [=set of event types to handle=] does not [=set/contain=] |eventName|, then return and run the following steps [=in parallel=]:
2686
+
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|.
2690
2687
1. Abort these steps.
2691
2688
2692
2689
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.
2693
2690
2694
-
1. If |activeWorker|'s <a>state</a> is *activating*, wait for |activeWorker|'s <a>state</a> to become *activated*.
2695
-
1. Invoke <a>Run Service Worker</a> algorithm with |activeWorker| as the argument.
2696
-
1. <a>Queue a task</a> |task| to run these substeps:
2697
-
1. Invoke |callbackSteps| with |activeWorker|'s [=service worker/global object=] as its argument.
2691
+
1. If |activeWorker|'s [=state=] is *activating*, wait for |activeWorker|'s [=state=] to become *activated*.
2692
+
1. Invoke [=Run Service Worker=] algorithm with |activeWorker| as the argument.
2693
+
1. [=Queue a task=] |task| to run these substeps:
2694
+
1. Let |event| be the result of [=creating an event=] with |eventConstructor| and the [=relevant realm=] of |activeWorker|'s [=service worker/global object=].
2695
+
1. If |initialization| is not null, then initialize |event| with |initialization|.
2696
+
1. [=Dispatch=] |event| on |activeWorker|'s [=service worker/global object=].
2698
2697
1. Invoke [=Update Service Worker Extended Events Set=] with |activeWorker| and |event|.
2698
+
1. If |postDispatchSteps| is not null, then run |postDispatchSteps| passing |event| as |dispatchedEvent|.
2699
2699
2700
-
The |task| *must* use |activeWorker|'s <a>event loop</a> and the <a>handle functional event task source</a>.
2700
+
The |task| *must* use |activeWorker|'s [=event loop=] and the [=handle functional event task source=].
2701
2701
2702
2702
1. Wait for |task| to have executed or been discarded.
2703
-
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|.
2703
+
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|.
2704
+
2705
+
<div class="example">
2706
+
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:
2707
+
2708
+
1. [=Fire Functional Event=] "`amazingthing`" using `AmazingThingEvent` on |serviceWorkerRegistration| with the following properties:
2709
+
: propertyName
2710
+
:: value
2711
+
: anotherPropertyName
2712
+
:: anotherValue
2713
+
2714
+
Then run the following steps with |dispatchedEvent|:
2715
+
2716
+
1. Do whatever you need to with |dispatchedEvent| on the service worker's event loop.
2717
+
2718
+
Note that the initialization steps and post-dispatch steps are optional. If they aren't needed, the prose would be:
2719
+
2720
+
1. [=Fire Functional Event=] "`whatever`" using {{ExtendableEvent}} on |serviceWorkerRegistration|.
0 commit comments