new OrderedMap()
Arraylike structure that preserves order while maintaining fast lookup by key.
The order of the array is detirmined by a sorted array of z-indicies, which are *positive* integers including 0.
Used for the Postcard rendering stack.
- Source:
Methods
-
add(key, zindex, value)
-
Adds a new object to the OrderedMap. If the key already exists, an Error is thrown.
Parameters:
Name Type Description keyString The unique identifier that can get/set the object zindexNumber The new z-index value to search with valueWhatever needs to be stored. - Source:
-
assert(key) → {Error}
-
Asserts that key exists in the OrderedMap
Parameters:
Name Type Description keyString - Source:
Returns:
if not found- Type
- Error
-
changeOrder(key, zindex)
-
Change the order of an object in the OrderedMap
Parameters:
Name Type Description keyString zindexNumber - Source:
Returns:
a new Error if the key does not exist or if the new z-index is < 0 -
exists(key) → {Boolean}
-
Asserts that key exists in the OrderedMap
Parameters:
Name Type Description keyString - Source:
Returns:
- Type
- Boolean
-
filter(callback)
-
Creates an array with all elements that pass the test implemented by the provided function. [TODO] Implement thisArg instead of apply-ing with null
Parameters:
Name Type Description callbackfunction Function to test each element of the OrderedMap. Invoked with arguments (key, zindex, value). Return true to keep the object, false otherwise. - Source:
-
findFirst(zindex) → {Number}
-
Traverses the sorted z-index array and find the index where the new z-index value should be inserted.
Parameters:
Name Type Description zindexNumber The new z-index value to search with - Source:
Returns:
- Type
- Number
-
forEach(callback)
-
Traverse through the OrderedMap, starting from lowest z-index to highest z-index.
Parameters:
Name Type Description callbackobjectCallback The callback function for each individual object. - Source:
-
get(key)
-
Get a object from the OrderedMap
Parameters:
Name Type Description keyString - Source:
Returns:
The value stored or a new Error if the key does not exist -
getZindex(key) → {Number|Error}
-
Get a object's z-index from the OrderedMap
Parameters:
Name Type Description keyString - Source:
Returns:
The z-index or a new Error if the key does not exist- Type
- Number | Error
-
length() → {Number|Error}
-
Number of objects in the OrderedMap
- Source:
Returns:
Length of the OrderedMap or Error if there's an unresolved issue.- Type
- Number | Error
-
remove(key)
-
Remove a object from the OrderedMap
Parameters:
Name Type Description keyString - Source:
-
toEnd(key)
-
Bring an object to the end of the OrderMap. Its new z-index will be the same as the greatest z-index currently in the OrderedMap, appearing after that object.
Parameters:
Name Type Description keyString - Source:
Returns:
a new Error if the key does not exist -
toStart(key)
-
Bring an object to the start of the OrderMap, i.e. set the z-index to 0. It will still appear after other objects which also have a z-index of 0, however. [TODO] modify this functionality so it is guaranteed to be at the first index?
Parameters:
Name Type Description keyString - Source:
Returns:
a new Error if the key does not exist -
updateValue(key, value)
-
Update the value of an object in the OrderedMap
Parameters:
Name Type Description keyString valueThe new value - Source:
Type Definitions
-
objectCallback(key, zindex, value)
-
This is called for each object in the OrderedMap.
Parameters:
Name Type Description keyString The key of the object zindexNumber The z-index of the object valueThe value of the object - Source: