Extended Map class with additional features and change event emitter.

Type Parameters

Hierarchy

  • Map<T["id"], T>
    • MapEx

Constructors

  • Type Parameters

    Parameters

    • Optionalentries: null | readonly (readonly [T["id"], T])[]

    Returns MapEx<T>

  • Type Parameters

    Parameters

    • Optionaliterable: null | Iterable<readonly [T["id"], T]>

    Returns MapEx<T>

Properties

[toStringTag]: string
change: EventEmitter<MapEx<T>> = ...

Emits when a change happens in this map.

size: number

the number of elements in the Map.

[species]: MapConstructor

Accessors

Methods

  • Returns an iterable of entries in the map.

    Returns IterableIterator<[T["id"], T]>

  • Clears all items from the map and updates the list. Emits the change event.

    Returns void

  • Deletes an item from the map by its id, updates the list, and triggers the onChange callback.

    Parameters

    • id: PK

      The id of the item to be deleted.

    Returns boolean

    True if the item was successfully deleted, false otherwise.

  • Returns an iterable of key, value pairs for every entry in the map.

    Returns IterableIterator<[T["id"], T]>

  • Executes a provided function once per each key/value pair in the Map, in insertion order.

    Parameters

    • callbackfn: ((value: T, key: T["id"], map: Map<T["id"], T>) => void)
        • (value, key, map): void
        • Parameters

          • value: T
          • key: T["id"]
          • map: Map<T["id"], T>

          Returns void

    • OptionalthisArg: any

    Returns void

  • Returns a specified element from the Map object. 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: T["id"]

    Returns undefined | T

    Returns the element associated with the specified key. If no element is associated with the specified key, undefined is returned.

  • Parameters

    • key: T["id"]

    Returns boolean

    boolean indicating whether an element with the specified key exists or not.

  • Returns an iterable of keys in the map

    Returns IterableIterator<T["id"]>

  • Sets or updates an item in the map, updates the list, and triggers the onChange callback.

    Parameters

    • id: PK

      The id for the item.

    • item: T

      The item to be added or updated.

    Returns this

    The MapEx instance for method chaining.

  • Returns an iterable of values in the map

    Returns IterableIterator<T>