Skip to main content

Class: StoreModel

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

const myFunction = function(err,data) { ... }

store.addListener({ field:'field1' }, myFunction, cb);
store.addListener(['field1', 'property1'], myFunction, cb); // field1.property1

Parameters​

NameTypeDescription
paramsPathArray | { field?: null | string }-
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, strings or path arrays. If using strings, you must provide a function callback.

const myFunction = function(err,data){ ... }
const fallbackListenerFn = function(err,data){ ... } // listener function used by field2
store.addListeners([{
field: 'field1',
listener: myFunction
},
{
field:'field2'
}],
fallbackListenerFn, cb);

store.addListeners([{ field: 'field1' },{ field: 'field2', listener: myFunction }], myFunction, cb);
store.addListeners(['field1','field2'], myFunction, cb);

Parameters​

NameTypeDescription
paramsstring[] | ListenerParam[] | PathArrayListenerParam[]-
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


get​

▸ get<T>(path, cb?): StandardPromise<T>

Get a value from the store.

store.get(['field1', 'property1'], function(err,value){});

Type parameters​

NameType
Tany

Parameters​

NameTypeDescription
pathnull | PathArrayThe field where the value is stored. If value is null or empty array the whole store values will be returned.
cb?StandardCallback<StandardError, any>Callback that will receive the value if found, undefined if not found or an error if the parameters to the call were not correct.

Returns​

StandardPromise<T>

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


getGlobal​

▸ getGlobal<T>(path, cb?): StandardPromise<T>

Get a single value from a global store.

Type parameters​

NameType
Tany

Parameters​

NameTypeDescription
pathnull | PathArrayThe field where the value is stored. If value is null or empty array the whole store values will be returned.
cb?StandardErrorCallback<T>-

Returns​

StandardPromise<T>

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


getGlobalMultiple​

▸ Private getGlobalMultiple(chains, cb?): Promise<StandardQueryResponse<any>>

Get multiple values from the global store.

Parameters​

NameType
chainsnull | PathArray[]
cb?StandardErrorCallback<Record<string, any>>

Returns​

Promise<StandardQueryResponse<any>>


getGlobalValue​

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

deprecated - Use store.getGlobal instead.

Get a single value from a global store.

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.


getMultiple​

▸ getMultiple<T>(paths, cb?): StandardPromise<T>

Gets multiple values from the store.

store.get([['field1', 'property1'], ['field1', 'property2']], function(err,value){});

Type parameters​

NameType
Tany

Parameters​

NameTypeDescription
pathsPathArray[]-
cb?StandardCallback<StandardError, any>Callback that will receive the value if found, undefined if not found or an error if the parameters to the call were not correct.

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

deprecated - Use store.get instead.

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 | FieldOnlyParamThe field where the value is stored.
cb?StandardErrorCallback<T>Callback that will receive the value if found, null if not found or an error if the parameters to the call were not correct.

Returns​

any

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


getValues​

▸ getValues(fields, cb?): any

deprecated - Use store.getMultiple instead.

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[] | FieldOnlyParam[]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

remove​

▸ remove(path, cb?): StandardPromise<any>

Remove a value from the store.

When a value is removed from the store, it also generates events according to mappings - lower-level fields that are modified, and higher-level objects containing this one.

store.remove(['field1', 'property1'], function(err,bool){});

Parameters​

NameTypeDescription
pathPathArrayAn array of strings representing a object property path (field)
cb?StandardErrorCallback<any>returns an error if there is one

Returns​

StandardPromise<any>

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


removeListener​

▸ removeListener(params, fn, cb?): void

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

Parameters​

NameTypeDescription
paramsPathArray | FieldOnlyParam-
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


removeMultiple​

▸ removeMultiple(paths, cb?): StandardPromise<any>

Removes multiple values from the store.

store.removeMultiple([['field1', 'property1'], ['field2', 'property2']], function(err,bool){});

Parameters​

NameTypeDescription
pathsPathArray[]An array of strings representing a object property path (field)
cb?StandardErrorCallback<any>returns an error if there is one

Returns​

StandardPromise<any>

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


removeValue​

▸ removeValue(params, cb?): void

deprecated - Use store.remove instead.

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[] | FieldOnlyParam[]An Array of field objects
cbanyreturns an error if there is one.

Returns​

any


set​

▸ set(path, value, cb?): StandardPromise<any>

Set a value in the store.

When a value is set in the store, it also generates events according to mappings - lower-level fields that are modified, and higher-level objects containing this one.

store.set(['field1', 'property1'], "new value"); // field1.property1

Parameters​

NameTypeDescription
pathPathArrayThe path array that represents the field where data will be stored
valueany-
cb?StandardErrorCallback<any>callback

Returns​

StandardPromise<any>


setMultiple​

▸ setMultiple(pathsAndValues, cb?): StandardPromise<any>

Sets multiple values in the store.

When a value is set in the store, it also generates events according to mappings - lower-level fields that are modified, and higher-level objects containing this one.

store.set([
{field: ['field1', 'property1'], value: "new value 1"},
{field: ['field2', 'property2'], value: "new value 2"}]); // field1.property1: new value 1 AND field2.property2: new value 2

Parameters​

NameTypeDescription
pathsAndValuesFieldPathArrayAndValue[]-
cb?StandardErrorCallback<any>callback

Returns​

StandardPromise<any>


setValue​

▸ setValue(params, cb?): void

deprecated - Use store.set instead

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
paramsFieldAndValueParam-
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
fieldsFieldAndValueParam[]-
cb?StandardErrorCallback<void>callback

Returns​

void