Class: Collection

Collection

new Collection()

Base model that represents multiple objects.
Properties:
Name Type Description
length number Number of known items in the instance
$busy boolean If instance is currently in the middle of an API call, equals `true`; else `false`
$loaded boolean If instance has been loaded or instantiated with data, equals `true`; else `false`
$selected array Array of selected items
$selectedCount number Count of items that are currently selected
$allSelected boolean If all known items in the instance are selected, equals `true`; else `false`
$noneSelected boolean If none of the items in the instance are selected, equals `true`; else `false`
$type string The type of model the instance is
Source:

Extends

Members

childModel :Singleton

The model to use when retrieving child objects.
Type:
Source:

(abstract) readService

Service to read (GET) the data for this instance. Services should return `false` if they are currently invalid.
Source:

(abstract) updateService

Service to update (PUT) the data for this instance. Services should return `false` if they are currently invalid.
Source:

Methods

add(val) → {ChildModel|Collection|array}

Creates one or more linked ChildModels, but does not add them into the current data.
Parameters:
Name Type Description
val undefined | null | ChildModel | object | Collection | array The pending data to set on the instance
Source:
Returns:
`val`
Type
ChildModel | Collection | array

bind(type, cb) → {Base}

Attaches a listener to an event type.
Parameters:
Name Type Description
type String The type of event to listen for
cb function The function to trigger every time the event type occurs
Inherited From:
Source:
Returns:
`this`
Type
Base

clone() → {Base}

Method to clone the instance.
Overrides:
Source:
Fires:
Returns:
`new this.constructor(null, true)`
Type
Base

fail(failopt) → {Base}

Attaches fail callback to the current promise thread.
Parameters:
Name Type Attributes Description
fail Base~failCallback <optional>
Inherited From:
Source:
Returns:
`this`
Type
Base

get() → {Array.<ChildModel>}

Method to retrieve all the current data for the instance.
Source:
Returns:
Type
Array.<ChildModel>

init(dataopt, forCloneopt) → {Base}

Initialization method. Called automatically when a new instance is instantiated.
Parameters:
Name Type Attributes Default Description
data <optional>
Initial data to populate the instance with
forClone Boolean <optional>
false Whether this instance is being created as a clone or not
Overrides:
Source:
Returns:
`this`
Type
Base

isFinal(idxopt) → {Boolean}

Indicates whether the instance has been finalized (resolved or rejected)
Parameters:
Name Type Attributes Default Description
idx number <optional>
this.$$cbQueueIdx Thread index to check
Inherited From:
Source:
Returns:
Type
Boolean

notify(idxopt, dataopt) → {Base}

Triggers a progress step for the provided promise thread.
Parameters:
Name Type Attributes Default Description
idx <optional>
this.$$cbQueueIdx Promise thread to notify of progress
data <optional>
Data related to the progress step
Inherited From:
Source:
Fires:
Returns:
`this`
Type
Base

one(type, cb) → {Base}

Attaches a one-time listener to an event type. After triggering once, the listener will automtically be unbound.
Parameters:
Name Type Description
type String The type of event to listen for
cb function The function to trigger the next time the event type occurs
Inherited From:
Source:
Returns:
`this`
Type
Base

pluck() → {Array.<Object>}

Method to retrieve specific fields from all the current data for the instance.
Source:
Returns:
Type
Array.<Object>

progress(progressopt) → {Base}

Attaches a progress callback to the current promise thread.
Parameters:
Name Type Attributes Description
progress Base~progressCallback <optional>
Inherited From:
Source:
Returns:
`this`
Type
Base

read(dataopt) → {Collection}

Uses the readService (if defined) to attempt to retrieve the data for the instance. Will finalize the instance.
Parameters:
Name Type Attributes Description
data <optional>
Data to be provided to the readService
Source:
Returns:
`this`
Type
Collection

refresh() → {Collection}

Re-runs the last `read` call or, if never called, calls `read`.
Source:
Returns:
`this`
Type
Collection

reject(idxopt, dataopt) → {Base}

Marks the promise thread as "rejected" (unsuccessfully complete).
Parameters:
Name Type Attributes Default Description
idx <optional>
this.$$cbQueueIdx Promise thread to reject
data <optional>
Data related to the rejection
Overrides:
Source:
Fires:
Returns:
`this`
Type
Base

resolve(idxopt, dataopt) → {Base}

Marks the promie thread as "resolved" (successfully complete).
Parameters:
Name Type Attributes Default Description
idx <optional>
this.$$cbQueueIdx Promise thread to resolve
data <optional>
Data related to the resolution
Overrides:
Source:
Fires:
Returns:
`this`
Type
Base

set(val) → {Collection}

Method to set the data for the instance. Also sets `this.$loaded = true`. Will re-apply any sorting/filtering after setting the data.
Parameters:
Name Type Description
val array The data to set on the instance
Source:
Returns:
`this`
Type
Collection

success(successopt) → {Base}

Attaches success callback to the current promise thread.
Parameters:
Name Type Attributes Description
success Base~successCallback <optional>
Inherited From:
Source:
Returns:
`this`
Type
Base

trigger(type, dataopt) → {Boolean}

Triggers an event of the given type, passing any listeners the data provided.
Parameters:
Name Type Attributes Description
type String The type of event to trigger
data <optional>
Object to pass into any listeners
Inherited From:
Source:
Returns:
Returns `true` if all listeners return true, else `false`
Type
Boolean

unbind(type, listeneropt) → {Base}

Detaches either all listeners or just a single listener from an event type.
Parameters:
Name Type Attributes Description
type String The type of event to unbind
listener function <optional>
The specific listener to unbind from the event type. If not provided, all listeners bound to the event type will be removed
Inherited From:
Source:
Returns:
`this`
Type
Base

unfinalize() → {number}

"Resets" the Promise state on the instance by incrementing the current promise thread index.
Inherited From:
Source:
Fires:
Returns:
`idx` New promise thread index
Type
number

update(dataopt) → {Collection}

Uses the updateService (if defined) to attempt to update the current data for the instance. Will finalize the instance upon success.
Parameters:
Name Type Attributes Description
data <optional>
Data to be provided to the updateService
Source:
Returns:
`this`
Type
Collection

Type Definitions

eachCB(data, index)

Callback for Collection.each.
This:
Parameters:
Name Type Description
data The child object
index number Index position of the child in the current data for the instance
Source:

failCallback(data)

Fail callback passed into a service.
Parameters:
Name Type Description
data The data resulting from an erroring service call
Source:

mapCB(data, index)

Callback for Collection.map.
This:
Parameters:
Name Type Description
data The child object
index number Index position of the child in the current data for the instance.
Source:

successCallback(data)

Success callback passed into a service.
Parameters:
Name Type Description
data The data resulting from a sucessful service call
Source:

Events

cloned

Event that triggers when the source model is cloned
Properties:
Name Type Description
clone Base The new instance that was created as a result of the clone
Inherited From:
Source:

finalized

Event that triggers when the model is finalized (resolved or rejected)
Inherited From:
Source:

notified

Event that triggers when the model is notified (progress is recorded)
Inherited From:
Source:

rejected

Event that triggers when the model is rejected (generally when a data load fails)
Inherited From:
Source:

resolved

Event that triggers when the model is resolved (generally when data is loaded succesfully)
Inherited From:
Source:

unfinalized

Event that triggers when the model is unfinalized (reset back to being neither resolved nor rejected)
Inherited From:
Source: