Class: StoreModel

Store Model

The store model is the store instances. This handles getters/setters of data

Members

DispatcherObject

This is the flux dispatcher. It can be used dispatch actions accross stores. These action are not caught inside of the global store service. https://facebook.github.io/flux/docs/overview.html

Example
store.Dispatcher.register(function(action){
		if(action.actionType === "ACTION1"){

		// Do something with the action here
		}


	});

	store.Dispatcher.dispatch({actionType:ACTION1,data:myData});

Methods

addListener
(params, fn, cb)

clients/StoreModel.js, line 278

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 Object

Params object

Name Type Description
field String optional

The data field to listen for. If this is empty it listen to all changes of the store.

fn function

the function to call when a listener is triggered

cb function optional

callback

Example
var myFunction = function(err,data){
	}
store.addListener({field:'field1'},myFunction,cb);

addListeners
(params, fn)

clients/StoreModel.js, line 315

Add an array of listeners as objects or strings. If using strings, you must provide a function callback.

Name Type Description
params Array.<Object> | Array.<String>

Params object

params[].field String

The data field to listen for.

params[].listener String

the function to call when a listener is triggered. If this is empty, fn is used.

fn function optional

the function to call when a listener is triggered

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)

clients/StoreModel.js, line 254

Destroys the store.

Name Type Description
cb function optional

Will return the value if found.

Example
store.destroy();

getValue
(params, cb){Any}

clients/StoreModel.js, line 117

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 Object | String

Params object. This can also be a string

Name Type Description
field String

The field where the value is stored.

cb function optional

Will return the value if found.

Returns:
Type Description
Any
  • The value of the field. If no callback is given and the value is local, this will run synchronous
Example
store.getValue({field:'field1'},function(err,value){});
store.getValue('field1',function(err,value){});

getValues
(fields, cb){Object}

clients/StoreModel.js, line 144

Get multiple values from the store.

Name Type Description
fields Array.<Object> | Array.<String>

An Array of field objects

fields[].field String

The name of the field

cb function optional

Will return the value if found.

Returns:
Type Description
Object
  • returns an object of with the fields as keys.If no callback is given and the value is local, this will run synchronous
Example
store.getValues([{field:'field1'},{field2:'field2'}],function(err,values){});
store.getValues(['field1','field2'],function(err,values){});

removeListener
(params, fn, cb)

clients/StoreModel.js, line 362

Remove a listener from store. If no field is given, we look for a store listener

Name Type Description
params Object

Params object

Name Type Description
field String optional

The data field

fn function optional

the function to remove from the listeners

cb function optional

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)

clients/StoreModel.js, line 399

Remove an array of listeners from the store

Name Type Description
params Array.<Object> | Array.<String>

Params object

params[].field String

The data field to listen for. If this is empty it listen to all changes of the store.

params[].listener String

The listener function

fn function optional

the function to remove from the listeners

cb function optional

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){Boolean}

clients/StoreModel.js, line 204

Remove a value from the store.

Name Type Description
params Object | String

Either an object or string

param.field String

The name of the field

cb function optional

Will return the value if found.

Returns:
Type Description
Boolean
  • returns true if succeeds.
Example
store.removeValue({field:'field1'},function(err,bool){});

removeValues
(params, cb){Boolean}

clients/StoreModel.js, line 241

Removes multiple values from the store.

Name Type Description
params Array.<Object> | Array.<String>

An Array of field objects

param[].field String

The name of the field

cb function optional

Will return the value if found.

Returns:
Type Description
Boolean
  • returns true if succeeds.
Example
store.removeValue({field:'field1'},function(err,bool){});

setValue
(params){null}

clients/StoreModel.js, line 63

Set a value in the store. Two events will be triggered with topics of: store and field.

Name Type Description
params Object

Params object

Name Type Description
field String

The name of the field where data will be stored

value String

Value to be stored

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

setValues
(fields){null}

clients/StoreModel.js, line 91

This will set multiple values in the store.

Name Type Description
fields Array.<Object>

An Array of field objects

fields[].field String

The name of the field

fields[].value Any

Field value

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