Fabric.js Document Engine

搜索文档

查找页面或章节

EN

恢复 API

查看 Markdown

fabricjs-document-engine/recovery 里的全部内容。

恢复存储 API 决定未保存内容的副本放在哪里。把一个存储传给 createDocumentEngine 的 recovery 配置项即可。恢复的具体行为见恢复指南。

内置存储

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.

RecoveryStore 接口

实现这个恢复存储 API,就能把副本放到别的地方:

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 是可选的。页面关闭时浏览器不会等待异步写入,所以如果有 setNow,引擎会在那一刻调用它。createIndexedDbRecovery 用 localStorage 来实现它。

配置项

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.

使用恢复存储 API 的引擎方法,比如 getRecoverableDocuments 和 restoreRecovery,列在 DocumentEngine 页面。

恢复存储 API | Fabric.js Document Engine