Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yjs/y-indexeddb
IndexedDB database adapter for Yjs
https://github.com/yjs/y-indexeddb
offline-first yjs
Last synced: 4 days ago
JSON representation
IndexedDB database adapter for Yjs
- Host: GitHub
- URL: https://github.com/yjs/y-indexeddb
- Owner: yjs
- License: other
- Created: 2015-11-07T23:21:34.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2023-11-02T19:09:23.000Z (about 1 year ago)
- Last Synced: 2024-05-23T03:34:50.171Z (6 months ago)
- Topics: offline-first, yjs
- Language: JavaScript
- Homepage: https://docs.yjs.dev/ecosystem/database-provider/y-indexeddb
- Size: 272 KB
- Stars: 181
- Watchers: 9
- Forks: 30
- Open Issues: 10
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# y-indexeddb
> IndexedDB database provider for Yjs. [Documentation](https://docs.yjs.dev/ecosystem/database-provider/y-indexeddb)
Use the IndexedDB database adapter to store your shared data persistently in
the browser. The next time you join the session, your changes will still be
there.* Minimizes the amount of data exchanged between server and client
* Makes offline editing possible## Getting Started
You find the complete documentation published online: [API documentation](https://docs.yjs.dev/ecosystem/database-provider/y-indexeddb).
```sh
npm i --save y-indexeddb
``````js
const provider = new IndexeddbPersistence(docName, ydoc)provider.on('synced', () => {
console.log('content from the database is loaded')
})
```## API
-
Create a y-indexeddb persistence provider. Specify docName as a unique string
that identifies this document. In most cases, you want to use the same identifier
that is used as the room-name in the connection provider.
-
The "synced" event is fired when the connection to the database has been established
and all available content has been loaded. The event is also fired when no content
is available yet.
-
Set a custom property on the provider instance. You can use this to store relevant
meta-information for the persisted document. However, the content will not be
synced with other peers.
-
Retrieve a stored value.
-
Delete a stored value.
-
Close the connection to the database and stop syncing the document. This method is
automatically called when the Yjs document is destroyed (e.g. ydoc.destroy()).
-
Destroy this database and remove the stored document and all related meta-information
from the database.
provider = new IndexeddbPersistence(docName: string, ydoc: Y.Doc)
provider.on('synced', function(idbPersistence: IndexeddbPersistence))
provider.set(key: any, value: any): Promise<any>
provider.get(key: any): Promise>any<
provider.del(key: any): Promise>undefined<
provider.destroy(): Promise
provider.clearData(): Promise
## License
Yjs is licensed under the [MIT License](./LICENSE).