Constructs a LocalStorageDocStore.
You typically only need one LocalStorageDocStore per app, since it can subscribe multiple documents.
The prefix to use for all of this class's localStorage keys. Default: "@collabs/local-storage".
The prefix for all of this class's localStorage keys, set in the constructor.
Default: "@collabs/local-storage".
Deletes all documents under keyPrefix from localStorage.
Unsubscribes all documents.
Future subscribe calls will throw an error.
Deletes docID
from localStorage.
Returns all docID
s that have state stored under our keyPrefix.
Emits an event, which triggers all the registered event handlers.
Event handlers are called in the order they are added. Errors in
event handlers are captured and logged (with console.error
),
not propagated to the caller.
Name of the event to emit.
Event object to pass to the event handlers.
Registers an event handler that is triggered when the event happens.
Name of the event to listen on.
Callback that handles the event.
If true, the event handler is triggered at most once (the next time the event happens), then unsubscribed.
An "off" function that removes the event handler when called.
Registers an event handler that is triggered when the event happens.
An "off" function that removes the event handler when called.
Subscribes doc
to updates stored under docID
.
All existing updates under docID
will be loaded into doc
asynchronously, emitting a "Load" event when finished (including
if there are no existing updates).
Also, all new updates to doc
will be saved under docID
,
emitting a "Save" event whenever the localStorage state becomes up-to-date with doc
.
This includes both local operations and updates from other sources.
The document to subscribe.
An arbitrary string that identifies which stored state to use.
Unsubscribes doc
from its subscribed docID
(if any).
Further updates to doc
will not be saved.
Generated using TypeDoc
Stores updates to Collabs documents in localStorage.
To load existing state into a document (if any) and store future updates to that document, call subscribe. You will need to supply a
docID
that identifies which stored state to use.This class is designed to work seamlessly with other sources of updates, such as @collabs/ws-client. In particular, updates from those sources will be stored alongside local operations.
Warning: This class is subject to localStorage's small storage quotas. Also, some methods (including subscribe) loop over all localStorage keys, which may be slow.
See also: @collabs/indexeddb, which stores updates in IndexedDB instead of localStorage.