source: frontend/node_modules/workbox-broadcast-update/BroadcastUpdatePlugin.js

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

Fix frontend appearance

  • Property mode set to 100644
File size: 2.1 KB
Line 
1/*
2 Copyright 2018 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 { dontWaitFor } from 'workbox-core/_private/dontWaitFor.js';
9import { BroadcastCacheUpdate, } from './BroadcastCacheUpdate.js';
10import './_version.js';
11/**
12 * This plugin will automatically broadcast a message whenever a cached response
13 * is updated.
14 *
15 * @memberof workbox-broadcast-update
16 */
17class BroadcastUpdatePlugin {
18 /**
19 * Construct a {@link workbox-broadcast-update.BroadcastUpdate} instance with
20 * the passed options and calls its `notifyIfUpdated` method whenever the
21 * plugin's `cacheDidUpdate` callback is invoked.
22 *
23 * @param {Object} [options]
24 * @param {Array<string>} [options.headersToCheck=['content-length', 'etag', 'last-modified']]
25 * A list of headers that will be used to determine whether the responses
26 * differ.
27 * @param {string} [options.generatePayload] A function whose return value
28 * will be used as the `payload` field in any cache update messages sent
29 * to the window clients.
30 */
31 constructor(options) {
32 /**
33 * A "lifecycle" callback that will be triggered automatically by the
34 * `workbox-sw` and `workbox-runtime-caching` handlers when an entry is
35 * added to a cache.
36 *
37 * @private
38 * @param {Object} options The input object to this function.
39 * @param {string} options.cacheName Name of the cache being updated.
40 * @param {Response} [options.oldResponse] The previous cached value, if any.
41 * @param {Response} options.newResponse The new value in the cache.
42 * @param {Request} options.request The request that triggered the update.
43 * @param {Request} options.event The event that triggered the update.
44 */
45 this.cacheDidUpdate = async (options) => {
46 dontWaitFor(this._broadcastUpdate.notifyIfUpdated(options));
47 };
48 this._broadcastUpdate = new BroadcastCacheUpdate(options);
49 }
50}
51export { BroadcastUpdatePlugin };
Note: See TracBrowser for help on using the repository browser.