Skip to main content

CollectionInstance

view on npm

A Collection Instance

.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

.size : number

Get the size of the collection (the number of data items in 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

ParamTypeDescription
dataArray.<DataTypeInput> | DataTypeInput

The data to collect

groupsstring | 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

ParamTypeDescription
keystring | number

The key of the item to update

dataDataTypeInput

The data to update the item with

config

The configuration to use for the update

config.deepboolean

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

ParamTypeDescription
dataKeystring

The key of the data item to look for

includeProvisionalboolean

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

ParamTypeDescription
dataKeystring

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

ParamTypeDescription
keystring

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

ParamTypeDescription
selectorNamestring

The name of the selector

defaultPkstring

The default primaryKey to select

.createSelectors(selectorNames) ⇒ this

Create Selector instances for a given set of selector names

Returns: this

The new Collection Instance

ParamTypeDescription
selectorNamesArray.<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

ParamTypeDescription
namestring

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

ParamTypeDescription
groupNamestring

The name of the group

configPlexusCollectionGroupConfig

.createGroups(groupNamesThe) ⇒ this

Create multiple groups with a name (no configuration)

Returns: this

The new Collection Instance

ParamTypeDescription
groupNamesTheArray.<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

ParamTypeDescription
namestring

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

ParamTypeDescription
keystring | 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

ParamTypeDescription
keystring

The key of the item to add

groupsArray.<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

ParamDescription
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

ParamTypeDescription
keysstring

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

ParamTypeDescription
keysstring | Array.<string>

The data key(s) to use for lookup

groupsArray.<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

ParamTypeDescription
groupNamesstring

(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

ParamTypeDescription
fnfunction

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

ParamTypeDescription
idsArray.<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

ParamTypeDescription
groupNamesArray.<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

ParamTypeDescription
keystring

The key to use for the collection