Class: OrderedMap

OrderedMap

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
key String The unique identifier that can get/set the object
zindex Number The new z-index value to search with
value Whatever needs to be stored.
Source:

assert(key) → {Error}

Asserts that key exists in the OrderedMap
Parameters:
Name Type Description
key String
Source:
Returns:
if not found
Type
Error

changeOrder(key, zindex)

Change the order of an object in the OrderedMap
Parameters:
Name Type Description
key String
zindex Number
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
key String
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
callback function 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
zindex Number 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
callback objectCallback The callback function for each individual object.
Source:

get(key)

Get a object from the OrderedMap
Parameters:
Name Type Description
key String
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
key String
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
key String
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
key String
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
key String
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
key String
value The new value
Source:

Type Definitions

objectCallback(key, zindex, value)

This is called for each object in the OrderedMap.
Parameters:
Name Type Description
key String The key of the object
zindex Number The z-index of the object
value The value of the object
Source: