Map
MMO.core ยท 1 symbol ยท generated 30 Sep 2026
Map
Map.js:64Extension of a javascript Map with events.
- Namespace
MMO.core- Extends
mixinEventEmitter(Map)
Index
| length accessor | Alias of size, so an array Map reads like a javascript array. | |
| constructor(args) | ||
| From(obj, schema, _hash) static | Build a Map from any plain value, recursively. | |
| toObject(deep, _hash) | Convert this object to primitive object/array | |
| toArray(deep, _hash) | Force conversion of this map to an array (if toObject returned an array, only its values are returned) | |
| toJSON() | Convert this object to primitive object/array | |
| isEqual(obj, strictOrder) | Test if content of this map is strictly equal to the content of an object | |
| isSimilar(obj) | Test whether this map CONTAINS the content of an object (a one-way comparison). | |
| isEmpty() | ||
| getText(key) | Render a value as plain text, through the key's schema when there is one. | |
| getHTML(key) | Render a value as html, through the key's schema when there is one. | |
| keyOf(value) | Find the key holding a value (strict equality, first match). | |
| indexOf(value) | Find the position of a value (strict equality, first match). | |
| indexOfKey(key) | Find the position of a key. | |
| keyAtIndex(index) | Get the key sitting at a given index. | |
| ketAtIndex(index) deprecated | ||
| pathOf(value, _hash) | Get the path of a value | |
| connectChild(map, key) | ||
| disconnectChild(map, key) | Detach a child map: emit MMO.core.MAP_DISCONNECT, then forget the parent link. | |
| loopEventsByScopeRecursive(scope, _hash) generator | Yield all events concerning a given scope recursively | |
| loopEmit() generator | Yield the entries of the global run queue that concern this map, i.e. | |
| emitChange(_hash) | Emit change asynchronously | |
| emitValueChange(key, type, _hash) | Emit change of a value at a given key, asynchronously | |
| emitIndexChange(key, oldIndex) | Emit change of index of a given key, asynchronously | |
| emitKeyChange(oldKey, newKey, _hash) | Emit a change of key on newKey | |
| emitChildConnection(type, path, map, _hash) | Emit connection/disconnection of a child synchronously | |
| watch(path, listener, event, scope) | Watch a value at a given path The listener is called immediately after it has connected successfully. | |
| unwatch(path, listener, event, scope) | Unwatch a value at a given path | |
| connectWatch(path, event, bind) | Try to connect watch at a given path. | |
| disconnectWatch(path, event, bind) | Undo MMO.core.Map#connectWatch. | |
| disconnectScope(scope) | Remove all watch/events set by a given scope | |
| changeWatchPath(oldPath, newPath, _hash) | Move watch from a path to another | |
| onChildConnection(type, parent, path, map) | [internal] React to a child being connected or disconnected anywhere below this map, by (re)connecting the watches whose path is now reachable, and dropping the others. | |
| extendedEntries() generator | Get a list of entries, index and events | |
| setExtendedEntries(entries, preserveArray) | Set values, keus, indexes and readjust watch path and events INTERNAL: used by sort or changeIndex | |
| clear() | Clear the map | |
| get(key) | Read a value. | |
| set(key, value, _hash) | Set the value at a given key | |
| delete(key) | Delete a value at a given key | |
| changeKey(oldKey, newKey, moveValue) | Change key of a value without changing its index. | |
| changeIndex(key, index, preserveArray) | Change index of a key | |
| setValue(obj, _hash) | Set the content of this map with the content of an object | |
| merge(obj, _hash) | Merge values from another object | |
| yieldWalk(path, create) generator | Walk through the map using json path, creating the structure if needed. | |
| walkTo(path, create) | Walk through the map using json path, creating the structure if needed. | |
| keyAt(path) | Get the last key of a path. | |
| mapAt(path, create) | Get the map HOLDING the value at a path (its parent), not the value itself. | |
| getAt(path, create) | Get the value at a path. | |
| safeGetAt(path, def) | Get the value at a path, never throwing. | |
| exists(path) | Test whether a path holds a value. | |
| setAt(path, value) | Set a value at a path, creating the missing levels along the way. | |
| mergeAt(path, value) | Merge a value into a path: recursive when both sides are maps, a plain set otherwise. | |
| deleteAt(path) | Delete element at given path | |
| isArray(allowEmpty) | Check if content is a json array (indexes are ordered integer starting from 0) | |
| push(value) | Append a value. | |
| unshift(value) | Insert a value in front, shifting every other item up one index. | |
| pop() | Remove and return the last value. | |
| shift() | Remove and return the first value, shifting every other item down one index. | |
| includes(value, similar) | Test whether a value is present. | |
| usort(cmp, preserveArray) | Sort by key and value | |
| ksort(cmp) | Sort by keys | |
| sort(cmp, preserveArray) | Sort by values | |
| setSchema(schema) | Set map schema | |
| getKeySchema(key, resolveInstance) | Get the schema describing one key. | |
| validate() | Validate the map against its schema | |
| validateKey(key) | Validate one key against its schema. |
Properties1
length
accessorMap.js:1214Alias of size, so an array Map reads like a javascript array.
- Type
number
Methods65
constructor(args)
Map.js:65| ...args |
From(obj, schema, _hash)
staticMap.js:80Build a Map from any plain value, recursively.
| obj | Object | Array | Map | the data to import |
| schema = null | ?(MMO.schemas.Schema | Promise | Object) | an optional schema to attach |
| _hash = new WeakMap() | WeakMap | [internal] prevents infinite recursion on cyclic data |
| returns | this | an instance of the class From was called on (so Entity.From yields an Entity) |
toObject(deep, _hash)
Map.js:98Convert this object to primitive object/array
| deep = true | Boolean | if deep, recursively convert inner MMO.core.Map |
| _hash = new WeakMap() | ||
| returns | Object | Array |
toArray(deep, _hash)
Map.js:116Force conversion of this map to an array (if toObject returned an array, only its values are returned)
| deep = true | ||
| _hash = new WeakMap() | ||
| returns | Array |
toJSON()
Map.js:125Convert this object to primitive object/array
| returns | Object | Array |
isEqual(obj, strictOrder)
Map.js:135Test if content of this map is strictly equal to the content of an object
| obj | Object | |
| strictOrder = true | Boolean | if true check if the order of the keys match too |
| returns | Boolean |
isSimilar(obj)
Map.js:145Test whether this map CONTAINS the content of an object (a one-way comparison).
- See
MMO.core.isSimilarfor the exact rules
| obj | Object | Map | |
| returns | boolean |
isEmpty()
Map.js:152| returns | boolean | true when the map holds nothing |
getText(key)
Map.js:161Render a value as plain text, through the key's schema when there is one.
| key | string | number | |
| returns | string |
getHTML(key)
Map.js:172Render a value as html, through the key's schema when there is one.
| key | string | number | |
| returns | string | Element |
keyOf(value)
Map.js:186Find the key holding a value (strict equality, first match).
| value | * | |
| returns | ?(string | number) | null when the value is absent |
indexOf(value)
Map.js:198Find the position of a value (strict equality, first match).
| value | * | |
| returns | number | -1 when the value is absent |
indexOfKey(key)
Map.js:212Find the position of a key.
| key | string | number | |
| returns | number | -1 when the key is absent |
keyAtIndex(index)
Map.js:226Get the key sitting at a given index.
| index | number | a negative index counts back from the end |
| returns | ?(string | number) | null when the index is out of range |
ketAtIndex(index)
deprecatedMap.js:238| index |
pathOf(value, _hash)
Map.js:247Get the path of a value
| value | * | |
| _hash = new WeakSet() | ||
| returns | Array | null |
connectChild(map, key)
Map.js:265| map | ||
| key |
disconnectChild(map, key)
Map.js:287Detach a child map: emit MMO.core.MAP_DISCONNECT, then forget the parent link.
| map | MMO.core.Map | the child |
| key | string | number | the key it was held at |
loopEventsByScopeRecursive(scope, _hash)
generatorMap.js:298Yield all events concerning a given scope recursively
| scope | object | the scope to look for in EventBinding |
| _hash = new WeakSet() | WeakSet | (internal) prevent recursion |
loopEmit()
generatorMap.js:322Yield the entries of the global run queue that concern this map, i.e. the changes that have been emitted but not yet delivered.
emitChange(_hash)
Map.js:334Emit change asynchronously
| _hash = new WeakSet() |
emitValueChange(key, type, _hash)
Map.js:352Emit change of a value at a given key, asynchronously
| key | string | int | |
| type = MMO.core.MAP_VALUE_CHANGED | string | one of MMO.core.(MAP_VALUE_CREATED|MAP_VALUE_CHANGED|MAP_VALUE_DELETED) |
| _hash = new WeakSet() |
emitIndexChange(key, oldIndex)
Map.js:366Emit change of index of a given key, asynchronously
| key | string | int | |
| oldIndex | int | the old index of the key |
emitKeyChange(oldKey, newKey, _hash)
Map.js:378Emit a change of key on newKey
| oldKey | string | the old key for the value |
| newKey | string | the new key for the value |
| _hash = new WeakSet() |
emitChildConnection(type, path, map, _hash)
Map.js:392Emit connection/disconnection of a child synchronously
| type | Symbol | MMO.core.MAP_CONNECT | MMO.core.MAP_DISCONNECT |
| path | string | the current path of map from this |
| map | MMO.core.Map | the map being connected |
| _hash = new WeakSet() |
watch(path, listener, event, scope)
Map.js:417Watch a value at a given path The listener is called immediately after it has connected successfully.
| path | string | the path at which to register the event (Array path NOT ALLOWED) |
| listener | Function | MMO.core.EventBinding | function(type, map, key, oldValue) |
| event = null | Symbol | null | if null use the key at the end of path |
| scope = null | null | Object | the scope to call the listener with (ignore when listener is an EventBinding) |
| returns | MMO.core.EventBinding | the bind |
unwatch(path, listener, event, scope)
Map.js:450Unwatch a value at a given path
| path | string | integer | the path at which to register the event (Array path NOT ALLOWED) |
| listener = null | Function | MMO.core.EventBinding | null | if null will look for binding with the right scope |
| event = null | Symbol | null | if null use the key at the end of path |
| scope = false | false | null | Object | if != false, look for binding with the right scope |
| returns | ?MMO.core.EventBinding | the bind or null if nothing was found |
connectWatch(path, event, bind)
Map.js:488Try to connect watch at a given path.
| path | string | integer | Array | a valid json path |
| event | string | Symbol | the event to connect to |
| bind | MMO.core.EventBinding | the bind to connect |
disconnectWatch(path, event, bind)
Map.js:531Undo MMO.core.Map#connectWatch. A path that no longer resolves is not an error: the watch simply had nothing attached.
| path | string | number | Array | |
| event | ?(string | Symbol) | |
| bind | MMO.core.EventBinding |
disconnectScope(scope)
Map.js:545Remove all watch/events set by a given scope
| scope |
changeWatchPath(oldPath, newPath, _hash)
Map.js:575Move watch from a path to another
| oldPath | string | integer | the old path at which the listener was registered (Array path NOT ALLOWED) |
| newPath | string | integer | the new path at which the listener was registered (Array path NOT ALLOWED) |
| _hash = new WeakMap() |
onChildConnection(type, parent, path, map)
Map.js:609[internal] React to a child being connected or disconnected anywhere below this map, by (re)connecting the watches whose path is now reachable, and dropping the others.
| type | Symbol | MMO.core.MAP_CONNECT | MMO.core.MAP_DISCONNECT |
| parent | MMO.core.Map | the map the child was attached to |
| path | string | the child's path, relative to this map |
| map | MMO.core.Map | the child |
extendedEntries()
generatorMap.js:633Get a list of entries, index and events
| returns | Generator<key, value, index, events> |
setExtendedEntries(entries, preserveArray)
Map.js:648Set values, keus, indexes and readjust watch path and events INTERNAL: used by sort or changeIndex
| entries | ||
| preserveArray = true | ||
| returns | MMO.core.Map |
clear()
Map.js:700Clear the map
get(key)
Map.js:717Read a value.
| key | * | |
| returns | * | undefined when the key is absent, or when the alias is write-only |
set(key, value, _hash)
Map.js:736Set the value at a given key
| key | * | |
| value | * | |
| _hash = new WeakMap() | ||
| returns | Boolean | true if the Map has changed |
delete(key)
Map.js:789Delete a value at a given key
| key | * | |
| returns | Boolean | true if the Map has changed |
changeKey(oldKey, newKey, moveValue)
Map.js:838Change key of a value without changing its index.
| oldKey | string | integer | the current key |
| newKey | string | integer | the new key to move to |
| moveValue = true | boolean | if true will also move the value |
| returns | boolean | true if the Map has changed |
changeIndex(key, index, preserveArray)
Map.js:883Change index of a key
| key | string | integer | the key |
| index | ||
| preserveArray = true | boolean | if this map is an array and this is true, the keys are ignored in the sorting process |
| returns | boolean | true if the Map has changed |
setValue(obj, _hash)
Map.js:907Set the content of this map with the content of an object
| obj | Object | |
| _hash = new WeakMap() | ||
| returns | Boolean | true if object has changed |
merge(obj, _hash)
Map.js:1005Merge values from another object
| obj | object | |
| _hash = new WeakMap() | ||
| returns | this |
yieldWalk(path, create)
generatorMap.js:1037Walk through the map using json path, creating the structure if needed.
| path | string | integer | Array | a valid json path (with no parent reference) |
| create = false | boolean | if true create the structure (as MMO.core.Map) along the way |
walkTo(path, create)
Map.js:1080Walk through the map using json path, creating the structure if needed.
| path | string | integer | Array | a valid json path (with no parent reference) |
| create = false | boolean | if true create the structure (as MMO.core.Map) along the way |
| returns | the current key,value,map at the current path (map represents the current parent) if key is null it means the path is empty and value === map |
keyAt(path)
Map.js:1091Get the last key of a path.
| path | string | number | Array | |
| returns | ?(string | number) | null when the path is empty |
mapAt(path, create)
Map.js:1102Get the map HOLDING the value at a path (its parent), not the value itself.
| path | string | number | Array | |
| create = false | boolean | create the missing levels along the way |
| returns | MMO.core.Map |
getAt(path, create)
Map.js:1114Get the value at a path.
| path | string | number | Array | |
| create = false | boolean | create the missing levels along the way |
| returns | * | undefined when the path holds nothing |
| throws | MMO.PathError | when the path crosses a value that is not a Map |
safeGetAt(path, def)
Map.js:1125Get the value at a path, never throwing.
| path | string | number | Array | |
| def | * | returned when the path is missing or broken |
| returns | * |
exists(path)
Map.js:1140Test whether a path holds a value.
| path | string | number | Array | |
| returns | boolean | false when the path is missing OR cannot be walked |
setAt(path, value)
Map.js:1154Set a value at a path, creating the missing levels along the way.
| path | string | number | Array | an empty path replaces this map's whole content |
| value | * | |
| returns | boolean | true when something changed |
mergeAt(path, value)
Map.js:1165Merge a value into a path: recursive when both sides are maps, a plain set otherwise.
| path | string | number | Array | |
| value | * | |
| returns | this |
deleteAt(path)
Map.js:1179Delete element at given path
| path | string | integer | array | |
| returns | boolean |
isArray(allowEmpty)
Map.js:1198Check if content is a json array (indexes are ordered integer starting from 0)
| allowEmpty = false | Boolean | if true, also return true if the map is empty |
| returns | Boolean |
push(value)
Map.js:1242Append a value.
| value | * | |
| returns | boolean | true when the map changed |
| throws | MMO.TypeError | when this map is not an array |
unshift(value)
Map.js:1254Insert a value in front, shifting every other item up one index.
| value | * | |
| returns | boolean | |
| throws | MMO.TypeError | when this map is not an array |
pop()
Map.js:1283Remove and return the last value.
| returns | * | undefined when the map is empty |
| throws | MMO.TypeError | when this map is not an array |
shift()
Map.js:1298Remove and return the first value, shifting every other item down one index.
| returns | * | undefined when the map is empty |
| throws | MMO.TypeError | when this map is not an array |
includes(value, similar)
Map.js:1313Test whether a value is present.
| value | * | |
| similar = false | boolean | compare with MMO.core.isSimilar instead of === |
| returns | boolean |
usort(cmp, preserveArray)
Map.js:1329Sort by key and value
| cmp | Function | fn([keyA, valueA], [keyB, valueB]): {int} |
| preserveArray = true | boolean | if this map is an array and this is true, the keys are ignored in the sorting process |
| returns | this |
ksort(cmp)
Map.js:1339Sort by keys
| cmp = MMO.core.compare | Function | fn(keyA, keyB): {int} |
| returns | this |
sort(cmp, preserveArray)
Map.js:1349Sort by values
| cmp = MMO.core.compare | Function | fn(valueA, valueB): {int} |
| preserveArray = true | boolean | if this map is an array and this is true, the keys are ignored in the sorting process |
| returns | this |
setSchema(schema)
Map.js:1360Set map schema
| schema | Promise<MMO.schemas.Schema> |
getKeySchema(key, resolveInstance)
Map.js:1406Get the schema describing one key.
| key | string | number | |
| resolveInstance = false | boolean | resolve an instanceOf schema first; this makes the call ASYNCHRONOUS and it then returns a Promise instead of a Schema |
| returns | ?(MMO.schemas.Schema | Promise<MMO.schemas.Schema>) | null when there is no schema |
validate()
Map.js:1420Validate the map against its schema
| returns | Promise<MMO.schemas.Annotation> | if no schema is set the returned annotation is null |
validateKey(key)
Map.js:1430Validate one key against its schema.
| key | string | number | |
| returns | Promise<?MMO.schemas.Annotation> | null when the key has no schema |