@glimt/record 0.0.33 → 0.0.34

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
@@ -9624,44 +9624,42 @@ class IframeManager {
9624
9624
  }
9625
9625
  }
9626
9626
  }
9627
- function makeid$1(length = 8) {
9628
- var result2 = "";
9629
- var characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
9630
- var charactersLength = characters.length;
9631
- for (var i2 = 0; i2 < length; i2++) {
9632
- result2 += characters.charAt(Math.floor(Math.random() * charactersLength));
9633
- }
9634
- return result2;
9635
- }
9636
9627
  const _StormSnapshotManager = class _StormSnapshotManager2 {
9637
9628
  constructor() {
9638
- __publicField(this, "id", makeid$1());
9639
9629
  __publicField(this, "lastFullSnapshot", -1);
9640
9630
  __publicField(this, "intervalBetweenSnapshots", 150);
9631
+ __publicField(this, "debounceTimeout", null);
9632
+ __publicField(this, "debounceTime", 10);
9641
9633
  if (_StormSnapshotManager2.instance) {
9642
9634
  return _StormSnapshotManager2.instance;
9643
9635
  }
9644
9636
  _StormSnapshotManager2.instance = this;
9645
9637
  }
9646
- requestFullSnapshot(bufferId) {
9647
- if (!takeFullSnapshot) return;
9638
+ //we're debouncing here because of how mutation buffers work.
9639
+ //multiple observers create their own mutation buffer, and
9640
+ //each buffer will handle mutations storms, so multiple buffers
9641
+ //will probably request a full snapshot at (basically) the same time.
9642
+ //we want to ensure all buffers have requested a full snapshot
9643
+ //(so we can be sure that all mutations have been made)
9644
+ //before we actually take a full snapshot.
9645
+ //also, we want a low debounceTime, bc if theres multiple, distinctive mutation storms,
9646
+ //in a somewhat quick succession, we want to record activity between them
9647
+ //not just one full snapshot after all the storms
9648
+ requestFullSnapshot() {
9649
+ if (this.debounceTimeout) {
9650
+ clearTimeout(this.debounceTimeout);
9651
+ }
9652
+ this.debounceTimeout = setTimeout(() => {
9653
+ this.debounceTimeout = null;
9654
+ this.takeSnapshot();
9655
+ }, this.debounceTime);
9656
+ }
9657
+ takeSnapshot() {
9648
9658
  if (Date.now() - this.lastFullSnapshot < this.intervalBetweenSnapshots) {
9649
- console.log(
9650
- "requestFullSnapshot: too soon",
9651
- "storm snapshot mng id:",
9652
- this.id,
9653
- "bufferId:",
9654
- bufferId
9655
- );
9659
+ console.log("StormSnapshotManager, takeSnapshot: too soon");
9656
9660
  return;
9657
9661
  }
9658
- console.log(
9659
- "taking full snapshot",
9660
- "storm snapshot mng id:",
9661
- this.id,
9662
- "bufferId:",
9663
- bufferId
9664
- );
9662
+ console.log("StormSnapshotManager, takeSnapshot: taking full snapshot");
9665
9663
  takeFullSnapshot();
9666
9664
  this.lastFullSnapshot = Date.now();
9667
9665
  }
@@ -9865,7 +9863,7 @@ class MutationBuffer {
9865
9863
  this.processInternalMutations(muts, true);
9866
9864
  } else {
9867
9865
  this.stormBatches = [];
9868
- stormSnapshotManager.requestFullSnapshot(this.bufId);
9866
+ stormSnapshotManager.requestFullSnapshot();
9869
9867
  }
9870
9868
  });
9871
9869
  __publicField(this, "processInternalMutations", (muts, overrideStorm = false) => {