PreloadScriptStorage.js 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.PreloadScriptStorage = void 0;
  4. /**
  5. * Container class for preload scripts.
  6. */
  7. class PreloadScriptStorage {
  8. /** Tracks all BiDi preload scripts. */
  9. #scripts = new Set();
  10. /** Finds all entries that match the given filter. */
  11. findPreloadScripts(filter) {
  12. if (!filter) {
  13. return [...this.#scripts];
  14. }
  15. return [...this.#scripts].filter((script) => {
  16. if (filter.id !== undefined && filter.id !== script.id) {
  17. return false;
  18. }
  19. if (filter.contextId !== undefined &&
  20. filter.contextId !== script.contextId) {
  21. return false;
  22. }
  23. if (filter.contextIds !== undefined &&
  24. !filter.contextIds.includes(script.contextId)) {
  25. return false;
  26. }
  27. if (filter.targetId !== undefined &&
  28. !script.targetIds.has(filter.targetId)) {
  29. return false;
  30. }
  31. return true;
  32. });
  33. }
  34. addPreloadScript(preloadScript) {
  35. this.#scripts.add(preloadScript);
  36. }
  37. /** Deletes all BiDi preload script entries that match the given filter. */
  38. removeBiDiPreloadScripts(filter) {
  39. for (const preloadScript of this.findPreloadScripts(filter)) {
  40. this.#scripts.delete(preloadScript);
  41. }
  42. }
  43. }
  44. exports.PreloadScriptStorage = PreloadScriptStorage;
  45. //# sourceMappingURL=PreloadScriptStorage.js.map