Generic ArrayList class for managing lists of items and iterating operations over them. The targeted use for this class is for augmentation onto a class that is responsible for managing multiple instances of another class (e.g. NodeList for Nodes). The recommended use is to augment your class with ArrayList, then use ArrayList.addMethod to mirror the API of the constituent items on the list's API.
The default implementation creates immutable lists, but mutability can be provided via the arraylist-add submodule or by implementing mutation methods directly on the augmented class's prototype.
ArrayList
items
Defined in
collection/js/arraylist.js:11
items
Array
array of items this list will be responsible for
_item
i
Defined in
collection/js/arraylist.js:138
Protected method for optimizations that may be appropriate for API
mirroring. Similar in functionality to item
, but is used by
methods added with ArrayList.addMethod()
.
i
Integer
Index of item to fetch
The item appropriate for pass through API methods
add
item
index
Provided by the arraylist-add module.
Defined in
collection/js/arraylist-add.js:13
Deprecated: Use ModelList or a custom ArrayList subclass
Add a single item to the ArrayList. Does not prevent duplicates.
item
Mixed
Item presumably of the same type as others in the ArrayList.
index
Number
(Optional.) Number representing the position at which the item should be inserted.
the instance.
addMethod
dest
name
Defined in
collection/js/arraylist.js:156
Adds a pass through method to dest (typically the prototype of a list class) that calls the named method on each item in the list with whatever parameters are passed in. Allows for API indirection via list instances.
Accepts a single string name or an array of string names.
list.each( function ( item ) {
item.methodName( 1, 2, 3 );
} );
// becomes
list.methodName( 1, 2, 3 );
Additionally, the pass through methods use the item retrieved by the
_item
method in case there is any special behavior that is
appropriate for API mirroring.
If the iterated method returns a value, the return value from the added method will be an array of values with each value being at the corresponding index for that item. If the iterated method does not return a value, the added method will be chainable.
each
fn
context
Defined in
collection/js/arraylist.js:51
Execute a function on each item of the list, optionally providing a custom execution context. Default context is the item.
The callback signature is callback( item, index )
.
fn
Function
the function to execute
context
Mixed
optional override 'this' in the function
this instance
filter
validator
Provided by the arraylist-filter module.
Defined in
collection/js/arraylist-filter.js:13
Deprecated: Use ModelList or a custom subclass implementation
Create a new ArrayList (or augmenting class instance) from a subset of items as determined by the boolean function passed as the argument. The original ArrayList is unchanged.
The validator signature is validator( item )
.
validator
Function
Boolean function to determine in or out.
New instance based on who passed the validator.
indexOf
needle
Defined in
collection/js/arraylist.js:95
Finds the first index of the needle in the managed array of items.
needle
Mixed
The item to search for
Array index if found. Otherwise -1
isEmpty
Defined in
collection/js/arraylist.js:116
Is this instance managing any items?
true if 1 or more items are being managed
item
i
Defined in
collection/js/arraylist.js:37
Get an item by index from the list. Override this method if managing a list of objects that have a different public representation (e.g. Node instances vs DOM nodes). The iteration methods that accept a user function will use this method for access list items for operation.
i
Integer
index to fetch
the item at the requested index
itemsAreEqual
a
b
Provided by the arraylist-add module.
Defined in
collection/js/arraylist-add.js:68
Deprecated: Use ModelList or a custom ArrayList subclass
Default comparator for items stored in this list. Used by remove().
a
Mixed
item to test equivalence with.
b
Mixed
other item to test equivalance.
true if items are deemed equivalent.
remove
needle
all
comparator
Provided by the arraylist-add module.
Defined in
collection/js/arraylist-add.js:39
Deprecated: Use ModelList or a custom ArrayList subclass
Removes first or all occurrences of an item to the ArrayList. If a comparator is not provided, uses itemsAreEqual method to determine matches.
the instance.
size
Defined in
collection/js/arraylist.js:106
How many items are in this list?
Number of items in the list
some
fn
context
Defined in
collection/js/arraylist.js:73
Execute a function on each item of the list, optionally providing a custom execution context. Default context is the item.
The callback signature is callback( item, index )
.
Unlike each
, if the callback returns true, the
iteration will stop.
fn
Function
the function to execute
context
Mixed
optional override 'this' in the function
True if the function returned true on an item
toJSON
Defined in
collection/js/arraylist.js:126
Provides an array-like representation for JSON.stringify.
an array representation of the ArrayList