Index

Map

MMO.core · 1 symbol · generated 5 Oct 2026

class

Map

Map.js:64

Extension of a javascript Map with events.

class MMO.core.Map extends MMO.core.mixinEventEmitter(Map)
Namespace
MMO.core
Extends
mixinEventEmitter(Map)
Events are triggered asynchronously whenever a change happen on the map. All events have the same signature function (type, map, path, value), where: - type: is one of the MMO.core.MAP_* constant - map is the current map triggering the event - path is the key at which the event is triggered, except for - MMO.core.MAP_CHANGED: this argument is not used - MMO.core.MAP_CONNECT|MMO.core.MAP_DISCONNECT: it is the path of the value compare to the current map - value is only used by : - MMO.core.MAP_INDEX_CHANGED: it is the old index of the key - MMO.core.MAP_KEY_CHANGED: it is the old key - MMO.core.MAP_CONNECT|MMO.core.MAP_DISCONNECT: it is the map being connected Events propagate from the target to all its parents. There are 2 types of events. 1. The ones registered at a given key: `map.on(key, fn(type, map, key, value))` - MMO.core.MAP_VALUE_CHANGED - MMO.core.MAP_VALUE_CREATED - MMO.core.MAP_VALUE_DELETED - MMO.core.MAP_INDEX_CHANGED - MMO.core.MAP_KEY_CHANGED 2. The ones registered with a Symbol: `map.on(MMO.core.MAP_xxx, fn(type, map, key, value))` - MMO.core.MAP_CHANGED - MMO.core.MAP_CONNECT - MMO.core.MAP_DISCONNECT Note: in order for the watches to work, MMO.core.MAP_CONNECT and MMO.core.MAP_DISCONNECT are emitted synchronously

Index

length accessorAlias of size, so an array Map reads like a javascript array.
constructor(args)
From(obj, schema, _hash) staticBuild 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) generatorYield all events concerning a given scope recursively
loopEmit() generatorYield 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() generatorGet 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) generatorWalk 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:1215

Alias of size, so an array Map reads like a javascript array.

get length() set length(value)
Type
number

Methods65

constructor(args)

Map.js:65
constructor(...args)
...args

From(obj, schema, _hash)

staticMap.js:80

Build a Map from any plain value, recursively.

static From(obj, schema = null, _hash = new WeakMap())Nested objects and arrays become Maps too, so the whole tree is observable.
objObject | Array | Mapthe 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
returnsthisan instance of the class From was called on (so Entity.From yields an Entity)

toObject(deep, _hash)

Map.js:98

Convert this object to primitive object/array

toObject(deep = true, _hash = new WeakMap())
deep = trueBooleanif deep, recursively convert inner MMO.core.Map
_hash = new WeakMap()
returnsObject | Array

toArray(deep, _hash)

Map.js:116

Force conversion of this map to an array (if toObject returned an array, only its values are returned)

toArray(deep = true, _hash = new WeakMap())
deep = true
_hash = new WeakMap()
returnsArray

toJSON()

Map.js:125

Convert this object to primitive object/array

toJSON()
returnsObject | Array

isEqual(obj, strictOrder)

Map.js:135

Test if content of this map is strictly equal to the content of an object

isEqual(obj, strictOrder = true)
objObject
strictOrder = trueBooleanif true check if the order of the keys match too
returnsBoolean

isSimilar(obj)

Map.js:145

Test whether this map CONTAINS the content of an object (a one-way comparison).

isSimilar(obj)
See
MMO.core.isSimilar for the exact rules
objObject | Map
returnsboolean

isEmpty()

Map.js:152
isEmpty()
returnsbooleantrue when the map holds nothing

getText(key)

Map.js:161

Render a value as plain text, through the key's schema when there is one.

getText(key)
keystring | number
returnsstring

getHTML(key)

Map.js:172

Render a value as html, through the key's schema when there is one.

getHTML(key)
keystring | number
returnsstring | Element

keyOf(value)

Map.js:186

Find the key holding a value (strict equality, first match).

keyOf(value)
value*
returns?(string | number)null when the value is absent

indexOf(value)

Map.js:198

Find the position of a value (strict equality, first match).

indexOf(value)
value*
returnsnumber-1 when the value is absent

indexOfKey(key)

Map.js:212

Find the position of a key.

indexOfKey(key)
keystring | number
returnsnumber-1 when the key is absent

keyAtIndex(index)

Map.js:226

Get the key sitting at a given index.

keyAtIndex(index)
indexnumbera negative index counts back from the end
returns?(string | number)null when the index is out of range

ketAtIndex(index)

deprecatedMap.js:238
ketAtIndex(index)
index

pathOf(value, _hash)

Map.js:247

Get the path of a value

pathOf(value, _hash = new WeakSet())
value*
_hash = new WeakSet()
returnsArray | null

connectChild(map, key)

Map.js:265
connectChild(map, key)
map
key

disconnectChild(map, key)

Map.js:287

Detach a child map: emit MMO.core.MAP_DISCONNECT, then forget the parent link.

disconnectChild(map, key)The event is emitted FIRST so listeners can still see the tree they are leaving.
mapMMO.core.Mapthe child
keystring | numberthe key it was held at

loopEventsByScopeRecursive(scope, _hash)

generatorMap.js:298

Yield all events concerning a given scope recursively

*loopEventsByScopeRecursive(scope, _hash = new WeakSet())
scopeobjectthe scope to look for in EventBinding
_hash = new WeakSet()WeakSet(internal) prevent recursion

loopEmit()

generatorMap.js:322

Yield the entries of the global run queue that concern this map, i.e. the changes that have been emitted but not yet delivered.

*loopEmit()

emitChange(_hash)

Map.js:334

Emit change asynchronously

emitChange(_hash = new WeakSet())
_hash = new WeakSet()

emitValueChange(key, type, _hash)

Map.js:352

Emit change of a value at a given key, asynchronously

emitValueChange(key, type = MMO.core.MAP_VALUE_CHANGED, _hash = new WeakSet())
keystring | int
type = MMO.core.MAP_VALUE_CHANGEDstringone of MMO.core.(MAP_VALUE_CREATED|MAP_VALUE_CHANGED|MAP_VALUE_DELETED)
_hash = new WeakSet()

emitIndexChange(key, oldIndex)

Map.js:366

Emit change of index of a given key, asynchronously

emitIndexChange(key, oldIndex)
keystring | int
oldIndexintthe old index of the key

emitKeyChange(oldKey, newKey, _hash)

Map.js:378

Emit a change of key on newKey

emitKeyChange(oldKey, newKey, _hash = new WeakSet())
oldKeystringthe old key for the value
newKeystringthe new key for the value
_hash = new WeakSet()

emitChildConnection(type, path, map, _hash)

Map.js:392

Emit connection/disconnection of a child synchronously

emitChildConnection(type, path, map, _hash = new WeakSet())
typeSymbolMMO.core.MAP_CONNECT | MMO.core.MAP_DISCONNECT
pathstringthe current path of map from this
mapMMO.core.Mapthe map being connected
_hash = new WeakSet()

watch(path, listener, event, scope)

Map.js:417

Watch a value at a given path The listener is called immediately after it has connected successfully.

watch(path, listener, event = null, scope = null)
pathstringthe path at which to register the event (Array path NOT ALLOWED)
listenerFunction | MMO.core.EventBindingfunction(type, map, key, oldValue)
event = nullSymbol | nullif null use the key at the end of path
scope = nullnull | Objectthe scope to call the listener with (ignore when listener is an EventBinding)
returnsMMO.core.EventBindingthe bind

unwatch(path, listener, event, scope)

Map.js:450

Unwatch a value at a given path

unwatch(path, listener = null, event = null, scope = false)
pathstring | integerthe path at which to register the event (Array path NOT ALLOWED)
listener = nullFunction | MMO.core.EventBinding | nullif null will look for binding with the right scope
event = nullSymbol | nullif null use the key at the end of path
scope = falsefalse | null | Objectif != false, look for binding with the right scope
returns?MMO.core.EventBindingthe bind or null if nothing was found

connectWatch(path, event, bind)

Map.js:488

Try to connect watch at a given path.

connectWatch(path, event, bind)If the watch is connected successfully, it is called directly with the correct arguments
pathstring | integer | Arraya valid json path
eventstring | Symbolthe event to connect to
bindMMO.core.EventBindingthe bind to connect

disconnectWatch(path, event, bind)

Map.js:531

Undo MMO.core.Map#connectWatch. A path that no longer resolves is not an error: the watch simply had nothing attached.

disconnectWatch(path, event, bind)
pathstring | number | Array
event?(string | Symbol)
bindMMO.core.EventBinding

disconnectScope(scope)

Map.js:545

Remove all watch/events set by a given scope

disconnectScope(scope)
scope

changeWatchPath(oldPath, newPath, _hash)

Map.js:575

Move watch from a path to another

changeWatchPath(oldPath, newPath, _hash = new WeakMap())
oldPathstring | integerthe old path at which the listener was registered (Array path NOT ALLOWED)
newPathstring | integerthe 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.

onChildConnection(type, parent, path, map)
typeSymbolMMO.core.MAP_CONNECT | MMO.core.MAP_DISCONNECT
parentMMO.core.Mapthe map the child was attached to
pathstringthe child's path, relative to this map
mapMMO.core.Mapthe child

extendedEntries()

generatorMap.js:633

Get a list of entries, index and events

*extendedEntries()
returnsGenerator<key, value, index, events>

setExtendedEntries(entries, preserveArray)

Map.js:648

Set values, keus, indexes and readjust watch path and events INTERNAL: used by sort or changeIndex

setExtendedEntries(entries, preserveArray = true)
entries
preserveArray = true
returnsMMO.core.Map

get(key)

Map.js:718

Read a value.

get(key)Override: a key declared as an alias in the schema reads through to its target path.
key*
returns*undefined when the key is absent, when the alias is write-only, or when its path is missing
map.get('adresse'); // undefined -- not a ReferenceError -- when there is no `adresses/default`

set(key, value, _hash)

Map.js:737

Set the value at a given key

set(key, value, _hash = new WeakMap())
key*
value*
_hash = new WeakMap()
returnsBooleantrue if the Map has changed

delete(key)

Map.js:790

Delete a value at a given key

delete(key)
key*
returnsBooleantrue if the Map has changed

changeKey(oldKey, newKey, moveValue)

Map.js:839

Change key of a value without changing its index.

changeKey(oldKey, newKey, moveValue = true)If value at newKey is set, it is deleted first
oldKeystring | integerthe current key
newKeystring | integerthe new key to move to
moveValue = truebooleanif true will also move the value
returnsbooleantrue if the Map has changed

changeIndex(key, index, preserveArray)

Map.js:884

Change index of a key

changeIndex(key, index, preserveArray = true)
keystring | integerthe key
index
preserveArray = truebooleanif this map is an array and this is true, the keys are ignored in the sorting process
returnsbooleantrue if the Map has changed

setValue(obj, _hash)

Map.js:908

Set the content of this map with the content of an object

setValue(obj, _hash = new WeakMap())
objObject
_hash = new WeakMap()
returnsBooleantrue if object has changed

merge(obj, _hash)

Map.js:1006

Merge values from another object

merge(obj, _hash = new WeakMap())
objobject
_hash = new WeakMap()
returnsthis

yieldWalk(path, create)

generatorMap.js:1038

Walk through the map using json path, creating the structure if needed.

*yieldWalk(path, create = false)
pathstring | integer | Arraya valid json path (with no parent reference)
create = falsebooleanif true create the structure (as MMO.core.Map) along the way

walkTo(path, create)

Map.js:1081

Walk through the map using json path, creating the structure if needed.

walkTo(path, create = false)
pathstring | integer | Arraya valid json path (with no parent reference)
create = falsebooleanif true create the structure (as MMO.core.Map) along the way
returnsthe 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:1092

Get the last key of a path.

keyAt(path)
pathstring | number | Array
returns?(string | number)null when the path is empty

mapAt(path, create)

Map.js:1103

Get the map HOLDING the value at a path (its parent), not the value itself.

mapAt(path, create = false)
pathstring | number | Array
create = falsebooleancreate the missing levels along the way
returnsMMO.core.Map

getAt(path, create)

Map.js:1115

Get the value at a path.

getAt(path, create = false)
pathstring | number | Array
create = falsebooleancreate the missing levels along the way
returns*undefined when the path holds nothing
throwsMMO.PathErrorwhen the path crosses a value that is not a Map

safeGetAt(path, def)

Map.js:1126

Get the value at a path, never throwing.

safeGetAt(path, def)
pathstring | number | Array
def*returned when the path is missing or broken
returns*

exists(path)

Map.js:1141

Test whether a path holds a value.

exists(path)
pathstring | number | Array
returnsbooleanfalse when the path is missing OR cannot be walked

setAt(path, value)

Map.js:1155

Set a value at a path, creating the missing levels along the way.

setAt(path, value)
pathstring | number | Arrayan empty path replaces this map's whole content
value*
returnsbooleantrue when something changed

mergeAt(path, value)

Map.js:1166

Merge a value into a path: recursive when both sides are maps, a plain set otherwise.

mergeAt(path, value)
pathstring | number | Array
value*
returnsthis

deleteAt(path)

Map.js:1180

Delete element at given path

deleteAt(path)
pathstring | integer | array
returnsboolean

isArray(allowEmpty)

Map.js:1199

Check if content is a json array (indexes are ordered integer starting from 0)

isArray(allowEmpty = false)
allowEmpty = falseBooleanif true, also return true if the map is empty
returnsBoolean

push(value)

Map.js:1243

Append a value.

push(value)
value*
returnsbooleantrue when the map changed
throwsMMO.TypeErrorwhen this map is not an array

unshift(value)

Map.js:1255

Insert a value in front, shifting every other item up one index.

unshift(value)Children keep their parent link, updated to their new index.
value*
returnsboolean
throwsMMO.TypeErrorwhen this map is not an array

pop()

Map.js:1284

Remove and return the last value.

pop()
returns*undefined when the map is empty
throwsMMO.TypeErrorwhen this map is not an array

shift()

Map.js:1299

Remove and return the first value, shifting every other item down one index.

shift()
returns*undefined when the map is empty
throwsMMO.TypeErrorwhen this map is not an array

includes(value, similar)

Map.js:1314

Test whether a value is present.

includes(value, similar = false)
value*
similar = falsebooleancompare with MMO.core.isSimilar instead of ===
returnsboolean

usort(cmp, preserveArray)

Map.js:1330

Sort by key and value

usort(cmp, preserveArray = true)
cmpFunctionfn([keyA, valueA], [keyB, valueB]): {int}
preserveArray = truebooleanif this map is an array and this is true, the keys are ignored in the sorting process
returnsthis

ksort(cmp)

Map.js:1340

Sort by keys

ksort(cmp = MMO.core.compare)
cmp = MMO.core.compareFunctionfn(keyA, keyB): {int}
returnsthis

sort(cmp, preserveArray)

Map.js:1350

Sort by values

sort(cmp = MMO.core.compare, preserveArray = true)
cmp = MMO.core.compareFunctionfn(valueA, valueB): {int}
preserveArray = truebooleanif this map is an array and this is true, the keys are ignored in the sorting process
returnsthis

setSchema(schema)

Map.js:1361

Set map schema

setSchema(schema)
schemaPromise<MMO.schemas.Schema>

getKeySchema(key, resolveInstance)

Map.js:1407

Get the schema describing one key.

getKeySchema(key, resolveInstance = false)
keystring | number
resolveInstance = falsebooleanresolve 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:1421

Validate the map against its schema

validate()
returnsPromise<MMO.schemas.Annotation>if no schema is set the returned annotation is null

validateKey(key)

Map.js:1431

Validate one key against its schema.

validateKey(key)
keystring | number
returnsPromise<?MMO.schemas.Annotation>null when the key has no schema