Class: StoreModel
Methods
-
addListener(params, fn, cb)
-
Add a listener to the store at either the store or field level. If no field is given, the store level is used. You can also listen to nested object (e.g., field1.nestedField).
Name Type Description paramsName Type Description fieldoptional The piece of data that you want to listen on. If this is empty it listens to all changes of the store.
fnListenerFunction cbundefined | Type Literal optional callback to be invoked
Name Type Description N/AType Literal Example
var myFunction = function(err,data) { } store.addListener({ field:'field1' }, myFunction, cb); -
addListeners(params, fn, cb)
-
Add an array of listeners as objects or strings. If using strings, you must provide a function callback.
Name Type Description paramsType Literal | Type Literal[] | string[] Name Type Description N/AType Literal Name Type Description fieldstring The piece of data that you want listen on. If this is empty it listen to all changes of the store.
listenerfn The function to call when the piece of data is modified. If this is empty, fn is used.
N/AType Literal[] Name Type Description fieldstring The piece of data that you want listen on. If this is empty it listen to all changes of the store.
listenerfn The function to call when the piece of data is modified. If this is empty, fn is used.
fnListenerFunction cbundefined | Type Literal optional callback to be invoked when the listeners are added.
Name Type Description N/AType Literal Example
var myFunction = function(err,data){ } store.addListeners([{ field: 'field1', listener: myFunction }, { field:'field2', listener: myFunction }], null, cb); store.addListeners([{ field: 'field1' },{ field: 'field2', listener: myFunction }], myFunction, cb); store.addListeners(['field1','field2'], myFunction, cb); -
destroy(cb)
-
Destroys the store.
Name Type Description cbStandardErrorCallback optional Function to be invoked after the store is destroyed.
Example
store.destroy(); -
getGlobalValue(field, cb)
-
Get a single value from a *global* store. This function is promisifed.
Name Type Description fieldstring The field to fetch
cbStandardErrorCallback optional -
getValue(params, cb)
-
Get a value from the store. If global is not set, we'll check local first then we'll check global. Returns the value of the field. If no callback is given and the value is local, this will run synchronously.
Be very careful not to `await` this function as it is not promisified. Use `await getGlobalValue` instead.
Name Type Description paramsType Literal | string The field where the value is stored.
Name Type Description N/AType Literal Name Type Description fieldstring The field where the value is stored.
cbStandardErrorCallback optional Will return the value if found.
Example
store.getValue({ field: 'field1' }, function(err,value){}); store.getValue('field1', function(err,value){}); -
getValues(fields, cb)
-
Get multiple values from the store. Returns an object of with the fields as keys.If no callback is given and the value is local, this will run synchronously. Returns an object of with the fields as keys.If no callback is given and the value is local, this will run synchronous
Name Type Description fieldsType Literal[] | string[] An Array of field objects. If there are no fields provided, or value is null, all values in the store are returned.
Name Type Description N/AType Literal[] Name Type Description fieldstring The field where the value is stored.
cbStandardErrorCallback optional Example
store.getValues([{ field:'field1' }, { field:'field2' }], function(err,values){}); store.getValues(['field1', 'field2'], function(err,values){}); -
removeListener(params, fn, cb)
-
Remove a listener from store. If no field is given, we look for a store listener
Name Type Description paramsName Type Description fieldoptional The data field with the listener that you want to remove.
fnListenerFunction cbStandardErrorCallback optional returns true if it was successful in removing the listener.
Example
var myFunction = function(err,data){} store.removeListener({ field: 'field1' }, MyFunction, function(bool){}); -
removeListeners(params, fn, cb)
-
Remove an array of listeners from the store
Name Type Description paramsListenerParam | ListenerParam[] Name Type Description ListenerParamName Type Description fieldstring listenerfn fnListenerFunction cbStandardErrorCallback optional returns true if it was successful in removing the listener.
Example
var myFunction = function(err,data){} store.removeListeners({ field: 'field1' }, MyFunction, function(bool){}); store.removeListeners([{ field: 'field1', listener: MyFunction}], function(bool){}); store.removeListeners(['field1'], MyFunction, function(bool){}); -
removeValue(params, cb)
-
Remove a value from the store.
Name Type Description paramsstring | Type Literal Either an object (`{ field: string }`) or string
Name Type Description N/AType Literal Name Type Description fieldstring cbStandardErrorCallback optional returns an error if there is one
Example
store.removeValue({ field: 'field1' }, function(err,bool){}); -
removeValues(params, cb)
-
Removes multiple values from the store.
Name Type Description paramsstring[] | Type Literal[] An Array of field objects
Name Type Description N/AType Literal[] Name Type Description fieldstring The name of the field
cbany returns an error if there is one.
Example
store.removeValues([{ field: 'field1' }], function(err,bool){}); -
setValue(params, cb)
-
Set a value in the store. Two events will be triggered with topics of: store and field.
Name Type Description paramsName Type Description fieldstring The name of the field where data will be stored
valueany Value to be stored
cbStandardErrorCallback optional callback
Example
store.setValue({ field:'field1', value:"new value" }); -
setValues(fields, cb)
-
This will set multiple values in the store.
Name Type Description fieldscbStandardErrorCallback optional callback
Example
store.setValues([{ field:'field1', value:"new value" }]);