Class: Collection

Collection


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:
Type
apy.components.Collection

<static> create()

Create all unsaved Resource(s)

Returns:

A single Promise chaining all created Resource(s)

Type
Promise

<static> createResource(payload)

Create an apy.components.Resource instance. Either based on given payload or an empty one.

Parameters:
Name Type Description
payload Object

optional Object representing the Resource

Returns:

The Created Resource instance

Type
apy.components.Resource

<static> deferredAll(promises)

Allow to group/chain Deferred/Promises altogether.

Parameters:
Name Type Description
promises Array

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
progressHandler function

A progress handler

Returns:

Asynchronous call

Type
Promise

<static> hasCreated()

Return unsaved Resource(s) count

Returns:

Has the Collection unsaved Resource(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
items Array

A list of Resource Objects


<static> remove(resource)

Remove a given Resource from the Collection

Parameters:
Name Type Description
resource apy.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 saved components from unsaved ones

Returns:

filtered Components

Type
Array

<static> savedCount()

Represents the count of saved Resource(s)

Returns:

saved Resource(s) count

Type
Integer

<static> selectAll()

Select all components (set the selected attribute)


<static> selectedComponents()

Filter selected components (resources)

Returns:

selected Components

Type
Array

<static> selectedOrSaved()

Return the selected components if any or saved Resource(s)

Returns:

selected or saved Resource(s)

Type
Array

<static> setState(state)

Set given state to all saved Resource(s)

Parameters:
Name Type Description
state string

State amongst {CREATE, READ, UPDATE, DELETE}

Returns:
Type
apy.components.Collection

<static> toggleSelect()

toggle-select all components (set the selected attribute)


<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 unsaved components from saved ones

Returns:

filtered Components

Type
Array

<static> unselectAll()

Unselect all components (set the selected attribute)


<static> update()

Update all saved Resource(s)

Returns:

A single Promise chaining all updated Resource(s)

Type
Promise

delete()

Delete all saved Resource(s)

Returns:

A single Promise chaining all deleted Resource(s)

Type
Promise