List is a generic implementation of an ordered list which contains utility methods for retrieving, manipulating, and iterating items.
new List(parent)
name | type | description |
---|---|---|
parent | * |
The parent of this list. |
The property key to sort by.
A callback that is invoked every time a child is added to this list.
The first item in the List or null
for an empty List.
The last item in the List, or null
for an empty List.
The number of items inside the List.
The objects that belong to this collection.
The next item in the List, or null
if the entire List has been traversed.
This property can be read successively after reading #first or manually setting the #position to iterate the List.
The parent of this list.
The index of the current element.
This is used internally when iterating through the list with the #first, #last, #get, and #previous properties.
The previous item in the List, or null
if the entire List has been traversed.
This property can be read successively after reading #last or manually setting the #position to iterate the List backwards.
A callback that is invoked every time a child is removed from this list.
Adds the given item to the end of the list. Each item must be unique.
name | type | arguments | Default | description |
---|---|---|---|---|
child | * | Array.<*> |
The item, or array of items, to add to the list. |
||
skipCallback | boolean | <optional> | false |
Skip calling the List.addCallback if this child is added successfully. |
The list's underlying array.
Adds an item to list, starting at a specified index. Each item must be unique within the list.
name | type | arguments | Default | description |
---|---|---|---|---|
child | * |
The item, or array of items, to add to the list. |
||
index | number | <optional> | 0 |
The index in the list at which the element(s) will be inserted. |
skipCallback | boolean | <optional> | false |
Skip calling the List.addCallback if this child is added successfully. |
The List's underlying array.
Brings the given child to the top of this List.
name | type | description |
---|---|---|
child | * |
The item to bring to the top of the List. |
The item which was moved.
Returns the total number of items in the List which have a property matching the given value.
name | type | description |
---|---|---|
property | string |
The property to test on each item. |
value | * |
The value to test the property against. |
The total number of matching elements.
Passes all children to the given callback.
name | type | arguments | description |
---|---|---|---|
callback | EachListCallback |
The function to call. |
|
context | * | <optional> |
Value to use as |
args | * | <optional> |
Additional arguments that will be passed to the callback, after the child. |
Checks if an item exists within the List.
name | type | description |
---|---|---|
child | * |
The item to check for the existence of. |
true
if the item is found in the list, otherwise false
.
Returns all children in this List.
You can optionally specify a matching criteria using the property
and value
arguments.
For example: getAll('parent')
would return only children that have a property called parent
.
You can also specify a value to compare the property to:
getAll('visible', true)
would return only children that have their visible property set to true
.
Optionally you can specify a start and end index. For example if this List had 100 children,
and you set startIndex
to 0 and endIndex
to 50, it would return matches from only
the first 50 children in the List.
name | type | arguments | description |
---|---|---|---|
property | string | <optional> |
An optional property to test against the value argument. |
value | any | <optional> |
If property is set then Child.property must strictly equal this value to be included in the results. |
startIndex | number | <optional> |
The first child index to start the search from. |
endIndex | number | <optional> |
The last child index to search up until. |
All items of the List which match the given criterion, if any.
Retrieves the item at a given position inside the List.
name | type | description |
---|---|---|
index | number |
The index of the item. |
The retrieved item, or undefined
if it's outside the List's bounds.
Searches for the first instance of a child with its name
property matching the given argument. Should more than one child have
the same name only the first is returned.
name | type | description |
---|---|---|
name | string |
The name to search for. |
The first child with a matching name, or null if none were found.
Returns the first element in a given part of the List which matches a specific criterion.
name | type | arguments | description |
---|---|---|---|
property | string |
The name of the property to test or a falsey value to have no criterion. |
|
value | * |
The value to test the |
|
startIndex | number | <optional> |
The position in the List to start the search at. |
endIndex | number | <optional> |
The position in the List to optionally stop the search at. It won't be checked. |
The first item which matches the given criterion, or null
if no such item exists.
Locates an item within the List and returns its index.
name | type | description |
---|---|---|
child | * |
The item to locate. |
The index of the item within the List, or -1 if it's not in the List.
Returns a random child from the group.
name | type | arguments | Default | description |
---|---|---|---|---|
startIndex | number | <optional> | 0 |
Offset from the front of the group (lowest child). |
length | number | <optional> | (to top) |
Restriction on the number of values you want to randomly select from. |
A random child of this Group.
Moves an item above another one in the List. If the given item is already above the other, it isn't moved. Above means toward the end of the List.
name | type | description |
---|---|---|
child1 | * |
The element to move above base element. |
child2 | * |
The base element. |
Moves an item below another one in the List. If the given item is already below the other, it isn't moved. Below means toward the start of the List.
name | type | description |
---|---|---|
child1 | * |
The element to move below base element. |
child2 | * |
The base element. |
Moves the given child down one place in this group unless it's already at the bottom.
name | type | description |
---|---|---|
child | * |
The item to move down. |
The item which was moved.
Moves an item in the List to a new position.
name | type | description |
---|---|---|
child | * |
The item to move. |
index | number |
Moves an item in the List to a new position. |
The item that was moved.
Moves the given child up one place in this group unless it's already at the top.
name | type | description |
---|---|---|
child | * |
The item to move up. |
The item which was moved.
Removes one or many items from the List.
name | type | arguments | Default | description |
---|---|---|---|---|
child | * |
The item, or array of items, to remove. |
||
skipCallback | boolean | <optional> | false |
Skip calling the List.removeCallback. |
The item, or array of items, which were successfully removed from the List.
Removes all the items.
name | type | arguments | Default | description |
---|---|---|---|---|
skipCallback | boolean | <optional> | false |
Skip calling the List.removeCallback. |
This List object.
Removes the item at the given position in the List.
name | type | arguments | Default | description |
---|---|---|---|---|
index | number |
The position to remove the item from. |
||
skipCallback | boolean | <optional> | false |
Skip calling the List.removeCallback. |
The item that was removed.
Removes the items within the given range in the List.
name | type | arguments | Default | description |
---|---|---|---|---|
startIndex | number | <optional> | 0 |
The index to start removing from. |
endIndex | number | <optional> |
The position to stop removing at. The item at this position won't be removed. |
|
skipCallback | boolean | <optional> | false |
Skip calling the List.removeCallback. |
An array of the items which were removed.
Replaces a child of this List with the given newChild. The newChild cannot be a member of this List.
name | type | description |
---|---|---|
oldChild | * |
The child in this List that will be replaced. |
newChild | * |
The child to be inserted into this List. |
Returns the oldChild that was replaced within this group.
Reverses the order of all children in this List.
This List object.
Sends the given child to the bottom of this List.
name | type | description |
---|---|---|
child | * |
The item to send to the back of the list. |
The item which was moved.
Sets the property key
to the given value on all members of this List.
name | type | arguments | description |
---|---|---|---|
property | string |
The name of the property to set. |
|
value | * |
The value to set the property to. |
|
startIndex | number | <optional> |
The first child index to start the search from. |
endIndex | number | <optional> |
The last child index to search up until. |
Shuffles the items in the list.
This List object.
Clears the List and recreates its internal array.
Sort the contents of this List so the items are in order based on the given property.
For example, sort('alpha')
would sort the List contents based on the value of their alpha
property.
name | type | arguments | description |
---|---|---|---|
property | string |
The property to lexically sort by. |
|
handler | function | <optional> |
Provide your own custom handler function. Will receive 2 children which it should compare and return a boolean. |
This List object.
Swaps the positions of two items in the list.
name | type | description |
---|---|---|
child1 | * |
The first item to swap. |
child2 | * |
The second item to swap. |