Skip to main content

DataMap<K, V>

A class that extends the built-in Map class and provides additional events for item set, update, delete, and clear operations.

Extends

  • Map<K, V>

Type parameters

Type parameterDescription
KThe type of keys in the map.
VThe type of values in the map.

Constructors

new DataMap()

new DataMap<K, V>(iterable?): DataMap<K, V>

Constructs a new DataMap instance.

Parameters

ParameterTypeDescription
iterable?null | Iterable<readonly [K, V]>An iterable object containing key-value pairs to populate the map.

Returns

DataMap<K, V>

Overrides

Map<K, V>.constructor

Properties

guard()

guard: (key, value) => boolean

A function that acts as a guard for adding items to the set. It determines whether a given value should be allowed to be added to the set.

Parameters

ParameterTypeDescription
keyKThe key of the entry to be checked against the guard.
valueVThe value of the entry to be checked against the guard.

Returns

boolean


onCleared

readonly onCleared: Event<unknown>

An event triggered when the map is cleared.


onItemDeleted

readonly onItemDeleted: Event<K>

An event triggered when an item is deleted from the map.


onItemSet

readonly onItemSet: Event<object>

An event triggered when a new item is set in the map.

Type declaration

key

key: K

value

value: V


onItemUpdated

readonly onItemUpdated: Event<object>

An event triggered when an existing item in the map is updated.

Type declaration

key

key: K

value

value: V

Methods

clear()

clear(): void

Clears the map and triggers the onCleared event.

Returns

void

Overrides

Map.clear


delete()

delete(key): boolean

Deletes the specified key from the map and triggers the onItemDeleted event if the key was found.

Parameters

ParameterTypeDescription
keyKThe key of the item to delete.

Returns

boolean

True if the key was found and deleted; otherwise, false.

Overrides

Map.delete


dispose()

dispose(): void

Clears the map and resets the events.

Returns

void


set()

set(key, value): DataMap<K, V>

Sets the value for the specified key in the map. If the item is new, then onItemSet is triggered. If the item is already in the map, then onItemUpdated is triggered.

Parameters

ParameterTypeDescription
keyKThe key of the item to set.
valueVThe value of the item to set.

Returns

DataMap<K, V>

The DataMap instance.

Overrides

Map.set