Class DynamicMap<K, V>

The DynamicMap implements a Map that dynamically creates values for requested keys. If a call to get is made for a key that does not exist yet, the fnCreateValue callback will be invoked to create the value dynamically.

This map is most useful to create systems that dynamically cache objects that are lazily created.

Type Parameters

  • K
  • V

Constructors

  • Type Parameters

    • K
    • V

    Parameters

    • fnCreateValue: ((key: K) => V)
        • (key): V
        • Parameters

          • key: K

          Returns V

    Returns DynamicMap<K, V>

Properties

_internal: Map<K, V>
[toStringTag]: string
fnCreateValue: ((key: K) => V)

Accessors

  • get length(): number
  • Returns number

  • get size(): number
  • Returns number

Methods

  • Returns IterableIterator<[K, V], any, any>

  • Returns void

  • Parameters

    • key: K

    Returns boolean

  • Returns IterableIterator<[K, V], any, any>

  • Parameters

    • callbackfn: ((value: V, key: K, map: Map<K, V>) => void)
        • (value, key, map): void
        • Parameters

          • value: V
          • key: K
          • map: Map<K, V>

          Returns void

    • OptionalthisArg: any

    Returns void

  • Returns a specified element from the Map object.

    Parameters

    • key: K

    Returns V

    Returns the element associated with the specified key. If no element is associated with the specified key, the value is created.

    If the key does not exist in the dynamic map, the fnCreateValue callback will be invoked to create the key. The resulting value is then internally retained by the dynamic map.

    If the value that is associated to the provided key is an object, then you will get a reference to that object and any change made to that object will effectively modify it inside the Map.

  • Parameters

    • key: K

    Returns boolean

  • Returns IterableIterator<K, any, any>

  • Parameters

    • key: K
    • value: V

    Returns this

  • Returns IterableIterator<V, any, any>