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): RecoveryStoreIndexedDB copies while the user edits, plus a synchronous localStorage copy when the page closes.
function createMemoryRecovery(): RecoveryStoreAn in-memory recovery store for tests.
| Name | Type | Default | Description |
|---|---|---|---|
| databaseName | string | — | The IndexedDB database name. |
| storeName | string | — | The object store name. |
The RecoveryStore interface
Implement this recovery store API to keep copies somewhere else:
| Name | Type | Default | Description |
|---|---|---|---|
| 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
| Name | Type | Default | Description |
|---|---|---|---|
| store* | RecoveryStore | — | Where copies are kept, such as createIndexedDbRecovery(). |
| interval | number | 2000 | Write 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.