GenericMap

An abstract collection that implements many generic methods, reusable by most maps.

Methods

has(key)

Returns whether an entry with the given key exists in a Map.

get(key|index, default?)

Gets the value for a key in a map.

set(key, value)

Sets the value for a given key.

add(value, key)

Adds a value for a given key to a map.

delete(key)

Deletes the value for a given key. Returns whether the key was found and successfully deleted.

keys()

Returns an array of the keys of this map.

values()

Returns an array of the values of this map.

entries()

Returns an array of all [key, value] entries for this map.

addEach(values|map)

Copies values or entries from another collection into this collection, and then returns this.

clear()

Deletes all of the values in the collection.

reduce(callback, basis)

Aggregates every value in this collection with the result collected up to that index.

reduceRight(callback, basis)

Aggregates every value in this collection, from right to left.

toJSON()

Used by JSON.stringify to create a JSON representation of the collection.

equals(value, equals?)

Returns whether this collection is equivalent to the given collection.

addMapChangeListener(listener, token?, beforeChange?)

Adds a listener for when the value for a key changes, or when entries are added or removed.

addBeforeMapChangeListener(listener, token?)

Adds a listener for before map entries are created, deleted, or updated.

removeMapChangeListener(listener, token?, beforeChange?)

Unregisters a map change listener provided by addMapChangeListener.

removeBeforeMapChangeListener(listener, token?)

Unregisters a map change listener provided by addBeforeMapChangeListener or addMapChangeListener with the beforeChange flag.

dispatchMapChange(key, value, beforeChange?)

Informs map change listeners that an entry was created, deleted, or updated.

dispatchBeforeMapChange(key, value)

Informs map change listeners that an entry will be created, deleted, or updated.

Usage

require("collections/shim-object");
var GenericMap = require("collections/generic-map");
Object.addEach(MyMap.prototype, GenericMap.prototype);
  • GenericMap
Source code