AFFiNE/packages/y-indexeddb/README.md

35 lines
672 B
Markdown
Raw Normal View History

# @toeverything/y-indexeddb
2023-06-17 08:58:48 +03:00
## Features
- persistence data in indexeddb
- sub-documents support
- fully TypeScript
## Usage
```ts
2023-05-04 02:16:22 +03:00
import { createIndexedDBProvider, downloadBinary } from '@toeverything/y-indexeddb';
import * as Y from 'yjs';
2023-06-17 08:58:48 +03:00
const yDoc = new Y.Doc({
// we use `guid` as unique key
guid: 'my-doc',
});
2023-05-04 02:16:22 +03:00
// sync yDoc with indexedDB
2023-06-17 08:58:48 +03:00
const provider = createIndexedDBProvider(yDoc);
provider.connect();
await provider.whenSynced.then(() => {
console.log('synced');
provider.disconnect();
});
2023-05-04 02:16:22 +03:00
// dowload binary data from indexedDB for once
2023-06-17 08:58:48 +03:00
downloadBinary(yDoc.guid).then(blob => {
2023-05-04 02:16:22 +03:00
if (blob !== false) {
Y.applyUpdate(yDoc, blob);
}
});
```