Skip to content

Commit 14bdd67

Browse files
authored
Add ability to reset the mapping id, to facilitate destructor in rrweb (rrwebRecord.stop) (#49)
1 parent b3e7d5a commit 14bdd67

File tree

4 files changed

+10
-2
lines changed

4 files changed

+10
-2
lines changed

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import snapshot, {
22
serializeNodeWithId,
33
transformAttribute,
44
visitSnapshot,
5+
cleanupSnapshot,
56
IGNORED_NODE,
67
} from './snapshot';
78
import rebuild, { buildNodeWithSN, addHoverClass } from './rebuild';
@@ -15,5 +16,6 @@ export {
1516
addHoverClass,
1617
transformAttribute,
1718
visitSnapshot,
19+
cleanupSnapshot,
1820
IGNORED_NODE,
1921
};

src/snapshot.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,4 +570,9 @@ export function visitSnapshot(
570570
walk(node);
571571
}
572572

573+
export function cleanupSnapshot() {
574+
// allow a new recording to start numbering nodes from scratch
575+
_id = 1;
576+
}
577+
573578
export default snapshot;

typings/index.d.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import snapshot, { serializeNodeWithId, transformAttribute, visitSnapshot, IGNORED_NODE } from './snapshot';
1+
import snapshot, { serializeNodeWithId, transformAttribute, visitSnapshot, IGNORED_NODE, cleanupSnapshot } from './snapshot';
22
import rebuild, { buildNodeWithSN, addHoverClass } from './rebuild';
33
export * from './types';
4-
export { snapshot, serializeNodeWithId, rebuild, buildNodeWithSN, addHoverClass, transformAttribute, visitSnapshot, IGNORED_NODE, };
4+
export { snapshot, serializeNodeWithId, rebuild, buildNodeWithSN, addHoverClass, transformAttribute, visitSnapshot, IGNORED_NODE, cleanupSnapshot, };

typings/snapshot.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,5 @@ export declare function transformAttribute(doc: Document, name: string, value: s
66
export declare function serializeNodeWithId(n: Node | INode, doc: Document, map: idNodeMap, blockClass: string | RegExp, skipChild?: boolean, inlineStylesheet?: boolean, maskInputOptions?: MaskInputOptions, slimDOMOptions?: SlimDOMOptions, recordCanvas?: boolean, preserveWhiteSpace?: boolean): serializedNodeWithId | null;
77
declare function snapshot(n: Document, blockClass: string | RegExp | undefined, inlineStylesheet: boolean | undefined, maskAllInputsOrOptions: boolean | MaskInputOptions, slimDOMSensibleOrOptions: boolean | SlimDOMOptions, recordCanvas?: boolean): [serializedNodeWithId | null, idNodeMap];
88
export declare function visitSnapshot(node: serializedNodeWithId, onVisit: (node: serializedNodeWithId) => unknown): void;
9+
export declare function cleanupSnapshot(): void;
910
export default snapshot;

0 commit comments

Comments
 (0)