@glimt/record 0.0.78 → 0.0.80

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -10335,8 +10335,13 @@ const _ObserveManager = class _ObserveManager2 {
10335
10335
  constructor() {
10336
10336
  __publicField(this, "docsObservers", /* @__PURE__ */ new WeakSet());
10337
10337
  __publicField(this, "shadowRootsObservers", /* @__PURE__ */ new WeakSet());
10338
+ __publicField(this, "docsDebounceTimers", /* @__PURE__ */ new WeakMap());
10339
+ __publicField(this, "shadowRootsDebounceTimers", /* @__PURE__ */ new WeakMap());
10340
+ __publicField(this, "debounceTime", 15);
10338
10341
  __publicField(this, "mutationOptions");
10339
10342
  __publicField(this, "emitter", null);
10343
+ __publicField(this, "isSnapshottingShadowRoots", false);
10344
+ __publicField(this, "isSnapshottingDocs", false);
10340
10345
  if (_ObserveManager2.instance) {
10341
10346
  return _ObserveManager2.instance;
10342
10347
  }
@@ -10409,37 +10414,73 @@ const _ObserveManager = class _ObserveManager2 {
10409
10414
  });
10410
10415
  }
10411
10416
  serializeAndEmitDoc(doc) {
10417
+ debugLog(
10418
+ "onDocObserver: doc already observed, emitting full snapshot for doc",
10419
+ doc
10420
+ );
10421
+ this.isSnapshottingDocs = true;
10412
10422
  const serialized = this.serializeDoc(doc);
10413
10423
  this.emitDoc(serialized);
10424
+ this.isSnapshottingDocs = false;
10414
10425
  }
10415
10426
  serializeAndEmitShadowRoot(shadowRoot2) {
10427
+ debugLog(
10428
+ "onShadowRootObserver: shadowRoot already observed, emitting full snapshot for shadowRoot",
10429
+ shadowRoot2
10430
+ );
10431
+ this.isSnapshottingShadowRoots = true;
10416
10432
  const serialized = this.serializeDoc(shadowRoot2.ownerDocument);
10417
10433
  this.emitShadowRoot(serialized, shadowRoot2);
10434
+ this.isSnapshottingShadowRoots = false;
10435
+ }
10436
+ debounceEmitDoc(doc) {
10437
+ const existingTimer = this.docsDebounceTimers.get(doc);
10438
+ if (existingTimer) clearTimeout(existingTimer);
10439
+ this.docsDebounceTimers.set(
10440
+ doc,
10441
+ setTimeout(() => {
10442
+ this.docsDebounceTimers.delete(doc);
10443
+ this.serializeAndEmitDoc(doc);
10444
+ }, this.debounceTime)
10445
+ );
10446
+ }
10447
+ debounceEmitShadowRoot(shadowRoot2) {
10448
+ const existingTimer = this.shadowRootsDebounceTimers.get(shadowRoot2);
10449
+ if (existingTimer) clearTimeout(existingTimer);
10450
+ this.shadowRootsDebounceTimers.set(
10451
+ shadowRoot2,
10452
+ setTimeout(() => {
10453
+ this.shadowRootsDebounceTimers.delete(shadowRoot2);
10454
+ this.serializeAndEmitShadowRoot(shadowRoot2);
10455
+ }, this.debounceTime)
10456
+ );
10418
10457
  }
10419
10458
  onDocObserver(doc) {
10459
+ if (this.isSnapshottingDocs) return false;
10420
10460
  if (!this.usable) return false;
10421
10461
  if (!this.docsObservers.has(doc)) {
10422
10462
  this.docsObservers.add(doc);
10423
10463
  return true;
10424
10464
  }
10425
10465
  debugLog(
10426
- "onDocObserver: doc already observed, emitting full snapshot for doc",
10466
+ "onDocObserver: doc already observed, debouncing full snapshot for doc",
10427
10467
  doc
10428
10468
  );
10429
- this.serializeAndEmitDoc(doc);
10469
+ this.debounceEmitDoc(doc);
10430
10470
  return false;
10431
10471
  }
10432
10472
  onShadowRootObserver(shadowRoot2) {
10473
+ if (this.isSnapshottingShadowRoots) return false;
10433
10474
  if (!this.usable) return false;
10434
10475
  if (!this.shadowRootsObservers.has(shadowRoot2)) {
10435
10476
  this.shadowRootsObservers.add(shadowRoot2);
10436
10477
  return true;
10437
10478
  }
10438
10479
  debugLog(
10439
- "onShadowRootObserver: shadowRoot already observed, emitting full snapshot for shadowRoot",
10480
+ "onShadowRootObserver: shadowRoot already observed, debouncing full snapshot for shadowRoot",
10440
10481
  shadowRoot2
10441
10482
  );
10442
- this.serializeAndEmitShadowRoot(shadowRoot2);
10483
+ this.debounceEmitShadowRoot(shadowRoot2);
10443
10484
  return false;
10444
10485
  }
10445
10486
  // canObserveDoc(doc: Document) {