@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.
package/dist/record.cjs CHANGED
@@ -10293,6 +10293,9 @@ const _ObserveManager = class _ObserveManager2 {
10293
10293
  constructor() {
10294
10294
  __publicField(this, "docsObservers", /* @__PURE__ */ new WeakSet());
10295
10295
  __publicField(this, "shadowRootsObservers", /* @__PURE__ */ new WeakSet());
10296
+ __publicField(this, "docsDebounceTimers", /* @__PURE__ */ new WeakMap());
10297
+ __publicField(this, "shadowRootsDebounceTimers", /* @__PURE__ */ new WeakMap());
10298
+ __publicField(this, "debounceTime", 15);
10296
10299
  __publicField(this, "mutationOptions");
10297
10300
  __publicField(this, "emitter", null);
10298
10301
  __publicField(this, "isSnapshottingShadowRoots", false);
@@ -10370,12 +10373,46 @@ const _ObserveManager = class _ObserveManager2 {
10370
10373
  });
10371
10374
  }
10372
10375
  serializeAndEmitDoc(doc) {
10376
+ debugLog(
10377
+ "onDocObserver: doc already observed, emitting full snapshot for doc",
10378
+ doc
10379
+ );
10380
+ this.isSnapshottingDocs = true;
10373
10381
  const serialized = this.serializeDoc(doc);
10374
10382
  this.emitDoc(serialized);
10383
+ this.isSnapshottingDocs = false;
10375
10384
  }
10376
10385
  serializeAndEmitShadowRoot(shadowRoot2) {
10386
+ debugLog(
10387
+ "onShadowRootObserver: shadowRoot already observed, emitting full snapshot for shadowRoot",
10388
+ shadowRoot2
10389
+ );
10390
+ this.isSnapshottingShadowRoots = true;
10377
10391
  const serialized = this.serializeDoc(shadowRoot2.ownerDocument);
10378
10392
  this.emitShadowRoot(serialized, shadowRoot2);
10393
+ this.isSnapshottingShadowRoots = false;
10394
+ }
10395
+ debounceEmitDoc(doc) {
10396
+ const existingTimer = this.docsDebounceTimers.get(doc);
10397
+ if (existingTimer) clearTimeout(existingTimer);
10398
+ this.docsDebounceTimers.set(
10399
+ doc,
10400
+ setTimeout(() => {
10401
+ this.docsDebounceTimers.delete(doc);
10402
+ this.serializeAndEmitDoc(doc);
10403
+ }, this.debounceTime)
10404
+ );
10405
+ }
10406
+ debounceEmitShadowRoot(shadowRoot2) {
10407
+ const existingTimer = this.shadowRootsDebounceTimers.get(shadowRoot2);
10408
+ if (existingTimer) clearTimeout(existingTimer);
10409
+ this.shadowRootsDebounceTimers.set(
10410
+ shadowRoot2,
10411
+ setTimeout(() => {
10412
+ this.shadowRootsDebounceTimers.delete(shadowRoot2);
10413
+ this.serializeAndEmitShadowRoot(shadowRoot2);
10414
+ }, this.debounceTime)
10415
+ );
10379
10416
  }
10380
10417
  onDocObserver(doc) {
10381
10418
  if (this.isSnapshottingDocs) return false;
@@ -10385,12 +10422,10 @@ const _ObserveManager = class _ObserveManager2 {
10385
10422
  return true;
10386
10423
  }
10387
10424
  debugLog(
10388
- "onDocObserver: doc already observed, emitting full snapshot for doc",
10425
+ "onDocObserver: doc already observed, debouncing full snapshot for doc",
10389
10426
  doc
10390
10427
  );
10391
- this.isSnapshottingDocs = true;
10392
- this.serializeAndEmitDoc(doc);
10393
- this.isSnapshottingDocs = false;
10428
+ this.debounceEmitDoc(doc);
10394
10429
  return false;
10395
10430
  }
10396
10431
  onShadowRootObserver(shadowRoot2) {
@@ -10401,12 +10436,10 @@ const _ObserveManager = class _ObserveManager2 {
10401
10436
  return true;
10402
10437
  }
10403
10438
  debugLog(
10404
- "onShadowRootObserver: shadowRoot already observed, emitting full snapshot for shadowRoot",
10439
+ "onShadowRootObserver: shadowRoot already observed, debouncing full snapshot for shadowRoot",
10405
10440
  shadowRoot2
10406
10441
  );
10407
- this.isSnapshottingShadowRoots = true;
10408
- this.serializeAndEmitShadowRoot(shadowRoot2);
10409
- this.isSnapshottingShadowRoots = false;
10442
+ this.debounceEmitShadowRoot(shadowRoot2);
10410
10443
  return false;
10411
10444
  }
10412
10445
  // canObserveDoc(doc: Document) {