source: frontend/node_modules/workbox-window/messageSW.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 1.1 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*/
8import './_version.js';
9/**
10 * Sends a data object to a service worker via `postMessage` and resolves with
11 * a response (if any).
12 *
13 * A response can be set in a message handler in the service worker by
14 * calling `event.ports[0].postMessage(...)`, which will resolve the promise
15 * returned by `messageSW()`. If no response is set, the promise will not
16 * resolve.
17 *
18 * @param {ServiceWorker} sw The service worker to send the message to.
19 * @param {Object} data An object to send to the service worker.
20 * @return {Promise<Object|undefined>}
21 * @memberof workbox-window
22 */
23// Better not change type of data.
24// eslint-disable-next-line @typescript-eslint/ban-types
25function messageSW(sw, data) {
26 return new Promise((resolve) => {
27 const messageChannel = new MessageChannel();
28 messageChannel.port1.onmessage = (event) => {
29 resolve(event.data);
30 };
31 sw.postMessage(data, [messageChannel.port2]);
32 });
33}
34export { messageSW };
Note: See TracBrowser for help on using the repository browser.