Class: Collection

Collection


new Collection()

Provides the sortable, iterable storage of entities that are
gettable, settable, sortable, removable, etcera(ble) by name

Author:
  • Chris Peters
Source:

Methods


addItem(item, name)

Add an item with optional name

Parameters:
Name Type Argument Description
item Any

The item to add

name String <optional>

The optional name of the item

Source:
Returns:
Type
Collection

addItems(items)

Add multiple items

Parameters:
Name Type Argument Description
items Object <repeatable>

Can be the object itself or an object containing the entity and it's name
eg: { item: Entity, name: 'entityName' }

Source:
Returns:
Type
Collection

each(fn, scope)

Iterates the collection's sorted items. The item, index, and name are supplied
to the provided function

Parameters:
Name Type Argument Description
fn function

The function to execute on the iterable

scope Object <optional>

The scope with which to execute the function

Source:

filter(fn, scope)

iterates items and return the ones that meet criteria

Parameters:
Name Type Argument Description
fn function

Truth predicate

scope Object <optional>

The scope with which to execute the function

Source:
Returns:
Type
Array

getItem(name)

Returns an existing item by name, or undefined if the name is not found

Parameters:
Name Type Description
name String

The name of the item

Source:
Returns:
Type
Any

getItemArray()

Returns a list of just the items

Source:
Returns:
Type
Array

getItemAt(index)

Returns an existing item by index

Parameters:
Name Type Description
index Integer
Source:
Returns:
Type
Any

getItemCount()

Returns the count of items in collection

Source:
Returns:
Type
Integer

getItemIndex(name)

Returns an item's current index

Parameters:
Name Type Description
name String
Source:
Returns:
Type
Integer

removeAllItems()

Removes all items from collection

Source:

setItem(name, value)

Assigns a new value to an existing item

Parameters:
Name Type Description
name String

The name of the object to modify

value Any

The new value

Source:

setItemIndex(name, index)

Moves item to new index

Parameters:
Name Type Description
name String

The name of the object being moved

index Integer

The item's new index

Source: