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.
2394
-
2395
-
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.
2396
-
2397
-
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>.
2393
+
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>
3109
3105
3110
3106
: Input
3111
-
:: |event|, an {{ExtendableEvent}} object
3107
+
:: |eventName|, a DOMString
3108
+
:: |eventConstructor|, an event constructor that extends {{ExtendableEvent}}
3112
3109
:: |registration|, a [=/service worker registration=]
3113
-
:: |callbackSteps|, an algorithm
3110
+
:: |initializationSteps|, optional steps to initialise |event|, constructed from |eventConstructor|
3111
+
:: |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=].
3114
3112
: Output
3115
3113
:: None
3116
3114
3117
-
1. Assert: <a>scope to registration map</a> contains a value equal to |registration|.
3118
-
1. Assert: |registration|'s <a>active worker</a> is not null.
3119
-
1. Let |activeWorker| be |registration|'s <a>active worker</a>.
3120
-
1. If |activeWorker|'s <a>set of event types to handle</a> does not [=set/contain=] |event|'s {{Event/type}}, then:
3121
-
1. Return and continue running these steps <a>in parallel</a>.
3122
-
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|.
3115
+
1. Assert: [=scope to registration map=] contains a value equal to |registration|.
3116
+
1. Assert: |registration|'s [=active worker=] is not null.
3117
+
1. Let |activeWorker| be |registration|'s [=active worker=].
3118
+
1. If |activeWorker|'s [=set of event types to handle=] does not [=set/contain=] |eventName|, then return and run the following steps [=in parallel=]:
3119
+
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|.
3123
3120
1. Abort these steps.
3124
3121
3125
3122
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.
3126
3123
3127
-
1. If |activeWorker|'s <a>state</a> is *activating*, wait for |activeWorker|'s <a>state</a> to become *activated*.
3128
-
1. Invoke <a>Run Service Worker</a> algorithm with |activeWorker| as the argument.
3129
-
1. <a>Queue a task</a> |task| to run these substeps:
3130
-
1. Invoke |callbackSteps| with |activeWorker|'s [=service worker/global object=] as its argument.
3124
+
1. If |activeWorker|'s [=state=] is *activating*, wait for |activeWorker|'s [=state=] to become *activated*.
3125
+
1. Invoke [=Run Service Worker=] algorithm with |activeWorker| as the argument.
3126
+
1. [=Queue a task=] |task| to run these substeps:
3127
+
1. Let |event| be the result of [=creating an event=] with |eventConstructor| and the [=relevant realm=] of |activeWorker|'s [=service worker/global object=].
3128
+
1. If |initializationSteps| is not null, then initialize |event| with |initializationSteps|.
3129
+
1. [=Dispatch=] |event| on |activeWorker|'s [=service worker/global object=].
3131
3130
1. Invoke [=Update Service Worker Extended Events Set=] with |activeWorker| and |event|.
3131
+
1. If |postDispatchSteps| is not null, then run |postDispatchSteps| passing |event| as |dispatchedEvent|.
3132
3132
3133
-
The |task| *must* use |activeWorker|'s <a>event loop</a> and the <a>handle functional event task source</a>.
3133
+
The |task| *must* use |activeWorker|'s [=event loop=] and the [=handle functional event task source=].
3134
3134
3135
3135
1. Wait for |task| to have executed or been discarded.
3136
-
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|.
3136
+
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|.
3137
+
3138
+
<div class="example">
3139
+
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:
3140
+
3141
+
1. [=Fire a functional event=] named "`amazingthing`" using `AmazingThingEvent` on |serviceWorkerRegistration| with the following properties:
3142
+
: propertyName
3143
+
:: value
3144
+
: anotherPropertyName
3145
+
:: anotherValue
3146
+
3147
+
Then run the following steps with |dispatchedEvent|:
3148
+
3149
+
1. Do whatever you need to with |dispatchedEvent|.
3150
+
3151
+
Note that the initialization steps and post-dispatch steps are optional. If they aren't needed, the prose would be:
3152
+
3153
+
1. [=Fire a functional event=] named "`whatever`" using {{ExtendableEvent}} on |serviceWorkerRegistration|.
0 commit comments