From 2e723a201073b60c96e02a9adecde71a85ef6080 Mon Sep 17 00:00:00 2001 From: Yanzhen Yu Date: Mon, 8 Mar 2021 13:30:54 +0800 Subject: [PATCH] impl #507 export takeFullSnapshot as a public API --- src/record/index.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/record/index.ts b/src/record/index.ts index b6e378d4..7e229c98 100644 --- a/src/record/index.ts +++ b/src/record/index.ts @@ -28,6 +28,8 @@ function wrapEvent(e: event): eventWithTime { let wrappedEmit!: (e: eventWithTime, isCheckout?: boolean) => void; +let takeFullSnapshot!: (isCheckout?: boolean) => void; + function record( options: recordOptions = {}, ): listenerHandler | undefined { @@ -190,7 +192,7 @@ function record( ), }); - function takeFullSnapshot(isCheckout = false) { + takeFullSnapshot = (isCheckout = false) => { wrappedEmit( wrapEvent({ type: EventType.Meta, @@ -251,7 +253,7 @@ function record( }), ); 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[] = []; @@ -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;