Skip to main content

Class: StoreModel

main.types.StoreModel

Methods

addListener

addListener(params, fn, cb?): void

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).

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

Parameters

NameTypeDescription
paramsObject-
params.field?stringThe piece of data that you want to listen on. If this is empty it listens to all changes of the store.
fnListenerFunction<any>the function to call when the data changes
cb?() => voidcallback to be invoked

Returns

void


addListeners

addListeners(params, fn, cb?): void

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

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);

Parameters

NameTypeDescription
paramsstring[] | { field: string ; listener: ListenerFunction<any> } | { field: string ; listener: ListenerFunction<any> }[]-
fnListenerFunction<any>The function to call when the piece of data is modified.
cb?() => voidcallback to be invoked when the listeners are added.

Returns

void


destroy

destroy(cb?): void

Destroys the store.

Parameters

NameTypeDescription
cb?StandardErrorCallback<boolean>Function to be invoked after the store is destroyed.

Returns

void


getGlobalValue

getGlobalValue<T>(field, cb?): StandardPromise<T>

Get a single value from a global store. This function is promisifed.

Type parameters

NameType
Tany

Parameters

NameTypeDescription
fieldstringThe field to fetch
cb?StandardErrorCallback<T>-

Returns

StandardPromise<T>

err will be string if an error occurred. data will contain the returned value or be undefined.


getValue

getValue<T>(params, cb?): any

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.

store.getValue({ field: 'field1' }, function(err,value){});
store.getValue('field1', function(err,value){});

Type parameters

NameType
Tany

Parameters

NameTypeDescription
paramsstring | { field: string }The field where the value is stored.
cb?StandardErrorCallback<T>Will return the value if found.

Returns

any

any Don't use the return statement. Always use the cb.


getValues

getValues(fields, cb?): any

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

store.getValues([{ field:'field1' }, { field:'field2' }], function(err,values){});
store.getValues(['field1', 'field2'], function(err,values){});

Parameters

NameTypeDescription
fieldsstring[] | { field: string }[]An Array of field objects. If there are no fields provided, or value is null, all values in the store are returned.
cb?StandardErrorCallback<any>-

Returns

any

  • returns an object of with the fields as keys.If no callback is given and the value is local, this will run synchronous

removeListener

removeListener(params, fn, cb?): void

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

Parameters

NameTypeDescription
paramsObject-
params.field?stringThe data field with the listener that you want to remove.
fnListenerFunction<any>The handler passed into addListener or addListeners.
cb?StandardErrorCallback<boolean>returns true if it was successful in removing the listener. javascript var myFunction = function(err,data){} store.removeListener({ field: 'field1' }, MyFunction, function(bool){});

Returns

void


removeListeners

removeListeners(params, fn?, cb?): void

Remove an array of listeners from the store

Parameters

NameTypeDescription
paramsRemoveListenersType-
fn?ListenerFunction<any>The handler passed into addListener or addListeners.
cb?StandardErrorCallback<boolean>returns true if it was successful in removing the listener. javascript 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){});

Returns

void


removeValue

removeValue(params, cb?): void

Remove a value from the store.

store.removeValue({ field: 'field1' }, function(err,bool){});

Parameters

NameTypeDescription
paramsstring | { field: string }Either an object ({ field: string }) or string
cb?StandardErrorCallback<void>returns an error if there is one

Returns

void


removeValues

removeValues(params, cb): any

Removes multiple values from the store.

store.removeValues([{ field: 'field1' }], function(err,bool){});

Parameters

NameTypeDescription
paramsstring[] | { field: string }[]An Array of field objects
cbanyreturns an error if there is one.

Returns

any


setValue

setValue(params, cb?): void

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

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

Parameters

NameTypeDescription
paramsObject-
params.fieldstringThe name of the field where data will be stored
params.valueanyValue to be stored
cb?StandardErrorCallback<void>callback

Returns

void


setValues

setValues(fields, cb?): void

This will set multiple values in the store.

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

Parameters

NameTypeDescription
fields{ field: string ; value: any }[]-
cb?StandardErrorCallback<void>callback

Returns

void