summaryrefslogtreecommitdiff
path: root/apps/web/src/lib/commands/preview-tracker.ts
diff options
context:
space:
mode:
Diffstat (limited to 'apps/web/src/lib/commands/preview-tracker.ts')
-rw-r--r--apps/web/src/lib/commands/preview-tracker.ts23
1 files changed, 23 insertions, 0 deletions
diff --git a/apps/web/src/lib/commands/preview-tracker.ts b/apps/web/src/lib/commands/preview-tracker.ts
new file mode 100644
index 00000000..68c8dee3
--- /dev/null
+++ b/apps/web/src/lib/commands/preview-tracker.ts
@@ -0,0 +1,23 @@
+export class PreviewTracker<T> {
+ private snapshot: T | null = null;
+
+ begin({ state }: { state: T }): void {
+ if (this.snapshot === null) {
+ this.snapshot = structuredClone(state);
+ }
+ }
+
+ isActive(): boolean {
+ return this.snapshot !== null;
+ }
+
+ getSnapshot(): T | null {
+ return this.snapshot;
+ }
+
+ end(): T | null {
+ const snapshot = this.snapshot;
+ this.snapshot = null;
+ return snapshot;
+ }
+}