Skip to content

Commit

Permalink
impl #507 export takeFullSnapshot as a public API
Browse files Browse the repository at this point in the history
  • Loading branch information
Yuyz0112 committed Mar 8, 2021
1 parent fc4dc95 commit 2e723a2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/record/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ function wrapEvent(e: event): eventWithTime {

let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void;

let takeFullSnapshot!: (isCheckout?: boolean) => void;

function record<T = eventWithTime>(
options: recordOptions<T> = {},
): listenerHandler | undefined {
Expand Down Expand Up @@ -190,7 +192,7 @@ function record<T = eventWithTime>(
),
});

function takeFullSnapshot(isCheckout = false) {
takeFullSnapshot = (isCheckout = false) => {
wrappedEmit(
wrapEvent({
type: EventType.Meta,
Expand Down Expand Up @@ -251,7 +253,7 @@ function record<T = eventWithTime>(
}),
);
mutationBuffers.forEach((buf) => buf.unlock()); // generate & emit any mutations that happened during snapshotting, as can now apply against the newly built mirror
}
};

try {
const handlers: listenerHandler[] = [];
Expand Down Expand Up @@ -455,4 +457,11 @@ record.freezePage = () => {
mutationBuffers.forEach((buf) => buf.freeze());
};

record.takeFullSnapshot = (isCheckout?: boolean) => {
if (!takeFullSnapshot) {
throw new Error('please take full snapshot after start recording');
}
takeFullSnapshot(isCheckout);
};

export default record;

0 comments on commit 2e723a2

Please sign in to comment.