MCPcopy Create free account
hub / github.com/DeepNotesApp/DeepNotes / revertToSnapshot

Function revertToSnapshot

apps/client/src/code/pages/utils.ts:37–59  ·  view source on GitHub ↗
(doc: Y.Doc, snapshotUpdate: Uint8Array)

Source from the content-addressed store, hash-verified

35}
36
37export function revertToSnapshot(doc: Y.Doc, snapshotUpdate: Uint8Array) {
38 const auxDoc = createPageDoc();
39
40 applyDocUpdate(auxDoc, snapshotUpdate);
41
42 const currentStateVector = Y.encodeStateVector(doc);
43
44 const snapshotStateVector = Y.encodeStateVector(auxDoc);
45 const forwardUpdate = Y.encodeStateAsUpdateV2(doc, snapshotStateVector);
46
47 const undoManager = new Y.UndoManager(
48 [auxDoc.getMap('page'), auxDoc.getMap('notes'), auxDoc.getMap('arrows')],
49 { trackedOrigins: new Set([null]) },
50 );
51
52 applyDocUpdate(auxDoc, forwardUpdate, null);
53
54 undoManager.undo();
55
56 const backwardUpdate = Y.encodeStateAsUpdateV2(auxDoc, currentStateVector);
57
58 applyDocUpdate(doc, backwardUpdate, null);
59}
60
61export function getPageTitle(
62 pageId: string,

Callers 1

restorePageSnapshotFunction · 0.90

Calls 3

createPageDocFunction · 0.85
applyDocUpdateFunction · 0.85
undoMethod · 0.80

Tested by

no test coverage detected