Class: 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
Name | Type | Description |
---|---|---|
params | Object | - |
params.field? | string | The piece of data that you want to listen on. If this is empty it listens to all changes of the store. |
fn | ListenerFunction <any > | the function to call when the data changes |
cb? | () => void | callback 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
Name | Type | Description |
---|---|---|
params | string [] | { field : string ; listener : ListenerFunction <any > } | { field : string ; listener : ListenerFunction <any > }[] | - |
fn | ListenerFunction <any > | The function to call when the piece of data is modified. |
cb? | () => void | callback to be invoked when the listeners are added. |
Returns
void
destroy
▸ destroy(cb?
): void
Destroys the store.
Parameters
Name | Type | Description |
---|---|---|
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
Name | Type |
---|---|
T | any |
Parameters
Name | Type | Description |
---|---|---|
field | string | The field to fetch |
cb? | StandardErrorCallback <T > | - |
Returns
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
Name | Type |
---|---|
T | any |
Parameters
Name | Type | Description |
---|---|---|
params | string | { 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
Name | Type | Description |
---|---|---|
fields | string [] | { 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
Name | Type | Description |
---|---|---|
params | Object | - |
params.field? | string | The data field with the listener that you want to remove. |
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.removeListener({ field: 'field1' }, MyFunction, function(bool){}); |
Returns
void
removeListeners
▸ removeListeners(params
, fn?
, cb?
): void
Remove an array of listeners from the store
Parameters
Name | Type | Description |
---|---|---|
params | RemoveListenersType | - |
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
Name | Type | Description |
---|---|---|
params | string | { 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
Name | Type | Description |
---|---|---|
params | string [] | { field : string }[] | An Array of field objects |
cb | any | returns 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
Name | Type | Description |
---|---|---|
params | Object | - |
params.field | string | The name of the field where data will be stored |
params.value | any | Value 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
Name | Type | Description |
---|---|---|
fields | { field : string ; value : any }[] | - |
cb? | StandardErrorCallback <void > | callback |
Returns
void