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

  • KeyType = unknown

  • ValueType = unknown

  • EntryType = [KeyType, ValueType]

  • T = ValueType

  • ChangeCallbackType = unknown




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


    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}); }); @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.


    • callback: ChangeCallbackType

      A function to be called when changes occur.

    Returns void

  • 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.

  • Remove the listener callback from the collection instance.


    a TypeAssertionError If callback is not a function.


    • callback: ChangeCallbackType

      Callback function that was previously added as a listener through the addListener method.

    Returns void

Generated using TypeDoc