Class Collection<KeyType, ValueType, EntryType, T, ChangeCallbackType>Abstract

Abstract base class containing methods shared by Realm List, Dictionary and Results.

A Collection always reflect the current state of the Realm. The one exception to this is when using or for...of enumeration, which will always enumerate over the objects which matched the query when the enumeration is begun, even if some of them are deleted or modified to be excluded by the filter during the enumeration.



Type Parameters

Hierarchy (view full)



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


    • callback: ChangeCallbackType

      A function to be called when changes occur.

    • Optional keyPaths: string | string[]

      Indicates a lower bound on the changes relevant for the listener. This is a lower bound, since if multiple listeners are added (each with their own keyPaths) the union of these key-paths will determine the changes that are considered relevant for all listeners registered on the collection. In other words: A listener might fire more than the key-paths specify, if other listeners with different key-paths are present.

    Returns void


    deletions and oldModificationsreport the indices in the collection before the change happened, whileinsertionsandnewModificationsreport the indices into the new version of the collection. @throws A {@link TypeAssertionError} ifcallback is not a function. @example wines.addListener((collection, changes) => { // collection === wines console.log(${changes.insertions.length} insertions); console.log(${changes.oldModifications.length} oldModifications); console.log(${changes.newModifications.length} newModifications); console.log(${changes.deletions.length} deletions); console.log(new size of collection: ${collection.length}); }); @example wines.addListener((collection, changes) => { console.log("A wine's brand might have changed"); }, ["brand"]); @note Adding the listener is an asynchronous operation, so the callback is invoked the first time to notify the caller when the listener has been added. Thus, when the callback is invoked the first time it will contain empty arrays for each property in the changes` object.

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

    Returns boolean

    true if the collection can be safely accessed.



Generated using TypeDoc