MCPcopy Create free account
hub / github.com/heygen-com/hyperframes / undo

Function undo

packages/studio/src/hooks/usePersistentEditHistory.ts:173–203  ·  view source on GitHub ↗
(callbacks: ApplyCallbacks)

Source from the content-addressed store, hash-verified

171 });
172 },
173 async undo(callbacks: ApplyCallbacks): Promise<ApplyResult> {
174 return mutate<ApplyResult>(async (currentState) => {
175 const entry = currentState.undo[currentState.undo.length - 1];
176 if (!entry) {
177 return {
178 state: currentState,
179 result: { ok: false, reason: "empty" },
180 };
181 }
182 const { currentFiles, currentHashes } = await readCurrentFileHashes(
183 Object.keys(entry.files),
184 callbacks.readFile,
185 );
186 const result = undoEditHistory(currentState, currentHashes, now());
187 if (!result.ok) {
188 return {
189 state: currentState,
190 result: { ok: false, reason: result.reason },
191 };
192 }
193 await writeFilesWithRollback({
194 files: result.filesToWrite,
195 rollbackFiles: currentFiles,
196 writeFile: callbacks.writeFile,
197 });
198 return {
199 state: result.state,
200 result: { ok: true, label: result.entry.label, paths: Object.keys(result.entry.files) },
201 };
202 });
203 },
204 async redo(callbacks: ApplyCallbacks): Promise<ApplyResult> {
205 return mutate<ApplyResult>(async (currentState) => {
206 const entry = currentState.redo[currentState.redo.length - 1];

Callers

nothing calls this directly

Calls 4

undoEditHistoryFunction · 0.90
mutateFunction · 0.85
readCurrentFileHashesFunction · 0.85
writeFilesWithRollbackFunction · 0.85

Tested by

no test coverage detected