Class: StoreModel

Store Model

The Store Model consists of store instances. It handles getters/setters of data.

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 -- field1.nestedField

Name Type Description
params any

Params object

fn any

the function to call when a listener is triggered

cb any

callback

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 any

Params object

fn any
cb any

callback

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

Will return the value if found.

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.

Name Type Description
params

Params object. This can also be a string

cb StandardCallback

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.

Name Type Description
fields

An Array of field objects. If there are no fields proviced, all values in the store are returned.

cb any

Will return the value if found.

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 any

Params object

fn any
cb any

returns true if it was succesfull in removing the listener.

Example
var myFunction = function(err,data){
}
store.removeListener({field:'field1'},MyFunction,function(bool){});
StoreCstorelient.removeListener(MyFunction,function(bool){});

removeListeners
(params, fn, cb)

Remove an array of listeners from the store

Name Type Description
params any

Params object

fn any
cb any

returns true if it was succesfull 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 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 any

An Array of field objects

cb any

returns an error if there is one.

Example
store.removeValue({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

Params object

Name Type Description
field string

The name of the field where data will be stored

value any

Value to be stored

cb StandardCallback

callback

Example
store.setValue({field:'field1',value:"new value"});

setValues
(fields, cb)

This will set multiple values in the store.

Name Type Description
fields

An Array of field objects

cb StandardCallback optional

callback

Example
store.setValues([{field:'field1',value:"new value"}]);