UNPKG

1.1 kBJavaScriptView Raw
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 { Queue } from './Queue.js';
9import './_version.js';
10/**
11 * A class implementing the `fetchDidFail` lifecycle callback. This makes it
12 * easier to add failed requests to a background sync Queue.
13 *
14 * @memberof workbox-background-sync
15 */
16class BackgroundSyncPlugin {
17 /**
18 * @param {string} name See the {@link workbox-background-sync.Queue}
19 * documentation for parameter details.
20 * @param {Object} [options] See the
21 * {@link workbox-background-sync.Queue} documentation for
22 * parameter details.
23 */
24 constructor(name, options) {
25 /**
26 * @param {Object} options
27 * @param {Request} options.request
28 * @private
29 */
30 this.fetchDidFail = async ({ request }) => {
31 await this._queue.pushRequest({ request });
32 };
33 this._queue = new Queue(name, options);
34 }
35}
36export { BackgroundSyncPlugin };