Skip to content

autoSave()

Wire up auto-save for any content store: debounce → checkpoint → status.

Requires a dirty store to track whether the buffer has unsaved changes. After each successful checkpoint persist, optionally calls markClean().

Signature

ts
function autoSave<T>(
	content: Store<T>,
	dirty: Store<boolean>,
	adapter: CheckpointAdapter,
	opts?: AutoSaveOptions,
): AutoSaveResult<T>

Parameters

ParameterTypeDescription
contentStore&lt;T&gt;
dirtyStore&lt;boolean&gt;
adapterCheckpointAdapter
optsAutoSaveOptions

Basic Usage

ts
const editor = textEditor({ initial: "" });
const save = autoSave(editor.buffer.content, editor.buffer.dirty, memoryAdapter(), {
    debounceMs: 1000,
    checkpointId: "my-editor",
    markClean: () => editor.buffer.markClean(),
  });
save.status.get(); // "saved" | "saving" | "unsaved"
save.dispose();

Released under the MIT License.