Documentation
    Preparing search index...

    A container that stores and retrieves values by key.

    The Serializable equivalent of a vanilla JavaScript Map.

    Type Parameters

    Implements

    • SerializableObject
    Index

    Accessors

    Methods

    • Creates an iterator over the Dictionary's key-value pairs.

      Enables the Dictionary to be iterable directly.

      Returns IteratorObject<[string, T]>

      An iterator of the Dictionary's key-value pairs.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      for (const [key, value] of dictionary) {
      console.log(key, value);
      }
      // Console output:
      // hello 1
      // world 2
    • Removes all entries from this Dictionary.

      Returns void

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      dictionary.clear();
      // `dictionary` is now empty.
    • Removes the entry with key from the Dictionary if it exists.

      Parameters

      • key: string

        The key of the entry to remove from the Dictionary.

      Returns boolean

      true if the Dictionary contained an entry with key key, otherwise false.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      console.log(dictionary.delete('world'));
      console.log(dictionary.delete('fizz'));
      // `dictionary` now contains these entries:
      // hello: 1
      //
      // Console output:
      // true
      // false
    • Creates an iterator over the Dictionary's key-value pairs.

      Returns IteratorObject<[string, T]>

      An iterator of the Dictionary's key-value pairs.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      for (const [key, value] of dictionary.entries()) {
      console.log(key, value);
      }
      // Console output:
      // hello 1
      // world 2
    • Gets the value of the entry whose key is key.

      Parameters

      • key: string

        The key of the entry whose value we're retrieving.

      Returns T | undefined

      The value of the entry with key key or undefined if no entry has key key.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      console.log(dictionary.get('world'));
      console.log(dictionary.get('fizz'));
      // Console output:
      // 2
      // undefined
    • Gets or inserts the value of the entry whose key is key. If no entry with key exists, then an entry is inserted with key and value value first before returning its value.

      Parameters

      • key: string

        The key of the entry whose value we're returning.

      • value: T

        The value to insert in the case that an entry with key key doesn't already exist.

      Returns T

      The value of the existing or newly inserted entry with key key.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      console.log(dictionary.getOrInsert('world', 3));
      console.log(dictionary.getOrInsert('fizz', 4));
      // Console output:
      // 2
      // 4
    • Gets or inserts the value of the entry whose key is key. If no entry with key exists, then an entry is inserted with key key and a value computed by callback before returning its value.

      Parameters

      • key: string

        The key of the entry whose value we're returning.

      • callback: ((key: string) => T) | Method<(key: string) => T>

        Computes the value of the entry in the case that no entry with key key exists. key is passed as an argument.

      Returns T

      The value of the existing or newly inserted entry with key key.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      console.log(dictionary.getOrInsertComputed('world', () => 3));
      console.log(dictionary.getOrInsertComputed('fizz', (key: string) => key.length));
      // Console output:
      // 2
      // 4
    • Returns whether the Dictionary contains an entry with key key.

      Parameters

      • key: string

        The key of the entry to look up if it exists.

      Returns boolean

      true if the Dictionary contains an entry with key key, otherwise false.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      console.log(dictionary.has('world'));
      console.log(dictionary.has('fizz'));
      // Console output:
      // true
      // false
    • Creates an iterator over the Dictionary's keys.

      Returns IteratorObject<string>

      An iterator of the Dictionary's keys.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      for (const key of dictionary.keys()) {
      console.log(key);
      }
      // Console output:
      // hello
      // world
    • Inserts a new entry whose key is key and value is value.

      Parameters

      • key: string

        The key of the new entry.

      • value: T

        The value of the new entry.

      Returns Dictionary<T>

      This Dictionary.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      dictionary.set("fizz", 4).set("buzz", 5);
      // `dictionary` now contains these entries:
      // hello: 1
      // world: 2
      // fizz: 4
      // buzz: 5
    • Creates an iterator over the Dictionary's values.

      Returns IteratorObject<T>

      An iterator of the Dictionary's values.

      const { containers } = createFutureMachine(futureDatabase);
      const dictionary = containers.dictionary.create<number>([
      ['hello', 1],
      ['world', 2],
      ]);

      for (const value of dictionary.values()) {
      console.log(value);
      }
      // Console output:
      // 1
      // 2