new Collection(name, service, endpoint, components)
A Collection of Resource(s)
Parameters:
| Name | Type | Description |
|---|---|---|
name |
string | Resource endpoint name |
service |
apy.CompositeService | Service instance |
endpoint |
string | REST API endpoint base |
components |
Array | (optional) initial components |
Example
var service = new apy.CompositeService(...);
var collection = new apy.components.Collection('myResourceName', service, 'myEndpoint');
function error(e) {
console.log('Error', e);
}
function success() {
console.log('Fetched Data', arguments);
}
function progress() {
console.log('Progress', arguments);
}
collection.fetch(progress)
.then(success)
.catch(error);
Extends
Methods
-
<static> clear()
-
Clear all Collection's components (Resources)
Returns:
-
<static> create()
-
Create all
unsavedResource(s)Returns:
A single Promise chaining all created Resource(s)
- Type
- Promise
-
<static> createResource(payload)
-
Create an
apy.components.Resourceinstance. Either based on given payload or an empty one.Parameters:
Name Type Description payloadObject optional Object representing the Resource
Returns:
The Created Resource instance
-
<static> deferredAll(promises)
-
Allow to group/chain Deferred/Promises altogether.
Parameters:
Name Type Description promisesArray A list of Promise instances
Returns:
A single Promise chaining given ones
- Type
- Promise
-
<static> fetch(progressHandler)
-
Fetch all Resource Objects based on config parameters
Parameters:
Name Type Description progressHandlerfunction A progress handler
Returns:
Asynchronous call
- Type
- Promise
-
<static> hasCreated()
-
Return
unsavedResource(s) countReturns:
Has the Collection
unsavedResource(s) ?- Type
- boolean
-
<static> hasUpdated()
-
Return true if at least one inner Resource is updated
Returns:
Is the Collection updated ?
- Type
- boolean
-
<static> isState()
-
Factorize logic Return whether or not at least one Collection's component's current state is in the given state
Returns:
Has Collection some of this state ?
- Type
- boolean
-
<static> load(items)
-
Load given Resource Objects into the Collection (recursively)
Parameters:
Name Type Description itemsArray A list of Resource Objects
-
<static> remove(resource)
-
Remove a given Resource from the Collection
Parameters:
Name Type Description resourceapy.components.Resource The Resource instance to remove
Returns:
- Type
- Array.<T>
-
<static> reset()
-
Reset all inner Collection's components
-
<static> save()
-
Shortcut to create & save all components (according to their state)
Returns:
A single Promise
- Type
- Promise
-
<static> savedComponents()
-
Filter
savedcomponents fromunsavedonesReturns:
filtered Components
- Type
- Array
-
<static> savedCount()
-
Represents the count of
savedResource(s)Returns:
savedResource(s) count- Type
- Integer
-
<static> selectAll()
-
Select all components (set the
selectedattribute) -
<static> selectedComponents()
-
Filter
selectedcomponents (resources)Returns:
selected Components
- Type
- Array
-
<static> selectedOrSaved()
-
Return the selected components if any or saved Resource(s)
Returns:
selectedorsavedResource(s)- Type
- Array
-
<static> setState(state)
-
Set given state to all
savedResource(s)Parameters:
Name Type Description statestring State amongst {CREATE, READ, UPDATE, DELETE}
Returns:
-
<static> toggleSelect()
-
toggle-select all components (set the
selectedattribute) -
<static> toString()
-
Define how Collection is represented. A Collection joins all its inner components calling their
toString()method.Returns:
The Collection representation as a String
- Type
- string
-
<static> unsavedComponents()
-
Filter
unsavedcomponents fromsavedonesReturns:
filtered Components
- Type
- Array
-
<static> unselectAll()
-
Unselect all components (set the
selectedattribute) -
<static> update()
-
Update all
savedResource(s)Returns:
A single Promise chaining all updated Resource(s)
- Type
- Promise
-
delete()
-
Delete all
savedResource(s)Returns:
A single Promise chaining all deleted Resource(s)
- Type
- Promise