CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
sagemathinc

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/sync/editor/string/test/ephemeral-syncstring.ts
Views: 791
1
/*
2
This is useful not just for testing, but also for implementing undo/redo for
3
editing a text document when there is no actual file or project involved.
4
*/
5
6
import { Client } from "./client-test";
7
import { SyncString } from "../sync";
8
import { a_txt } from "./data";
9
import { once } from "@cocalc/util/async-utils";
10
11
export default async function ephemeralSyncstring() {
12
const { client_id, project_id, path, init_queries } = a_txt();
13
const client = new Client(init_queries, client_id);
14
const syncstring = new SyncString({
15
project_id,
16
path,
17
client,
18
ephemeral: true,
19
});
20
// replace save to disk, since otherwise unless string is empty,
21
// this will hang forever... and it is called on close.
22
// @ts-ignore
23
syncstring.save_to_disk = async () => Promise<void>;
24
await once(syncstring, "ready");
25
return syncstring;
26
}
27
28