Adds items to the ModelCollection.
The items to add to the ModelCollection.
Removes all items from the ModelCollection.
The name of the event to fire.
Optional arguments to pass to subscribers.
Returns false
if the bus is stopped. Otherwise,
returns a Promise that will resolve with an array of values returned by
event subscribers, or reject with the first Promise rejection or thrown error.
The set of items in the ModelCollection.
NOTE: Returns a shallow copy of the underlying collection. That means the array returned can be mutated without affecting the real ModelCollection, but all the items in the array are the same by reference, so mutating an object in the collection will also mutate the object stored in the ModelCollection.
Registers a subscriber for the given event. The subscriber will be invoked in the context used to create the EventBus and passed any arguments provided to the fire method.
The name of the event to listen for.
The subscriber to invoke when the event is fired.
Method to invoke to remove the subscriber.
Similar to on, except the subscriber will be removed as soon as it is invoked.
The name of the event to listen for.
The subscriber to invoke when the event is fired.
Method to invoke to remove the subscriber.
Removes items from the ModelCollection.
The items to remove from the ModelCollection.
Resumes notifying subscribers after stop was called. Any events fired before resuming are dropped entirely.
Gets or sets the currently selected items within the list. NOTE: Only currently available items can be selected. For example, if you are using {@link module:models.withFiltering withFiltering} then items which have been filtered out can not be selected.
The items to select. Must be present in the current list. To retrieve the currently selected items, do not pass any arguments.
The currently selected items.
Stops notifying subscribers of fired events until resume is called.
Select all, none, or some of the ModelCollection items, depending on which are currently selected and which are passed as arguments.
When called with no arguments, the behavior of toggle changes depending on whether none, some, or all items are currently selected:
call | condition | result |
---|---|---|
toggle() |
selected() == [] | select all items |
toggle() |
selected() != items() | select all items |
toggle() |
selected() == items() | select no items |
When passed items, only those items' selection status will be toggled. None of the previously selected items' selection status will change:
list.selected(); // [1, 2, 3]
list.toggle(2); // [1, 3]
list.toggle(2); // [1, 2, 3]
The items to select or deselect. Must be present in the current list. To select or deselect all items, pass no arguments.
The currently selected items.
Tracks which items within the wrapped ModelCollection instance are selected at any given time. NOTE: Items which are not available through the wrapped ModelCollection can not be selected.
{@link Events.REMOVED}
{@link Events.FILTER_CHANGED}