AFFiNE/packages/common/y-indexeddb
2024-03-14 13:05:52 +08:00
..
src feat: bump blocksuite (#6078) 2024-03-13 17:04:21 +08:00
.gitignore refactor(infra): directory structure (#4615) 2023-10-18 15:30:08 +00:00
package.json feat: bump blocksuite (#6112) 2024-03-14 13:05:52 +08:00
project.json refactor(infra): directory structure (#4615) 2023-10-18 15:30:08 +00:00
README.md chore: change default branch to canary (#4948) 2023-11-15 07:46:50 +00:00
tsconfig.json refactor(infra): directory structure (#4615) 2023-10-18 15:30:08 +00:00
tsconfig.node.json refactor(infra): directory structure (#4615) 2023-10-18 15:30:08 +00:00
vite.config.ts style: apply prefer-node-protocol lint rule (#5627) 2024-01-19 03:47:08 +00:00

@toeverything/y-indexeddb

Features

  • persistence data in indexeddb
  • sub-documents support
  • fully TypeScript

Usage

import { createIndexedDBProvider, downloadBinary } from '@toeverything/y-indexeddb';
import * as Y from 'yjs';

const yDoc = new Y.Doc({
  // we use `guid` as unique key
  guid: 'my-doc',
});

// sync yDoc with indexedDB
const provider = createIndexedDBProvider(yDoc);
provider.connect();
await provider.whenSynced.then(() => {
  console.log('synced');
  provider.disconnect();
});

// dowload binary data from indexedDB for once
downloadBinary(yDoc.guid).then(blob => {
  if (blob !== false) {
    Y.applyUpdate(yDoc, blob);
  }
});

LICENSE

MIT