Options
All
  • Public
  • Public/Protected
  • All
Menu

Class IndexedDBDocStore

Stores updates to Collabs documents in IndexeddDB.

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.

  • Exception: Updates from other tabs via @collabs/tab-sync are not saved, since the source tab should save them.

See also: @collabs/local-storage, which stores updates in localStorage instead of IndexedDB.

Hierarchy

Index

Constructors

  • Constructs an IndexedDBDocStore.

    You typically only need one IndexedDBDocStore per app, since it can subscribe multiple documents.

    Parameters

    • options: { dbName?: string } = {}
      • Optional dbName?: string

        The name of the database to use. Default: "@collabs/indexeddb".

    Returns IndexedDBDocStore

Properties

dbName: string

The name of this class's IndexedDB database, set in the constructor.

Default: "@collabs/indexeddb".

Methods

  • clear(): Promise<void>
  • close(): void
  • delete(docID: string): Promise<void>
  • docIDs(): Promise<Set<string>>
  • 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.

    Type Parameters

    Parameters

    Returns void

  • Registers an event handler that is triggered when the event happens.

    Type Parameters

    Parameters

    Returns (() => void)

    An "off" function that removes the event handler when called.

      • (): void
      • Registers an event handler that is triggered when the event happens.

        Returns void

        An "off" function that removes the event handler when called.

  • subscribe(doc: AbstractDoc | CRuntime, docID: string): void
  • 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 IndexedDB state becomes up-to-date with doc. This includes both local operations and updates from other sources.

    throws

    If doc is already subscribed to a docID.

    throws

    If another doc is subscribed to docID.

    Parameters

    • doc: AbstractDoc | CRuntime

      The document to subscribe.

    • docID: string

      An arbitrary string that identifies which stored state to use.

    Returns void

  • unsubscribe(doc: AbstractDoc | CRuntime): void

Generated using TypeDoc