Class Dictionary<T>

Instances of this class are returned when accessing object properties whose type is "Dictionary"

Dictionaries behave mostly like a JavaScript object i.e., as a key/value pair where the key is a string.

Type Parameters

  • T = unknown

Hierarchy (view full)

Indexable

[key: string]: T

@ts-expect-error We're exposing methods in the end-users namespace of keys

Methods

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

    Parameters

    • callback: DictionaryChangeCallback

      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.

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

    Returns boolean

    true if the dictionary can be safely accessed.

    Since

    0.14.0 @ts-expect-error We're exposing methods in the end-users namespace of keys

  • Removes elements from the dictionary, with the keys provided. This does not throw if the keys are already missing from the dictionary.

    Parameters

    • key: string | string[]

      The key to be removed.

    Returns this

    The dictionary

    Throws

    An AssertionError if not inside a write transaction.

    Since

    10.6.0 @ts-expect-error We're exposing methods in the end-users namespace of keys

  • Adds one or more elements with specified key and value to the dictionary or updates value if key exists.

    Parameters

    • elements: {
          [key: string]: T;
      }

      The object of element(s) to add.

      • [key: string]: T

    Returns this

    The dictionary.

    Throws

    an AssertionError If not inside a write transaction, input object contains symbol keys or if any value violates types constraints.

    Since

    10.6.0 @ts-expect-error We're exposing methods in the end-users namespace of keys

  • Adds an element with the specified key and value to the dictionary or updates value if key exists.

    Parameters

    • key: string

      The key of the element to add.

    • value: T

      The value of the element to add.

    Returns this

    The dictionary.

    Throws

    an AssertionError If not inside a write transaction, key is a symbol or if value violates type constraints.

    Since

    12.0.0

Generated using TypeDoc