[Announcement] y-localforage

I’ve just launched y-localforage, a Yjs storage provider which uses localForage for persistence. LocalForage is a simple storage library for JavaScript which wraps IndexedDB, WebSQL and other storage technologies in a common, localStorage -like API. In the end, this means: if there is a localForage “driver”, you can use y-localForage to instantiate a Yjs provider for it

y-localforage reflects my current knowledge about Yjs.

Great care has been taken to keep any data safe and allow programmers to wait for synchronization to finish. y-localforage even handles “subdocs” automatically - but with an important restriction:

do not use the “copy” feature for Y.Docs, i.e., do not create a Y.Doc instance with the same GUID as another one - Y.Doc copies do not “synchronize” as described in the docs anyway.

1 Like

I was wondering what advantages this library has over yjs/y-indexeddb: IndexedDB database adapter for Yjs (github.com) ??

Well, apart from the possibility to use an arbitrary localforage driver - let me cite the readme:

"In addition to other database providers y-localforage

  • contains an isSynced property which reflects the main document’s own current synchronization status,
  • and an isFullySynced property which includes the synchronization state of any subdocs,
  • emits additional events (sync-started, sync-continued, sync-finished and sync-aborted) which inform about synchronization progress for the main document,
  • and subdoc-synced which informs about a given subdoc being successfully synchronized,
  • sends a load event to the main doc and any subdoc as soon as that Y.Doc has been fully loaded from persistence,
  • automatically persists any subdocs as well, and
  • includes rudimentary error handling which breaks down the provider upon failure (which means that you have to re-incarnate the provider after the cause for this failure has been removed).

y-localforage always tries to keep your data safe and not to overwrite or even delete previously written updates. Even a failure normally only means that the last update could not be written but all the previous ones are still safe."

This clearly describes the differences…