Skip to content

Commit 33f7886

Browse files
committed
feat: Remove unusuedrecord.xxx methods & module scope vars
1 parent 6dc2af8 commit 33f7886

File tree

1 file changed

+15
-33
lines changed

1 file changed

+15
-33
lines changed

packages/rrweb/src/record/index.ts

Lines changed: 15 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,11 @@ declare global {
6565
const __RRWEB_EXCLUDE_IFRAME__: boolean;
6666
}
6767

68-
let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void;
69-
70-
let _takeFullSnapshot!: (isCheckout?: boolean) => void;
71-
let canvasManager: CanvasManagerInterface;
72-
let recording = false;
68+
// Tihs is stored in module scope because we access it in other exported methods
69+
let _takeFullSnapshot: undefined | ((isCheckout?: boolean) => void);
7370

7471
export const mirror = createMirror();
72+
7573
function record<T = eventWithTime>(
7674
options: recordOptions<T> = {},
7775
): listenerHandler | undefined {
@@ -211,7 +209,7 @@ function record<T = eventWithTime>(
211209
}
212210
return e as unknown as T;
213211
};
214-
wrappedEmit = (e: eventWithTime, isCheckout?: boolean) => {
212+
const wrappedEmit = (e: eventWithTime, isCheckout?: boolean) => {
215213
if (
216214
mutationBuffers[0]?.isFrozen() &&
217215
e.type !== EventType.FullSnapshot &&
@@ -256,7 +254,7 @@ function record<T = eventWithTime>(
256254
checkoutEveryNms &&
257255
e.timestamp - lastFullSnapshotEvent.timestamp > checkoutEveryNms;
258256
if (exceedCount || exceedTime) {
259-
_takeFullSnapshot(true);
257+
takeFullSnapshot(true);
260258
}
261259
}
262260
};
@@ -335,7 +333,7 @@ function record<T = eventWithTime>(
335333

336334
const processedNodeManager = new ProcessedNodeManager();
337335

338-
canvasManager =
336+
const canvasManager: CanvasManagerInterface =
339337
typeof __RRWEB_EXCLUDE_CANVAS__ === 'boolean' && __RRWEB_EXCLUDE_CANVAS__
340338
? new CanvasManagerNoop()
341339
: new CanvasManager({
@@ -386,7 +384,7 @@ function record<T = eventWithTime>(
386384
mirror,
387385
});
388386

389-
_takeFullSnapshot = (isCheckout = false) => {
387+
const takeFullSnapshot = (isCheckout = false) => {
390388
wrappedEmit(
391389
wrapEvent({
392390
type: EventType.Meta,
@@ -468,6 +466,7 @@ function record<T = eventWithTime>(
468466
mirror.getId(document),
469467
);
470468
};
469+
_takeFullSnapshot = takeFullSnapshot;
471470

472471
try {
473472
const handlers: listenerHandler[] = [];
@@ -644,9 +643,8 @@ function record<T = eventWithTime>(
644643
});
645644

646645
const init = () => {
647-
_takeFullSnapshot();
646+
takeFullSnapshot();
648647
handlers.push(observe(document));
649-
recording = true;
650648
};
651649
if (
652650
document.readyState === 'interactive' ||
@@ -684,7 +682,7 @@ function record<T = eventWithTime>(
684682
return () => {
685683
handlers.forEach((h) => h());
686684
processedNodeManager.destroy();
687-
recording = false;
685+
_takeFullSnapshot = undefined;
688686
unregisterErrorHandler();
689687
};
690688
} catch (error) {
@@ -693,34 +691,18 @@ function record<T = eventWithTime>(
693691
}
694692
}
695693

696-
record.addCustomEvent = <T>(tag: string, payload: T) => {
697-
if (!recording) {
698-
throw new Error('please add custom event after start recording');
699-
}
700-
wrappedEmit(
701-
wrapEvent({
702-
type: EventType.Custom,
703-
data: {
704-
tag,
705-
payload,
706-
},
707-
}),
708-
);
709-
};
710-
711-
record.freezePage = () => {
712-
mutationBuffers.forEach((buf) => buf.freeze());
713-
};
694+
// record.addCustomEvent is removed because Sentry Session Replay does not use it
695+
// record.freezePage is removed because Sentry Session Replay does not use it
714696

715697
export function takeFullSnapshot(isCheckout?: boolean) {
716-
if (!recording) {
698+
if (!_takeFullSnapshot) {
717699
throw new Error('please take full snapshot after start recording');
718700
}
719701
_takeFullSnapshot(isCheckout);
720702
}
721703

722-
record.takeFullSnapshot = takeFullSnapshot;
723-
704+
// For backwards compatibility - we can eventually remove this when we migrated to using the exported `mirror` & `takeFullSnapshot`
724705
record.mirror = mirror;
706+
record.takeFullSnapshot = takeFullSnapshot;
725707

726708
export default record;

0 commit comments

Comments
 (0)