Autosave

Saving a document on every keystroke. Each save carries the whole document (a PUT), so only the latest version matters: concurrency: 'queue-latest' keeps the saves in order and skips the versions overtaken while a save is in flight. Two calls at most: the one in flight and the latest. A keystroke replaces the waiting call, whose mutate() rejects with 'Replaced', never sent. Source

Each keystroke saves the whole document. A save takes 1.5 s (an artificial delay): type a word quickly.

save.pendingInputs()
—
server
"draft"

Server

  1. Nothing yet.
// Each call carries the whole document, so a replaced call loses nothing.
protected readonly save = mutation<string, void>({
  concurrency: 'queue-latest',
  mutationFn: (content, abortSignal) => this.server.save({ docId: 'A', content }, abortSignal),
});
<input #doc type="text" (input)="save.mutate(doc.value)" />