PrioritisedArray
Extends:
Direct Subclass:
An array of two-way bound data Models that are automatically synced with the currently used DataSource
Constructor Summary
Public Constructor | ||
public |
constructor(dataType: Function, dataSource: DataSource, dataSnapshot: Snapshot, options: Object, modelOptions: Object): PrioritisedArray |
Member Summary
Public Members | ||
public get |
The number of items in the (synchronized or local) data set. |
|
public set |
A setter on the length is necessary because internal methods of Array modify the lngth. |
Method Summary
Public Methods | ||
public |
Adds a model instance to the rear of the PrioritisedArray, and emits a 'child_added' and possibly 'new_child' event after successful addition. |
|
public |
Finds an item based on its Id in the datasource. |
|
public |
Inserts a model instance at the given position of the PrioritisedArray, and recalculates the priority (position) of all models after the inserted position. |
|
public |
Removes subscription to events emitted by this PrioritisedArray. |
|
public |
Subscribes to events emitted by this PrioritisedArray. |
|
public |
Subscribes to the given event type exactly once; it automatically unsubscribes after the first time it is triggered. |
|
public |
Adds a model or object to the end of the list. |
|
public |
Removes the model instance at the given position. |
Public Constructors
public constructor(dataType: Function, dataSource: DataSource, dataSnapshot: Snapshot, options: Object, modelOptions: Object): PrioritisedArray source
Params:
Name | Type | Attribute | Description |
dataType | Function | DataType of the models being added to the PrioritisedArray. |
|
dataSource | DataSource |
|
dataSource to load the models from. If none is given, a new DataSource is made with a path guessed from the model's DataType name. |
dataSnapshot | Snapshot |
|
snapshot already containing model data. Prevents initial subscription on all values in the DataSource. |
options | Object |
|
options to pass to the dataSource if none is provided and a new one is constructed. |
modelOptions | Object |
|
options to merge into the construction of every new Model. |
Public Members
Public Methods
public add(model: Model | Object, prevSiblingId: String): Object source
Adds a model instance to the rear of the PrioritisedArray, and emits a 'child_added' and possibly 'new_child' event after successful addition.
public findById(id: *): Model source
Finds an item based on its Id in the datasource.
Params:
Name | Type | Attribute | Description |
id | * |
public insertAt(model: Model, position: Number): Object source
Inserts a model instance at the given position of the PrioritisedArray, and recalculates the priority (position) of all models after the inserted position.
public off(event: String, handler: Function, context: Object): void source
Removes subscription to events emitted by this PrioritisedArray. If no handler or context is given, all handlers for the given event are removed. If no parameters are given at all, all event types will have their handlers removed.
Return:
void |
public on(event: String, handler: Function, context: Object): void source
Subscribes to events emitted by this PrioritisedArray.
Params:
Name | Type | Attribute | Description |
event | String | One of the following Event Types: 'value', 'child_changed', 'child_moved', 'child_removed'. |
|
handler | Function | Function that is called when the given event type is emitted. |
|
context | Object | Optional: context of 'this' inside the handler function when it is called. |
Return:
void |
public once(event: String, handler: Function, context: Object): Promise source
Subscribes to the given event type exactly once; it automatically unsubscribes after the first time it is triggered.
Params:
Name | Type | Attribute | Description |
event | String | One of the following Event Types: 'value', 'child_changed', 'child_moved', 'child_removed'. |
|
handler | Function |
|
Function that is called when the given event type is emitted. |
context | Object |
|
context of 'this' inside the handler function when it is called. |
Return:
Promise | If no callback function provided, a promise that resolves once the event has happened |
public remove(position: Number): void source
Removes the model instance at the given position. Does not remove the model from the datasource, to do that call model.remove() directly, or PrioArray[index].remove().
Params:
Name | Type | Attribute | Description |
position | Number | Index in the PrioritisedArray of the model to remove. |
Return:
void |