Provides access to sync related functionality of Ditto.

Access this object via Ditto.sync on any Ditto instance.

Properties

ditto: Ditto

The Ditto instance managed by this sync object.

subscriptions: readonly SyncSubscription<any>[]

All currently active sync subscriptions.

Note: Manage sync subscriptions using registerSubscription() to register a new sync subscription and SyncSubscription.cancel() to remove an existing sync subscription.

Accessors

Methods

  • Installs and returns a sync subscription for a query, configuring Ditto to receive updates from other peers for documents matching that query. The passed in query must be a SELECT query, otherwise an error is thrown.

    Type Parameters

    Parameters

    • query: string

      a string containing a valid query expressed in DQL.

    • OptionalqueryArguments: T

      an object containing the arguments for the query. Example: {mileage: 123} for a query with :mileage placeholder.

    Returns SyncSubscription<T>

    An active SyncSubscription for the passed in query and arguments. It will remain active until it is cancelled or the Ditto instance managing the sync subscription has been closed.

    DittoError query/invalid: if query argument is not a string or not valid DQL.

    DittoError query/arguments-invalid: if queryArguments argument is invalid (e.g. contains unsupported types).

    DittoError query/unsupported: if the query is not a SELECT query.

    DittoError may throw other errors.

  • Starts the network transports. Ditto will connect to other devices.

    By default Ditto will enable all peer-to-peer transport types. On Node, this means BluetoothLE, WiFi/LAN, and AWDL. On the Web, only connecting via Websockets is supported. The default network configuration can be modified with updateTransportConfig() or replaced with setTransportConfig().

    Performance of initial sync when bootstrapping new peers can be improved by calling disableSyncWithV3() before start(). Only call that method when all peers in the mesh are known to be running Ditto v4 or higher.

    Ditto will prevent the process from exiting until sync is stopped (not relevant when running in the browser).

    NOTE: the BluetoothLE transport on Linux is experimental, this method panics if no BluetoothLE hardware is available. Therefore, contrary to the above, the BluetoothLE transport is temporarily disabled by default on Linux.

    Returns void

  • Stops all network transports.

    You may continue to use the Ditto store locally but no data will sync to or from other devices.

    Returns void