@glimt/record 0.0.79 → 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,6 +10335,9 @@ 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);
10340
10343
  __publicField(this, "isSnapshottingShadowRoots", false);
@@ -10411,12 +10414,46 @@ const _ObserveManager = class _ObserveManager2 {
10411
10414
  });
10412
10415
  }
10413
10416
  serializeAndEmitDoc(doc) {
10417
+ debugLog(
10418
+ "onDocObserver: doc already observed, emitting full snapshot for doc",
10419
+ doc
10420
+ );
10421
+ this.isSnapshottingDocs = true;
10414
10422
  const serialized = this.serializeDoc(doc);
10415
10423
  this.emitDoc(serialized);
10424
+ this.isSnapshottingDocs = false;
10416
10425
  }
10417
10426
  serializeAndEmitShadowRoot(shadowRoot2) {
10427
+ debugLog(
10428
+ "onShadowRootObserver: shadowRoot already observed, emitting full snapshot for shadowRoot",
10429
+ shadowRoot2
10430
+ );
10431
+ this.isSnapshottingShadowRoots = true;
10418
10432
  const serialized = this.serializeDoc(shadowRoot2.ownerDocument);
10419
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
+ );
10420
10457
  }
10421
10458
  onDocObserver(doc) {
10422
10459
  if (this.isSnapshottingDocs) return false;
@@ -10426,12 +10463,10 @@ const _ObserveManager = class _ObserveManager2 {
10426
10463
  return true;
10427
10464
  }
10428
10465
  debugLog(
10429
- "onDocObserver: doc already observed, emitting full snapshot for doc",
10466
+ "onDocObserver: doc already observed, debouncing full snapshot for doc",
10430
10467
  doc
10431
10468
  );
10432
- this.isSnapshottingDocs = true;
10433
- this.serializeAndEmitDoc(doc);
10434
- this.isSnapshottingDocs = false;
10469
+ this.debounceEmitDoc(doc);
10435
10470
  return false;
10436
10471
  }
10437
10472
  onShadowRootObserver(shadowRoot2) {
@@ -10442,12 +10477,10 @@ const _ObserveManager = class _ObserveManager2 {
10442
10477
  return true;
10443
10478
  }
10444
10479
  debugLog(
10445
- "onShadowRootObserver: shadowRoot already observed, emitting full snapshot for shadowRoot",
10480
+ "onShadowRootObserver: shadowRoot already observed, debouncing full snapshot for shadowRoot",
10446
10481
  shadowRoot2
10447
10482
  );
10448
- this.isSnapshottingShadowRoots = true;
10449
- this.serializeAndEmitShadowRoot(shadowRoot2);
10450
- this.isSnapshottingShadowRoots = false;
10483
+ this.debounceEmitShadowRoot(shadowRoot2);
10451
10484
  return false;
10452
10485
  }
10453
10486
  // canObserveDoc(doc: Document) {