The Store class is a utility class for storing information such as settings. The Store can store hierarchical data.
Type:Object
get/set
The store options.
Type:Object
get/set
The object that contains a copy of all items in the store. The copy is created using clone() method.
Type:Function
get/set
The merge function to be used in the merge() method. By default, BitmistJS's deep merge utility function is used.
Both the merge source object and target object are passed to this merge function. Return the merged object from the merge function.
merger(targetObject, sourceObject); // merge sourceObject into targetObject
Parameter | Type | Description |
---|---|---|
options | Object | The object to initialize the Store. Has the following keys: |
“items” | Object | The items object to initialize a Store. |
“merger” | Function | The merge function object. |
Type:Undefined
Removes all items from the Store.
None.
Undefined.
Type:Object
Returns the deep copy of items this store holds.
None.
The deep copy of stored items.
Type:*
Returns the value specified by the key parameter. Returns the default value if the key doesn't exist. The value will be deep copied if the value is an array or object.
You can use a period-separated string to specify a hierarchy. The below example returns the value of store[“settings”][“name”] from the store.
store.get("settings.name");
No exception is thrown even if any of the intermediate levels of the hierarchy do not exist. In the above example, it returns Undefined if “settings” does not exist, without an error.
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.
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.
Parameter | Type | Description |
---|---|---|
newItems Required | Object/ Array of objects | The object to merge or 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. |
Undefined.
Type:Undefined
Removes the item that has the specified key.
Parameter | Type | Description |
---|---|---|
key Required | String | The key to remove. |
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 item already exists in the store, the value will be overwritten by the new value.
You can use a period-separated string to specify a hierarchy. The below example sets the value to store[“settings”][“name”].
store.set("settings.name", "BarHeader");
If the intermediate hierarchies do not exist, they will be created automatically. In the above example, if “settings” does not exist, the hierarchy “settings” is automatically created. However, if the intermediate hierarchy already exists and is not an object, an error will be thrown. For example, if the above code is executed on a Store object with content {“settings”: “value”}, the “settings ” hierarchy cannot be created and it causes an error.
Parameter | Type | Description |
---|---|---|
key Required | String | The key to set the value. |
value Required | * | The value to set. |
Undefined.