Inherits:Store
The ChainableStore is a class that inherits the Store class. The ChainableStore can be chained to another ChainableStore object. When chained, it tries to retrieve the item from the chained Store object if the requested item does not exist in its own store.
On this page, only the difference from the parent class is explained.
Type:Object
get/set
The object that contains a copy of all items in both stores. The copy is created using clone() method. The stored items in its own store are initialized to the passed values when set.
Type:Object
get
The object that contains items in its own store. It doesn't contain items in the chained store.
Parameter | Type | Description |
---|---|---|
options | Object | The options to initialize the Store. Has the following keys in addition to the keys available to the parent class: |
“chain” | Store | The store object to chain. |
“writeThrough” | Boolean | If true, then it modifies the chained store when set()/merge() instead of itself. |
Type:Undefined
Chains to another ChainableStore object. Only one ChainableStore can be chained. If you call chain() several times, it is overwritten by the latter one.
Parameter | Type | Description |
---|---|---|
store Required | ChainableStore | A ChainableStore object to chain. |
Undefined.
Type:Object
Returns the deep copy of stored items. When the store is chained to another store, it clones both the locally stored items and chained items and then merges them using BitmistJS's deep merge utility function.
None.
The deep copy of items in both stores.
Type:*
Returns the value specified by the key parameter.
It tries to retrieve the item from the chained store object if the item requested does not exist in its own store. If the item exists in both store and mergeable, both items are cloned and merged using BitmistJS's deep merge utility function.
If the item doesn't exist in both stores, the default value is returned.
Parameter | Type | Description |
---|---|---|
key Required | String | The key to be retrieved. |
defaultValue | * | The default value to be returned when the key doesn't exist. |
The value specified by the key. When the key is not found, returns defaultValue, or undefined if defaultValue is missing.
Type:Boolean
Returns if the specified key exists.
It tries to retrieve the item from the chained store object if the item requested does not exist in its own store.
Parameter | Type | Description |
---|---|---|
key Required | String | The key to check. |
True if the key exists, false if it doesn't exist.
Type:Undefined
Merges new items into current items.
If the store is chained to another store, by default it merges with its own store items. If “writeThrough” option is true in either the constructor option or the option parameter, it merges with items in the chained store.
Parameter | Type | Description |
---|---|---|
value Required | Object/ Array of objects | An object to merge or an array of objects. If the newItems parameter is an array, all objects in the array will be merged in order. |
merger | Function | The function for merging objects. This parameter has a higher priority than merger property. |
options | Object | The options. Has the following keys: |
“writeThrough” | Boolean | If True, then it sets the value to the chained store. |
Undefined.
Type:Undefined
Sets the value to an item specified by the key parameter. If the key does not exist, it will be automatically created.
If the store is chained to another store, by default it sets the item to its own store. If “writeThrough” option is true in either the constructor option or the option parameter, it sets the item to the chained store.
Parameter | Type | Description |
---|---|---|
key Required | String | The key to set the value. |
value Required | * | The value to set. |
options | Object | The options. Has the following keys: |
“writeThrough” | Boolean | If True, then it sets the value to te chained store. |
Undefined.