Plugin.mjs 967 B

123456789101112131415161718192021222324252627282930313233343536373839
  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.mjs';
  8. import './_version.mjs';
  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 workbox.backgroundSync
  14. */
  15. class Plugin {
  16. /**
  17. * @param {...*} queueArgs Args to forward to the composed Queue instance.
  18. * See the [Queue]{@link workbox.backgroundSync.Queue} documentation for
  19. * parameter details.
  20. */
  21. constructor(...queueArgs) {
  22. this._queue = new Queue(...queueArgs);
  23. this.fetchDidFail = this.fetchDidFail.bind(this);
  24. }
  25. /**
  26. * @param {Object} options
  27. * @param {Request} options.request
  28. * @private
  29. */
  30. async fetchDidFail({request}) {
  31. await this._queue.pushRequest({request});
  32. }
  33. }
  34. export {Plugin};