Properties

โ—๏ธinfo

Here useful properties of the Collection are listed.

agileInstance#

Agile Instance to which the Collection belongs

MY_STATE.agileInstance(); // Returns a Agile Instance

Note that it is stored as a function in the Collection, to avoid endless deep classes.

key#

Current key/name of the Collection. It is used to uniquely identify the Collection. Besides getting the key, we can also assign a new key with help of this property.

MY_COLLECTION.key = "myCoolCollection";
MY_COLLECTION.key; // Returns 'myCoolCollection'

size#

How many Items are stored in the Collection right now.

MY_COLLECTION.collect({id: 1, name: "jeff"});
MY_COLLECTION.collect({id: 5, name: "frank"});
MY_COLLECTION.size; // Returns 2

Be aware that placeholder Items doesn't get counted.

data#

All Items of the Collection are stored here.

MY_COLLECTION.collect({id: 1, name: "jeff"});
MY_COLLECTION.collect({id: 5, name: "frank"});
MY_COLLECTION.data; // Returns (see below)
// {
// 1: Item({id: 1, name: "jeff"}),
// 5: Item({id: 5, name: "frank"})
// }

We recommend using the getAllItems function to get assess to all Items,

MY_COLLECTION.getAllItems(); // Returns (see below)
// [
// Item({id: 1, name: "jeff"}),
// Item({id: 5, name: "frank"})
// ]

or the default Group.

MY_COLLECTION.getGroup(MY_COLLECTION.config.defaultGroupKey).items; // Returns (see below)
// [
// Item({id: 1, name: "jeff"}),
// Item({id: 5, name: "frank"})
// ]

Because the data property isn't thought to be used in the outer world.

isPersisted#

If the State Value got successfully persisted into an external Storage like the Local Storage.

MY_COLLECTION.isPersisted; // Returns false
MY_COLLECTION.persist();
MY_COLLECTION.isPersisted; // Returns true (if the persisting was successfull)

groups#

Here all Groups of the Collection are stored.

MY_COLLECTION.createGroup("group1", [1, 2, 3]);
MY_COLLECTION.createGroup("group2", [1, 7, 4]);
MY_COLLECTION.groups; // Returns (see below)
// {
// group1: Group([1, 2, 3]),
// group2: Group([1, 7, 4])
// }

If we want to get access to one specific Group, we should use

MY_COLLECTION.getGroup("group1");

instead of

MY_COLLECTION.groups["group1"]

selectors#

Here all Selectors of the Collection are stored.

MY_COLLECTION.createGroup("selector1", 1);
MY_COLLECTION.createGroup("selector2", 7);
MY_COLLECTION.groups; // Returns (see below)
// {
// selector1: Selector(1),
// selector2: Selector(7)
// }

If we want to get access to one specific Selector, we should use

MY_COLLECTION.getSelector("selector1");

instead of

MY_COLLECTION.selectors["selector1"]
Last updated on