source: frontend/node_modules/workbox-window/src/messageSW.ts@ cdcff72

Last change on this file since cdcff72 was 9af201e, checked in by MBK <marija.karapandzova@…>, 12 days ago

Fix frontend appearance

  • Property mode set to 100644
File size: 1.2 KB
Line 
1/*
2 Copyright 2019 Google LLC
3
4 Use of this source code is governed by an MIT-style
5 license that can be found in the LICENSE file or at
6 https://opensource.org/licenses/MIT.
7*/
8
9import './_version.js';
10
11/**
12 * Sends a data object to a service worker via `postMessage` and resolves with
13 * a response (if any).
14 *
15 * A response can be set in a message handler in the service worker by
16 * calling `event.ports[0].postMessage(...)`, which will resolve the promise
17 * returned by `messageSW()`. If no response is set, the promise will not
18 * resolve.
19 *
20 * @param {ServiceWorker} sw The service worker to send the message to.
21 * @param {Object} data An object to send to the service worker.
22 * @return {Promise<Object|undefined>}
23 * @memberof workbox-window
24 */
25// Better not change type of data.
26// eslint-disable-next-line @typescript-eslint/ban-types
27function messageSW(sw: ServiceWorker, data: {}): Promise<any> {
28 return new Promise((resolve) => {
29 const messageChannel = new MessageChannel();
30 messageChannel.port1.onmessage = (event: MessageEvent) => {
31 resolve(event.data);
32 };
33 sw.postMessage(data, [messageChannel.port2]);
34 });
35}
36
37export {messageSW};
Note: See TracBrowser for help on using the repository browser.