(abstract) new EmitterList()
Contain and manage a list of @{link OO.EventEmitter} items.
Aggregates and manages their events collectively.
This mixin must be used in a class that also mixes in @{link OO.EventEmitter}.
- Source:
Methods
addItems(items, indexopt) → {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:
Fires:
Returns:
- Type
- OO.EmitterList
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.<string, (string|null)> | 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 |
- Source:
Throws:
-
If aggregation already exists
- Type
- Error
clearItems() → {OO.EmitterList}
getItemCount() → {number}
Get number of items.
- Source:
Returns:
Number of items in the list
- Type
- number
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
getItems() → {Array.<OO.EventEmitter>}
(protected) insertItem(item, index) → {number}
Utility method to insert an item into the list, and connect it to aggregate events.
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
isEmpty() → {boolean}
Check if a list contains no items.
- Source:
Returns:
Group is empty
- Type
- boolean
(private) moveItem(item, newIndex) → {number}
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:
Throws:
-
If item is not in the list
- Type
- Error
Returns:
The index the item was moved to
- Type
- number
removeItems(items) → {OO.EmitterList}
Remove items.
Parameters:
Name | Type | Description |
---|---|---|
items |
Array.<OO.EventEmitter> | Items to remove |
- Source:
Fires:
Returns:
- Type
- OO.EmitterList
Events
add
Item has been added.
Parameters:
Name | Type | Description |
---|---|---|
item |
OO.EventEmitter | Added item |
index |
number | Index items were added at |
- Source:
clear
The list has been cleared of items.
- Source:
move
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:
remove
Item has been removed.
Parameters:
Name | Type | Description |
---|---|---|
item |
OO.EventEmitter | Removed item |
index |
number | Index the item was removed from |
- Source: