Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Refactor to preclude the need for a continuous raf loop
  • Loading branch information
eoghanmurray committed Apr 11, 2024
commit 6cb833570a62149782675366ea4b9a8b43071b0a
27 changes: 9 additions & 18 deletions packages/rrweb/src/record/processed-node-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,8 @@ import type MutationBuffer from './mutation';
*/
export default class ProcessedNodeManager {
private nodeMap: WeakMap<Node, Set<MutationBuffer>> = new WeakMap();
// Whether to continue RAF loop.
private loop = true;

constructor() {
this.periodicallyClear();
}

private periodicallyClear() {
requestAnimationFrame(() => {
this.clear();
if (this.loop) this.periodicallyClear();
});
}
private active = false;

public inOtherBuffer(node: Node, thisBuffer: MutationBuffer) {
const buffers = this.nodeMap.get(node);
Expand All @@ -27,15 +16,17 @@ export default class ProcessedNodeManager {
}

public add(node: Node, buffer: MutationBuffer) {
if (!this.active) {
this.active = true;
requestAnimationFrame(() => {
this.nodeMap = new WeakMap();
this.active = false;
});
}
this.nodeMap.set(node, (this.nodeMap.get(node) || new Set()).add(buffer));
}

private clear() {
this.nodeMap = new WeakMap();
}

public destroy() {
// Stop the RAF loop.
this.loop = false;
// cleanup no longer needed
}
}