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
string optional The piece of data that you want to listen on. If this is empty it listens to all changes of the store.
fn
any the function to call when the data changes
cb
any callback to be invoked
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
Function 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
Function The function to call when the piece of data is modified. If this is empty, fn is used.
fn
any optional The function to call when the piece of data is modified.
cb
any optional callback to be invoked when the listeners are added.
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
any Function to be invoked after the store is destroyed.
Example
store.destroy();
-
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.
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
StandardCallback The callback to be invoked if the method fails.
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
any 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
optional Name Type Description field
string optional The data field with the listener that you want to remove.
fn
any optional The handler passed into `addListener` or `addListeners`.
cb
any optional returns true if it was successful in removing the listener.
Example
var myFunction = function(err,data){} store.removeListener({ field: 'field1' }, MyFunction, function(bool){}); store.removeListener(MyFunction, function(bool){});
-
removeListeners(params, fn, cb)
-
Remove an array of listeners from the store
Name Type Description params
any fn
any The handler passed into `addListener` or `addListeners`.
cb
any 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
any Either an object (`{ field: string }`) or string
cb
any 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
StandardCallback The callback to be invoked if the method fails.
Example
store.setValue({ field:'field1', value:"new value" });
-
setValues(fields, cb)
-
This will set multiple values in the store.
Name Type Description fields
setValuesParam[] An array where each element is like the object below.
cb
StandardCallback The callback to be invoked if the method fails.
Example
store.setValues([{ field:'field1', value:"new value" }]);