new Base()
Base model that all other models will inherit from. Provides Promises/A functionality as well as publish/subscribe functionality.
Properties:
Name | Type | Description |
---|---|---|
$errors |
Object | Contains details about any error states on the instance |
Methods
(static) extend(properties) → {function}
Allows for model extension
Parameters:
Name | Type | Description |
---|---|---|
properties |
Object | Properties to extend the new model with. Methods may call `this._super.apply(this, arguments)` to call parent model methods that are overwritten. |
Returns:
New constructor
- Type
- function
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 |
Returns:
`this`
- Type
- Base
clone() → {Base}
Method to clone the instance.
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> |
Returns:
`this`
- Type
- Base
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 |
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 |
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 |
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 |
Returns:
`this`
- Type
- Base
progress(progressopt) → {Base}
Attaches a progress callback to the current promise thread.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
progress |
Base~progressCallback |
<optional> |
Returns:
`this`
- Type
- Base
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 |
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 |
Fires:
Returns:
`this`
- Type
- Base
success(successopt) → {Base}
Attaches success callback to the current promise thread.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
success |
Base~successCallback |
<optional> |
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 |
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 |
Returns:
`this`
- Type
- Base
unfinalize() → {number}
"Resets" the Promise state on the instance by incrementing the current promise thread index.
Fires:
Returns:
`idx` New promise thread index
- Type
- number
Type Definitions
alwaysCallback()
Always callback will be triggered when/if the current promise thread is finalized (either resolved OR rejected).
failCallback()
Fail callback will be triggered when/if the current promise thread is rejected.
progressCallback()
Progress callback will be triggered as the current promise thread passes through various states of progress.
successCallback()
Success callback will be triggered when/if the current promise thread is resolved.
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 |
finalized
Event that triggers when the model is finalized (resolved or rejected)
notified
Event that triggers when the model is notified (progress is recorded)
rejected
Event that triggers when the model is rejected (generally when a data load fails)
resolved
Event that triggers when the model is resolved (generally when data is loaded succesfully)
unfinalized
Event that triggers when the model is unfinalized (reset back to being neither resolved nor rejected)