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 for...in 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.

Since

0.11.0

Type Parameters

Hierarchy (view full)

Implements

  • Iterable<T>

Constructors

Methods

  • This is the same method as the Collection.values method. Its presence makes collections iterable, thus able to be used with ES6 for-of loops, ... spread operators, and more.

    Returns Iterator<T, any, undefined>

    An iterable of each value in the collection.

    See

    Symbol.iterator and the iterable protocol

    Example

    for (let object of collection) {
    // do something with each object
    }

    Since

    0.11.0

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

    Parameters

    • 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

    Note

    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.

  • Returns Iterable<EntryType>

    An iterator with all key/value pairs in the collection.

    See

    Array.prototype.keys

    Since

    0.11.0

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

    Since

    0.14.0

  • Returns Iterable<KeyType>

    An iterator with all keys in the collection.

    See

    Array.prototype.keys

    Since

    0.11.0

  • Remove all callback listeners from the collection instance.

    Returns void

  • Remove the listener callback from the collection instance.

    Parameters

    Returns void

    Throws

    a TypeAssertionError If callback is not a function.

  • Returns Iterable<ValueType>

    An iterator with all values in the collection.

    See

    Array.prototype.keys

    Since

    0.11.0

Generated using TypeDoc