Class SubscriptionSet

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)

Properties

Accessors

Methods

  • 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

Generated using TypeDoc