BackgroundSyncPlugin.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. /*
  2. Copyright 2018 Google LLC
  3. Use of this source code is governed by an MIT-style
  4. license that can be found in the LICENSE file or at
  5. https://opensource.org/licenses/MIT.
  6. */
  7. import { Queue } from './Queue.js';
  8. import './_version.js';
  9. /**
  10. * A class implementing the `fetchDidFail` lifecycle callback. This makes it
  11. * easier to add failed requests to a background sync Queue.
  12. *
  13. * @memberof module:workbox-background-sync
  14. */
  15. class BackgroundSyncPlugin {
  16. /**
  17. * @param {string} name See the [Queue]{@link module:workbox-background-sync.Queue}
  18. * documentation for parameter details.
  19. * @param {Object} [options] See the
  20. * [Queue]{@link module:workbox-background-sync.Queue} documentation for
  21. * parameter details.
  22. */
  23. constructor(name, options) {
  24. /**
  25. * @param {Object} options
  26. * @param {Request} options.request
  27. * @private
  28. */
  29. this.fetchDidFail = async ({ request }) => {
  30. await this._queue.pushRequest({ request });
  31. };
  32. this._queue = new Queue(name, options);
  33. }
  34. }
  35. export { BackgroundSyncPlugin };