new NameValueStore()
Base class for interacting with a name/value store.
This base class saves to local storage, but you can create your own function overrides for remote storage as long as you maintain the same function signatures and callback requirements.
See WebComponents.cq-views for an implementation example.
Methods
-
get(field, cb)
-
Retrieves a value from the name/value store.
Parameters:
Name Type Description fieldstring The field for which the value is retrieved.
cbCIQ.NameValueStore~getCallback A callback function called after the retrieval operation has been completed. Two arguments are provided to the callback function. The first argument indicates the success or failure of the operation; the second argument is the value returned by the operation.
- Since:
-
8.2.0 Made
cba required parameter; changed its type to CIQ.NameValueStore~getCallback.
Example
nameValueStore.get("myfield", function (err, data) { if (err) { // Do something with the error. } else { // Do something with the retrieved data. } }); -
remove(field [, cb])
-
Removes a field from the name/value store.
Parameters:
Name Type Argument Description fieldstring The field to remove.
cbCIQ.NameValueStore~updateCallback <optional>
A callback function called after the storage operation has been completed. A single argument, which indicates success or failure of the operation, is provided to the callback function.
- Since:
-
8.2.0 Changed the type of the
cbparameter to CIQ.NameValueStore~updateCallback.
Example
nameValueStore.remove("myfield", function (err) { if (err) { // Do something with the error. } else { // Do something after the field has been removed. } }); -
set(field, value [, cb])
-
Stores a value in the name/value store.
Parameters:
Name Type Argument Description fieldstring The name under which the value is stored.
valuestring | object The value to store.
cbCIQ.NameValueStore~updateCallback <optional>
A callback function called after the storage operation has been completed. A single argument, which indicates success or failure of the operation, is provided to the callback function.
- Since:
-
8.2.0 Changed the type of the
cbparameter to CIQ.NameValueStore~updateCallback.
Example
nameValueStore.set("myfield", "myValue", function (err) { if (err) { // Do something with the error. } else { // Do something after the data has been stored. } });
Type Definitions
-
getCallback(error, response)
-
A function called after a retrieval operation on the name/value store has been completed.
Parameters:
Name Type Description errorobject | string An error object or error code if data retrieval failed; null if data retrieval was successful.
responseobject | string The data retrieved from storage or null if retrieval failed.
- Since:
-
8.2.0
-
updateCallback(error)
-
A function called after an update of the name/value store has been completed.
Parameters:
Name Type Description errorobject | string An error object or error code if the storage update failed; null if the update was successful.
- Since:
-
8.2.0
