CollectionInstance
A Collection Instance
- CollectionInstance
- .id :
string - .instanceId :
string - .value :
Array.<DataTypeInput> - .keys :
Array.<string> - .groups :
Record.<string, GroupInstance> - .groupsValue :
Record.<GroupNames, Array.<DataTypeInput>> - .selectors :
Record.<SelectorNames, PlexusCollectionSelector> - .selectorsValue :
Record.<SelectorNames, Array.<DataTypeInput>> - .name :
string - .lastUpdatedKey :
string - .collect(data, groups) ⇒
this - .update(key, data, config)
- .has(dataKey, includeProvisional) ⇒
boolean - .getItem(dataKey) ⇒
this - .getItemValue(key) ⇒
DataTypeInput - .createSelector(selectorName, defaultPk) ⇒
this - .createSelectors(selectorNames) ⇒
this - .getSelector(name) ⇒
this|undefined - .createGroup(groupName, config) ⇒
this - .createGroups(groupNamesThe) ⇒
this - .getGroup(name) ⇒
this - .getGroupsOf(key) ⇒
Array.<string> - .addToGroups(key, groups) ⇒
this - .watchGroup(name, callback) ⇒
function - .delete(keys) ⇒
this - .removeFromGroup(keys, groups) ⇒
this - .clear(groupNames) ⇒
this - .compute(fn) ⇒
this - .reCompute(ids) ⇒
this - .reComputeGroups(groupNames) ⇒
this - .key(key) ⇒
this
- .id :
.id : string
The internal ID of the collection
.instanceId : string
The internal id of the collection with an instance prefix
.value : Array.<DataTypeInput>
Get all of the collection data values as an array
.keys : Array.<string>
Get all of the collection data keys as an array
.groups : Record.<string, GroupInstance>
Get all the groups in the collection as an object
.groupsValue : Record.<GroupNames, Array.<DataTypeInput>>
Get all the groups and their children's data values as an object
.selectors : Record.<SelectorNames, PlexusCollectionSelector>
Get all the selectors in the collection as an object
.selectorsValue : Record.<SelectorNames, Array.<DataTypeInput>>
Get all the groups and their children's data values as an object
.name : string
Get the name (generated or custom) of the collection store
.lastUpdatedKey : string
Get the last updated key of the collection
.collect(data, groups) ⇒ this
Collect An item of data (or many items of data using an array) into the collection.
Returns: this
The collection instance
Requires:: Each data item must have the primary key as a property
| Param | Type | Description |
|---|---|---|
| data | Array.<DataTypeInput> | DataTypeInput | The data to collect |
| groups | string | Array.<string> | The groups to add the items to |
.update(key, data, config)
Update the collection with data; This is like collect but will not add new items, and can can be used to patch existing items
| Param | Type | Description |
|---|---|---|
| key | string | number | The key of the item to update |
| data | DataTypeInput | The data to update the item with |
| config | The configuration to use for the update | |
| config.deep | boolean | Should the update be deep or shallow |
.has(dataKey, includeProvisional) ⇒ boolean
Check if the collection has a data item with the given key
Returns: boolean
Whether the collection has a data item with the given key
| Param | Type | Description |
|---|---|---|
| dataKey | string | The key of the data item to look for |
| includeProvisional | boolean | Whether to include provisional data items in the search. This may be useful if you are using a collection to store data that is not yet available |
.getItem(dataKey) ⇒ this
Get the Value of the data item with the provided key (the raw data). If there is not an existing data item, this will return a provisional one
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| dataKey | string | The key of the data item to get |
.getItemValue(key) ⇒ DataTypeInput
Get the value of an item in the collection
Returns: DataTypeInput
The value of the item
| Param | Type | Description |
|---|---|---|
| key | string | The key of the item to get |
.createSelector(selectorName, defaultPk) ⇒ this
Create a Selector instance for a given selector name
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| selectorName | string | The name of the selector |
| defaultPk | string | The default primaryKey to select |
.createSelectors(selectorNames) ⇒ this
Create Selector instances for a given set of selector names
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| selectorNames | Array.<string> | The names of the selectors to create |
.getSelector(name) ⇒ this | undefined
Get A Selector instance of a given selector name
Returns: this | undefined
Either a Selector Instance or undefined
| Param | Type | Description |
|---|---|---|
| name | string | The Selector Name to search for |
.createGroup(groupName, config) ⇒ this
Create a group with a name and a configuration
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| groupName | string | The name of the group |
| config | PlexusCollectionGroupConfig |
.createGroups(groupNamesThe) ⇒ this
Create multiple groups with a name (no configuration)
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| groupNamesThe | Array.<string> | names of the groups to create |
.getGroup(name) ⇒ this
Get A Group instance of a given group name
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| name | string | The Group Name to search for |
.getGroupsOf(key) ⇒ Array.<string>
Given a key, get all Group names that the key is in
Returns: Array.<string>
An array of Group names that the key is in
| Param | Type | Description |
|---|---|---|
| key | string | number | The data key(s) to use for lookup |
.addToGroups(key, groups) ⇒ this
Add a data item to a group or groups
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| key | string | The key of the item to add |
| groups | Array.<string> | string | The group(s) to add the item to |
.watchGroup(name, callback) ⇒ function
A shortcut to watch a group for changes
Returns: function
A function to stop watching the group
| Param | Description |
|---|---|
| name | The name of the group you are watching |
| callback | The callback to run when the group data changes |
.delete(keys) ⇒ this
Delete a data item completely from the collection.
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| keys | string | The data key(s) to use for lookup |
.removeFromGroup(keys, groups) ⇒ this
Remove a data item from a set of groups
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| keys | string | Array.<string> | The data key(s) to use for lookup |
| groups | Array.<string> | string | Either a single group or an array of groups to remove the data from |
.clear(groupNames) ⇒ this
Delete all data in the collection
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| groupNames | string | (Optional) Either an array or a single group name to clear data from |
.compute(fn) ⇒ this
Run this function when data is collected to format it in a particular way; useful for converting one datatype into another
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| fn | function | A function that takes in the data and returns the formatted data |
.reCompute(ids) ⇒ this
Re-runs the compute function on select IDs (or all the collection if none provided)
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| ids | Array.<string> | Array.<Number> | The data key(s) to use for lookup |
.reComputeGroups(groupNames) ⇒ this
Same as reCompute, but for groups
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| groupNames | Array.<string> | string | The data key(s) to use for lookup |
.key(key) ⇒ this
Set the key of the collection for enhanced internal tracking
Returns: this
The new Collection Instance
| Param | Type | Description |
|---|---|---|
| key | string | The key to use for the collection |