Represents the set of all active flexible sync subscriptions for a Realm instance.

The server will continuously evaluate the queries that the instance is subscribed to and will send data that matches them, as well as remove data that no longer does.

The set of subscriptions can only be modified inside a SubscriptionSet.update callback, by calling methods on the corresponding MutableSubscriptionSet instance.

Hierarchy (view full)

Constructors

Accessors

  • get error(): null | string
  • If state is SubscriptionSetState.Error, this will be a string representing why the SubscriptionSet is in an error state. It will be null if there is no error.

    Returns null | string

    A string representing the error, or null if there is no error.

  • get isEmpty(): boolean
  • Whether there are no subscriptions in the set.

    Returns boolean

    true if there are no subscriptions in the set, false otherwise.

  • get length(): number
  • Returns number

    The number of subscriptions in the set.

  • get state(): SubscriptionSetState
  • Returns SubscriptionSetState

    The state of the SubscriptionSet.

  • get version(): number
  • The version of the SubscriptionSet. This is incremented every time a SubscriptionSet.update is applied.

    Returns number

    The version of the SubscriptionSet.

Methods

  • Makes the subscription set iterable.

    Returns IterableIterator<Subscription>

    Iterable of each value in the set.

    Example

    for (const subscription of subscriptions) {
    // ...
    }
  • Find a subscription by name.

    Parameters

    • name: string

      The name to search for.

    Returns null | Subscription

    The named subscription, or null if the subscription is not found.

  • Find a subscription by query. Will match both named and unnamed subscriptions.

    Type Parameters

    • Subscription

    Parameters

    Returns null | Subscription

    The subscription with the specified query, or null if the subscription is not found.

  • Call this to make changes to this SubscriptionSet from inside the callback, such as adding or removing subscriptions from the set.

    The MutableSubscriptionSet argument can only be used from the callback and must not be used after it returns.

    All changes done by the callback will be batched and sent to the server. You can either await the call to update, or call SubscriptionSet.waitForSynchronization to wait for the new data to be available.

    Parameters

    • callback: ((mutableSubscriptions, realm) => void)

      A callback function which receives a MutableSubscriptionSet instance as the first argument, which can be used to add or remove subscriptions from the set, and the Realm associated with the SubscriptionSet as the second argument (mainly useful when working with initialSubscriptions in FlexibleSyncConfiguration).

    Returns Promise<void>

    A promise which resolves when the SubscriptionSet is synchronized, or is rejected if there was an error during synchronization (see SubscriptionSet.waitForSynchronization)

    Example

    await realm.subscriptions.update(mutableSubscriptions => {
    mutableSubscriptions.add(realm.objects("Cat").filtered("age > 10"));
    mutableSubscriptions.add(realm.objects("Dog").filtered("age > 20"), { name: "oldDogs" });
    mutableSubscriptions.removeByName("youngDogs");
    });
    // `realm` will now return the expected results based on the updated subscriptions
  • Wait for the server to acknowledge this set of subscriptions and return the matching objects.

    If state is SubscriptionSetState.Complete, the promise will be resolved immediately.

    If state is SubscriptionSetState.Error, the promise will be rejected immediately.

    Returns Promise<void>

    A promise which is resolved when synchronization is complete, or is rejected if there is an error during synchronization.

Generated using TypeDoc