registerQuotaErrorCallback.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. Copyright 2019 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 { logger } from './_private/logger.js';
  8. import { assert } from './_private/assert.js';
  9. import { quotaErrorCallbacks } from './models/quotaErrorCallbacks.js';
  10. import './_version.js';
  11. /**
  12. * Adds a function to the set of quotaErrorCallbacks that will be executed if
  13. * there's a quota error.
  14. *
  15. * @param {Function} callback
  16. * @memberof workbox-core
  17. */
  18. // Can't change Function type
  19. // eslint-disable-next-line @typescript-eslint/ban-types
  20. function registerQuotaErrorCallback(callback) {
  21. if (process.env.NODE_ENV !== 'production') {
  22. assert.isType(callback, 'function', {
  23. moduleName: 'workbox-core',
  24. funcName: 'register',
  25. paramName: 'callback',
  26. });
  27. }
  28. quotaErrorCallbacks.add(callback);
  29. if (process.env.NODE_ENV !== 'production') {
  30. logger.log('Registered a callback to respond to quota errors.', callback);
  31. }
  32. }
  33. export { registerQuotaErrorCallback };