new Singleton()
Base model that represents a single object.
Properties:
Name | Type | Default | Description |
---|---|---|---|
$dirty |
boolean | false | If instance has been modified since initilization or the last save, equals `true`; else `false` |
$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` | |
$type |
string | The type of model the instance is |
- Source:
Extends
Members
(abstract) changeService
Service to change (PATCH) the data for this instance. Services should return `false` if they are currently invalid.
- Source:
(abstract) createService
Service to create (POST) data for this instance. Services should return `false` if they are currently invalid.
- Source:
(abstract) deleteService
Service to remove (DELETE) this instance. Services should return `false` if they are currently invalid.
- 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:
(abstract) uploadService
Service to upload data for this instance. Services should return `false` if they are currently invalid.
- Source:
Methods
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
cancel() → {Singleton}
Clears any pending data that may exist.
- Source:
Returns:
`this`
- Type
- Singleton
change(dataopt) → {Singleton}
Uses the changeService (if defined) to attempt to change the data for the instance. Will finalize the instance upon success.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
data |
<optional> |
this.$$setData | Data to be provided to the changeService. Defaults to an object contining all the fields who's value has changed and who's "updateable" config is not false |
- Source:
Returns:
`this`
- Type
- Singleton
clearCache() → {Singleton}
Clears any instance and field cache that is currently present.
- Source:
Returns:
`this`
- Type
- Singleton
clone()
Clones $$setData and other properties.
- Overrides:
- Source:
create(dataopt) → {Singleton}
Uses the createService (if defined) to attempt to create data for the instance. Will finalize the instance.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
<optional> |
Data to be provided to the createService. Defaults to an object contining all the fields who's "createable" config is not false |
- Source:
Returns:
`this`
- Type
- Singleton
delete(dataopt) → {Singleton}
Uses the deleteService (if defined) to attempt to create data for the instance. Will finalize the instance.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
<optional> |
Data to be provided to the deleteService |
- Source:
Returns:
`this`
- Type
- Singleton
fail(failopt) → {Base}
Attaches fail callback to the current promise thread.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
fail |
Base~failCallback |
<optional> |
Returns:
`this`
- Type
- Base
finalize(dataopt) → {Singleton}
Merges the current and pending data (or sets the current data and removes the pending data).
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
object |
<optional> |
If provided, is used as the finalized data. If not, `this.get()` is used |
- Source:
Returns:
`this`
- Type
- Singleton
get() → {object}
Method to retrieve all the current and pending data ($$data extended by $$setData) for the instance.
- Source:
Returns:
- Type
- object
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 |
- 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 |
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> |
- Inherited From:
- Source:
Returns:
`this`
- Type
- Base
read(dataopt) → {Singleton}
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
- Singleton
refresh() → {Singleton}
Re-runs the last `read` call or, if never called, calls `read`.
- Source:
Returns:
`this`
- Type
- Singleton
reject()
Sets `this.$loaded = true`, deletes `this.$busy`, and clears any instance cache that may exist.
- Overrides:
- Source:
resolve()
Sets `this.$loaded = true`, deletes `this.$busy`, and clears any instance cache that may exist.
- Overrides:
- Source:
set(val) → {Singleton}
Method to set the pending data ($$setData) for the instance. Also sets `this.$loaded = true`.
Parameters:
Name | Type | Description |
---|---|---|
val |
object | The pending data to set on the instance |
- Source:
Returns:
`this`
- Type
- Singleton
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) → {Singleton}
Uses the updateService (if defined) to attempt to update the data for the instance. Will finalize the instance upon success.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
<optional> |
Data to be provided to the updateService. Defaults to an object contining all the fields who's "updateable" config is not false |
- Source:
Returns:
`this`
- Type
- Singleton
upload(dataopt) → {Singleton}
Uses the uploadService (if defined) to attempt to upload data for the instance. Will finalize the instance.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
data |
<optional> |
Data to be provided to the uploadService |
- Source:
Returns:
`this`
- Type
- Singleton
validate() → {boolean}
Validates each field and returns whether the model is valid or not.
- Source:
Returns:
- Type
- boolean
Type Definitions
eachCB(fieldConfig)
Callback for Singleton.each.
This:
Parameters:
Name | Type | Description |
---|---|---|
fieldConfig |
FieldConfig |
- Source:
failCallback(data)
Fail callback passed into a service.
Parameters:
Name | Type | Description |
---|---|---|
data |
The data resulting from an erroring service call |
- Source:
pickCB(fieldConfig)
Callback for Singleton.pick.
This:
Parameters:
Name | Type | Description | ||||||
---|---|---|---|---|---|---|---|---|
fieldConfig |
FieldConfig |
Properties
|
- 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: