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

Constructors

Methods

  • Returns Generator<[string, T], any, unknown>

    An iterator with all entries in the dictionary.

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

    Parameters

    • callback: DictionaryChangeCallback<T>

      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 oldModifications report the indices in the collection before the change happened, while insertions and newModifications report the indices into the new version of the collection.

    Throws

    A TypeAssertionError if callback 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 Generator<[string, T], any, unknown>

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

    See

    Array.prototype.entries

    Since

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

  • 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

  • Returns Generator<string, any, unknown>

    An iterator with all values in the dictionary.

    See

    Array.prototype.keys

    Since

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

  • Remove all callback listeners from the collection instance.

    Returns void

  • 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

  • The plain object representation for JSON serialization. Use circular JSON serialization libraries such as @ungap/structured-clone and flatted to stringify Realm entities that have circular structures.

    Parameters

    • Optional _: string
    • Optional cache: unknown

    Returns DefaultObject

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

  • Returns Generator<T, any, unknown>

    An iterator with all values in the dictionary.

    See

    Array.prototype.values

    Since

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

Generated using TypeDoc