Files
AFFiNE-Mirror/packages/y-indexeddb/README.md
2023-05-03 18:16:22 -05:00

25 lines
539 B
Markdown

# @toeverything/y-indexeddb
## Usage
```ts
import { createIndexedDBProvider, downloadBinary } from '@toeverything/y-indexeddb';
import * as Y from 'yjs';
const yDoc = new Y.Doc();
// sync yDoc with indexedDB
const provider = createIndexedDBProvider('docName', yDoc);
provider.connect();
await provider.whenSynced.then(() => {
console.log('synced');
provider.disconnect();
});
// dowload binary data from indexedDB for once
downloadBinary('docName').then(blob => {
if (blob !== false) {
Y.applyUpdate(yDoc, blob);
}
});
```