UNPKG

@react-native-ohos/realm

Version:

Realm by MongoDB is an offline-first mobile database: an alternative to SQLite and key-value stores

52 lines 2.92 kB
import type { Realm } from "../Realm"; import { BaseSubscriptionSet } from "./BaseSubscriptionSet"; import { MutableSubscriptionSet } from "./MutableSubscriptionSet"; /** * 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 {@link SubscriptionSet.update} callback, * by calling methods on the corresponding {@link MutableSubscriptionSet} instance. */ export declare class SubscriptionSet extends BaseSubscriptionSet { /** * Wait for the server to acknowledge this set of subscriptions and return the * matching objects. * * If `state` is {@link SubscriptionSetState.Complete}, the promise will be resolved immediately. * * If `state` is {@link SubscriptionSetState.Error}, the promise will be rejected immediately. * @returns A promise which is resolved when synchronization is complete, or is * rejected if there is an error during synchronization. */ waitForSynchronization(): Promise<void>; /** * 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 {@link SubscriptionSet.waitForSynchronization} * to wait for the new data to be available. * @param callback A callback function which receives a {@link MutableSubscriptionSet} * instance as the first argument, which can be used to add or remove subscriptions * from the set, and the {@link Realm} associated with the SubscriptionSet as the * second argument (mainly useful when working with `initialSubscriptions` in * {@link FlexibleSyncConfiguration}). * @returns A promise which resolves when the SubscriptionSet is synchronized, or is rejected * if there was an error during synchronization (see {@link 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 */ update(callback: (mutableSubscriptions: MutableSubscriptionSet, realm: Realm) => void): Promise<void>; } //# sourceMappingURL=SubscriptionSet.d.ts.map