Realm.Sync.NamedSubscription

A managed Realm object representing a subscription. Subscriptions are used by Query-based Realms to define which data should be available on the device.

Extends

createdAt

Returns the date for when this subscription was first created.

error
readonly

Returns the error message if the server encountered an error when evaluating the query covered by this subscription. undefined is returned if state != Realm.Sync.SubscriptionState.Error.

Type:
string
expiresAt

Returns the point in time from which Realm can safely delete this subscription. This will happen automatically.

Realm will attempt to cleanup expired subscriptions when the app is started or whenever any subscription is modified, there is no guarantee it will happen immediately after it expires.

state

Gets the current state of the subscription. Can be either:

  • Realm.Sync.SubscriptionState.Error: An error occurred while creating or processing the query-based sync subscription.
  • Realm.Sync.SubscriptionState.Creating: The subscription is being created.
  • Realm.Sync.SubscriptionState.Pending: The subscription was created, but has not yet been processed by the sync server.
  • Realm.Sync.SubscriptionState.Complete: The subscription has been processed by the sync server and data is being synced to the device.
  • Realm.Sync.SubscriptionState.Invalidated: The subscription has been removed.
Type:
number
updatedAt

Returns when this subscription was last used or updated.

"Used" in this context means that someone resubscribed to the subscription.

"Updated" means that someone updated the Subscription.query or some other field part of this class.

This field is NOT updated whenever the results of the query changes.

This field plus Subscription.timeToLive defines Subscription.expiresAt.

addListener(callback)

Add a listener callback which will be called when a live object instance changes.

Parameters:
  • callback
    • Type: function
    • A function to be called when changes occur. The callback function is called with two arguments:

      • obj: the object that changed,
      • changes: a dictionary with keys deleted, and changedProperties. deleted is true if the object has been deleted. changesProperties is an array of properties that have changed their value.
Throws:
  • Error
    • If callback is not a function.

Example:
wine.addListener((obj, changes) => {
 // obj === wine
 console.log(`object is deleted: ${changes.deleted}`);
 console.log(`${changes.changedProperties.length} properties have been changed:`);
 changes.changedProperties.forEach(prop => {
     console.log(` ${prop}`);
  });
})
isValid()boolean

Checks if this object has not been deleted and is part of a valid Realm.

Returns: boolean indicating if the object can be safely accessed.
linkingObjects(objectType, property)Realm.Results

Returns all the objects that link to this object in the specified relationship.

Parameters:
  • objectType
    • Type: string
    • The type of the objects that link to this object's type.

  • property
    • Type: string
    • The name of the property that references objects of this object's type.

Throws:
  • Error
    • If the relationship is not valid.

Returns: Realm.Results the objects that link to this object.
linkingObjectsCount()number

Returns the total count of incoming links to this object

Returns: number number of links to this object.
objectSchema()ObjectSchema

Returns the schema for the type this object belongs to.

Returns: ObjectSchema the schema that describes this object.
removeAllListeners()

Remove all listeners.

removeListener(callback)

Remove the listener callback

Parameters:
  • callback
    • Type: function
    • A function previously added as listener