Expand all

abstract OO.EmitterList

Constructor

new OO.EmitterList()abstract #

Contain and manage a list of OO.EventEmitter items.

Aggregates and manages their events collectively.

This mixin must be used in a class that also mixes in OO.EventEmitter.

Source:
Contain and manage a list of OO.EventEmitter items.

Methods

addItems(items, [index]) → {OO.EmitterList} #

Add items to the list.

Parameters:

Name Type Attributes Description
items OO.EventEmitter | Array.<OO.EventEmitter>

Item to add or an array of items to add

index number optional

Index to add items at. If no index is given, or if the index that is given is invalid, the item will be added at the end of the list.

Source:

Returns:

Type
OO.EmitterList

Fires:

Add items to the list.

aggregate(events) #

Aggregate the events emitted by the group.

When events are aggregated, the group will listen to all contained items for the event, and then emit the event under a new name. The new event will contain an additional leading parameter containing the item that emitted the original event. Other arguments emitted from the original event are passed through.

Parameters:

Name Type Description
events Object

An object keyed by the name of the event that should be aggregated (e.g., ‘click’) and the value of the new name to use (e.g., ‘groupClick’). A null value will remove aggregated events.

Source:

Throws:

If aggregation already exists

Type
Error
Aggregate the events emitted by the group.

clearItems() → {OO.EmitterList} #

Clear all items.

Source:

Returns:

Type
OO.EmitterList

Fires:

Clear all items.

getItemCount() → {number} #

Get number of items.

Source:

Returns:

Number of items in the list

Type
number
Get number of items.

getItemIndex(item) → {number} #

Get the index of a specific item.

Parameters:

Name Type Description
item OO.EventEmitter

Requested item

Source:

Returns:

Index of the item

Type
number
Get the index of a specific item.

getItems() → {Array.<OO.EventEmitter>} #

Get all items.

Source:

Returns:

Items in the list

Type
Array.<OO.EventEmitter>
Get all items.

insertItem(item, index) → {number}protected #

Utility method to insert an item into the list, and connect it to aggregate events.

Don't call this directly unless you know what you're doing. Use addItems() instead.

This method can be extended in child classes to produce different behavior when an item is inserted. For example, inserted items may also be attached to the DOM or may interact with some other nodes in certain ways. Extending this method is allowed, but if overridden, the aggregation of events must be preserved, or behavior of emitted events will be broken.

If you are extending this method, please make sure the parent method is called.

Parameters:

Name Type Description
item OO.EventEmitter | Object

Item to add

index number

Index to add items at

Source:

Returns:

The index the item was added at

Type
number

Utility method to insert an item into the list, and connect it to aggregate events.

isEmpty() → {boolean} #

Check if a list contains no items.

Source:

Returns:

Group is empty

Type
boolean
Check if a list contains no items.

moveItem(item, newIndex) → {number}private #

Move an item from its current position to a new index.

The item is expected to exist in the list. If it doesn't, the method will throw an exception.

Parameters:

Name Type Description
item OO.EventEmitter

Items to add

newIndex number

Index to move the item to

Source:

Returns:

The index the item was moved to

Type
number

Throws:

If item is not in the list

Type
Error
Move an item from its current position to a new index.

removeItems(items) → {OO.EmitterList} #

Remove items.

Parameters:

Name Type Description
items OO.EventEmitter | Array.<OO.EventEmitter>

Items to remove

Source:

Returns:

Type
OO.EmitterList

Fires:

Remove items.

Events

add(item, index) #

Item has been added.

Parameters:

Name Type Description
item OO.EventEmitter

Added item

index number

Index items were added at

Source:
Item has been added.

clear() #

The list has been cleared of items.

Source:
The list has been cleared of items.

move(item, index, oldIndex) #

Item has been moved to a new index.

Parameters:

Name Type Description
item OO.EventEmitter

Moved item

index number

Index item was moved to

oldIndex number

The original index the item was in

Source:
Item has been moved to a new index.

remove(item, index) #

Item has been removed.

Parameters:

Name Type Description
item OO.EventEmitter

Removed item

index number

Index the item was removed from

Source:
Item has been removed.