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 params
Name Type Description field
optional The piece of data that you want to listen on. If this is empty it listens to all changes of the store.
fn
ListenerFunction cb
undefined | Type Literal optional callback to be invoked
Name Type Description N/A
Type 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 params
Type Literal | Type Literal[] | string[] Name Type Description N/A
Type Literal Name Type Description field
string The piece of data that you want listen on. If this is empty it listen to all changes of the store.
listener
fn The function to call when the piece of data is modified. If this is empty, fn is used.
N/A
Type Literal[] Name Type Description field
string The piece of data that you want listen on. If this is empty it listen to all changes of the store.
listener
fn The function to call when the piece of data is modified. If this is empty, fn is used.
fn
ListenerFunction cb
undefined | Type Literal optional callback to be invoked when the listeners are added.
Name Type Description N/A
Type 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 cb
StandardErrorCallback 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 field
string The field to fetch
cb
StandardErrorCallback 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 params
Type Literal | string The field where the value is stored.
Name Type Description N/A
Type Literal Name Type Description field
string The field where the value is stored.
cb
StandardErrorCallback 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 fields
Type 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/A
Type Literal[] Name Type Description field
string The field where the value is stored.
cb
StandardErrorCallback 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 params
Name Type Description field
optional The data field with the listener that you want to remove.
fn
ListenerFunction cb
StandardErrorCallback 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 params
ListenerParam | ListenerParam[] Name Type Description ListenerParam
Name Type Description field
string listener
fn fn
ListenerFunction cb
StandardErrorCallback 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 params
string | Type Literal Either an object (`{ field: string }`) or string
Name Type Description N/A
Type Literal Name Type Description field
string cb
StandardErrorCallback 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 params
string[] | Type Literal[] An Array of field objects
Name Type Description N/A
Type Literal[] Name Type Description field
string The name of the field
cb
any 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 params
Name Type Description field
string The name of the field where data will be stored
value
any Value to be stored
cb
StandardErrorCallback optional callback
Example
store.setValue({ field:'field1', value:"new value" });
-
setValues(fields, cb)
-
This will set multiple values in the store.
Name Type Description fields
cb
StandardErrorCallback optional callback
Example
store.setValues([{ field:'field1', value:"new value" }]);