Skip to content

Commit

Permalink
Rename paused -> frozen for consistency and change to use getter/sett…
Browse files Browse the repository at this point in the history
…er access methods
  • Loading branch information
eoghanmurray committed Oct 4, 2020
1 parent c93fbfd commit 1006d8e
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
14 changes: 7 additions & 7 deletions src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ function record<T = eventWithTime>(
let incrementalSnapshotCount = 0;
wrappedEmit = (e: eventWithTime, isCheckout?: boolean) => {
if (
mutationBuffer.paused &&
mutationBuffer.isFrozen() &&
e.type !== EventType.FullSnapshot &&
!(
e.type == EventType.IncrementalSnapshot &&
Expand All @@ -92,7 +92,7 @@ function record<T = eventWithTime>(
// we've got a user initiated event so first we need to apply
// all DOM changes that have been buffering during paused state
mutationBuffer.emit();
mutationBuffer.paused = false;
mutationBuffer.unfreeze();
}

emit(((packFn ? packFn(e) : e) as unknown) as T, isCheckout);
Expand Down Expand Up @@ -125,8 +125,8 @@ function record<T = eventWithTime>(
isCheckout,
);

let wasPaused = mutationBuffer.paused;
mutationBuffer.paused = true; // don't allow any mirror modifications during snapshotting
let wasFrozen = mutationBuffer.isFrozen();
mutationBuffer.freeze(); // don't allow any mirror modifications during snapshotting
const [node, idNodeMap] = snapshot(
document,
blockClass,
Expand Down Expand Up @@ -164,9 +164,9 @@ function record<T = eventWithTime>(
},
}),
);
if (!wasPaused) {
if (!wasFrozen) {
mutationBuffer.emit(); // emit anything queued up now
mutationBuffer.paused = false;
mutationBuffer.unfreeze();
}
}

Expand Down Expand Up @@ -347,7 +347,7 @@ record.addCustomEvent = <T>(tag: string, payload: T) => {
};

record.freezePage = () => {
mutationBuffer.paused = true;
mutationBuffer.freeze();
};

export default record;
16 changes: 14 additions & 2 deletions src/record/mutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function isINode(n: Node | INode): n is INode {
* controls behaviour of a MutationObserver
*/
export default class MutationBuffer {
public paused: boolean = false;
private frozen: boolean = false;

private texts: textCursor[] = [];
private attributes: attributeCursor[] = [];
Expand Down Expand Up @@ -159,9 +159,21 @@ export default class MutationBuffer {
this.emissionCallback = cb;
}

public freeze() {
this.frozen = true;
}

public unfreeze() {
this.frozen = false;
}

public isFrozen() {
return this.frozen;
}

public processMutations = (mutations: mutationRecord[]) => {
mutations.forEach(this.processMutation);
if (!this.paused) {
if (!this.frozen) {
this.emit();
}
};
Expand Down
3 changes: 2 additions & 1 deletion typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ import { mirror } from './utils';
import * as utils from './utils';
export { EventType, IncrementalSource, MouseInteractions, ReplayerEvents, } from './types';
declare const addCustomEvent: <T>(tag: string, payload: T) => void;
export { record, addCustomEvent, Replayer, mirror, utils };
declare const freezePage: () => void;
export { record, addCustomEvent, freezePage, Replayer, mirror, utils };
5 changes: 4 additions & 1 deletion typings/record/mutation.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { MaskInputOptions } from 'rrweb-snapshot';
import { mutationRecord, blockClass, mutationCallBack } from '../types';
export default class MutationBuffer {
paused: boolean;
private frozen;
private texts;
private attributes;
private removes;
Expand All @@ -16,6 +16,9 @@ export default class MutationBuffer {
private maskInputOptions;
private recordCanvas;
init(cb: mutationCallBack, blockClass: blockClass, inlineStylesheet: boolean, maskInputOptions: MaskInputOptions, recordCanvas: boolean): void;
freeze(): void;
unfreeze(): void;
isFrozen(): boolean;
processMutations: (mutations: mutationRecord[]) => void;
emit: () => void;
private processMutation;
Expand Down

0 comments on commit 1006d8e

Please sign in to comment.