- Handle Functional Event
+ Fire Functional Event
: Input
- :: |event|, an {{ExtendableEvent}} object
+ :: |eventName|, a string
+ :: |eventConstructor|, an event constructor that extends {{ExtendableEvent}}
:: |registration|, a [=/service worker registration=]
- :: |callbackSteps|, an algorithm
+ :: |initialization|, optional property initialization for |event|, constructed from |eventConstructor|
+ :: |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=].
: Output
:: None
- 1. Assert: scope to registration map contains a value equal to |registration|.
- 1. Assert: |registration|'s active worker is not null.
- 1. Let |activeWorker| be |registration|'s active worker.
- 1. If |activeWorker|'s set of event types to handle does not [=set/contain=] |event|'s {{Event/type}}, then:
- 1. Return and continue running these steps in parallel.
- 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|.
+ 1. Assert: [=scope to registration map=] contains a value equal to |registration|.
+ 1. Assert: |registration|'s [=active worker=] is not null.
+ 1. Let |activeWorker| be |registration|'s [=active worker=].
+ 1. If |activeWorker|'s [=set of event types to handle=] does not [=set/contain=] |eventName|, then return and run the following steps [=in parallel=]:
+ 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|.
1. Abort these steps.
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.
- 1. If |activeWorker|'s state is *activating*, wait for |activeWorker|'s state to become *activated*.
- 1. Invoke Run Service Worker algorithm with |activeWorker| as the argument.
- 1. Queue a task |task| to run these substeps:
- 1. Invoke |callbackSteps| with |activeWorker|'s [=service worker/global object=] as its argument.
+ 1. If |activeWorker|'s [=state=] is *activating*, wait for |activeWorker|'s [=state=] to become *activated*.
+ 1. Invoke [=Run Service Worker=] algorithm with |activeWorker| as the argument.
+ 1. [=Queue a task=] |task| to run these substeps:
+ 1. Let |event| be the result of [=creating an event=] with |eventConstructor| and the [=relevant realm=] of |activeWorker|'s [=service worker/global object=].
+ 1. If |initialization| is not null, then initialize |event| with |initialization|.
+ 1. [=Dispatch=] |event| on |activeWorker|'s [=service worker/global object=].
1. Invoke [=Update Service Worker Extended Events Set=] with |activeWorker| and |event|.
+ 1. If |postDispatchSteps| is not null, then run |postDispatchSteps| passing |event| as |dispatchedEvent|.
- The |task| *must* use |activeWorker|'s event loop and the handle functional event task source.
+ The |task| *must* use |activeWorker|'s [=event loop=] and the [=handle functional event task source=].
1. Wait for |task| to have executed or been discarded.
- 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|.
+ 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|.
+
+
+ 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:
+
+ 1. [=Fire Functional Event=] "`amazingthing`" using `AmazingThingEvent` on |serviceWorkerRegistration| with the following properties:
+ : propertyName
+ :: value
+ : anotherPropertyName
+ :: anotherValue
+
+ Then run the following steps with |dispatchedEvent|:
+
+ 1. Do whatever you need to with |dispatchedEvent| on the service worker's event loop.
+
+ Note that the initialization steps and post-dispatch steps are optional. If they aren't needed, the prose would be:
+
+ 1. [=Fire Functional Event=] "`whatever`" using {{ExtendableEvent}} on |serviceWorkerRegistration|.
+