Fabric.js Document Engine

Search documentation

Find a page or section

中文

Recovery API

View as Markdown

Everything in fabricjs-document-engine/recovery.

The recovery store API decides where copies of unsaved work are kept. Pass a store to the recovery option of createDocumentEngine. How recovery behaves is explained in the recovery guide.

Built-in stores

function createIndexedDbRecovery(options?: IndexedDbRecoveryOptions): RecoveryStore

IndexedDB copies while the user edits, plus a synchronous localStorage copy when the page closes.

function createMemoryRecovery(): RecoveryStore

An in-memory recovery store for tests.

NameTypeDefaultDescription
databaseNamestring—The IndexedDB database name.
storeNamestring—The object store name.

The RecoveryStore interface

Implement this recovery store API to keep copies somewhere else:

NameTypeDefaultDescription
get*(key: string): Promise<unknown>—Reads a copy.
set*(key: string, value: unknown): Promise<void>—Writes a copy.
setNow(key: string, value: unknown): void—Writes a copy synchronously, for the moment the page closes.
delete*(key: string): Promise<void>—Deletes a copy.
keys*(): Promise<string[]>—Lists the stored keys.

setNow is optional. Browsers do not wait for async writes while a page closes, so the engine calls setNow at that moment if it exists. createIndexedDbRecovery uses localStorage for it.

The option

NameTypeDefaultDescription
store*RecoveryStore—Where copies are kept, such as createIndexedDbRecovery().
intervalnumber2000Write a copy at most once every this many milliseconds while there are unsaved changes.

The engine methods that use the recovery store API, such as getRecoverableDocuments and restoreRecovery, are listed on DocumentEngine.

Recovery store API | Fabric.js Document Engine