import { FieldAndValueParam, FieldOnlyParam, FieldPathArrayAndValue, ListenerFunction, ListenerParam, PathArray, PathArrayListenerParam, RemoveListenersType } from "../platform/services/config/types"; import { StandardCallback, StandardError, StandardErrorCallback, StandardPromise } from "../types"; import { IRouterClient } from "./routerClient"; export type DispatchListenerFunction = (any: any) => void; export type Mappings = Record; export type RemoveStoreCallback = (params: { store: string; global?: boolean; }, cb?: StandardErrorCallback) => StandardPromise; export declare class StoreModel { /** * @ignore */ routerClient: IRouterClient; /** * @ignore */ removeStoreCallback: RemoveStoreCallback; /** * @ignore */ isGlobal: boolean; /** * @ignore */ values: Record; /** * @ignore */ listeners: Record; /** * @ignore * @deprecated */ registeredDispatchListeners: DispatchListenerFunction[]; /** * @ignore */ mapping: Mappings; /** * Prevents multiple listener requests on the same field from being sent to the DistributedStoreService * @ignore */ subs: Record; /** * @ignore */ name: string; /** * @ignore */ constructor(params: { global?: boolean; name: string; values?: Record; }, routerClient: IRouterClient, removeStoreCallback: RemoveStoreCallback); /** This is the Flux dispatcher. It can be used dispatch actions across stores. These action are not caught inside of the global store service. For more information, you can read the [Flux documentation](https://facebook.github.io/flux/docs/overview.html). * * Example: * ``` * store.Dispatcher.register(function(action){ * if(action.actionType === "ACTION1") { * // Do something with the action here. * } * }) * ``` * @ignore */ Dispatcher: { register: (fn: (update: any) => void) => void; dispatch: (data: any) => void; }; /** * @param {*} err * @param {*} message * @ignore */ handleDispatchedMessages(err: StandardError, message?: { data: any; }): void; /** * @deprecated - Use [store.set](#set) instead * * Set a value in the store. Two events will be triggered with topics of: store and field. * * ```javascript * store.setValue({ field:'field1', value:"new value" }); * ``` * @param {String} params.field The name of the field where data will be stored * @param {String} params.value Value to be stored * @param {function} cb callback */ setValue(params: FieldAndValueParam, cb?: StandardErrorCallback): void; /** * Handles changes to the store. Will publish from the field that was changed and back. * * @private Do not call this function directly. It will be converted to private member in a future release * @ignore */ publishObjectUpdates(fieldPath: PathArray, mappings: Mappings): void; /** * Send items that are no longer mapped or had their map change. If a value is remapped we'll send out the new value. * * @private Do not call this function directly. It will be converted to private member in a future release * @ignore */ triggerMultipleListeners(removals: string[]): void; /** * This will set multiple values in the store. * * ```javascript * store.setValues([{ field:'field1', value:"new value" }]); * ``` * @param {function} cb callback * @param {Array<{ field : string, value : any}>} fields An array where each element is like the object below. */ setValues(fields: FieldAndValueParam[], cb?: StandardErrorCallback): void; /** * @deprecated - Use [store.get](#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. * * ```javascript * store.getValue({ field: 'field1' }, function(err,value){}); * store.getValue('field1', function(err,value){}); * ``` * @param {object|string} params The field where the value is stored. * @param {String} params.field The field where the value is stored. * @param {StandardCallback} cb 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 Don't use the return statement. Always use the cb. */ getValue(params: FieldOnlyParam | string, cb?: StandardErrorCallback): T | any; /** * Get the entire store. * * @param { Function} cb Will return the value if found * @returns object | void - The store in key/value form if it's a local store - otherwise void * @ignore */ getAll(cb: StandardErrorCallback>): any; /** * @deprecated - Use [store.getMultiple](#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 * * ```javascript * store.getValues([{ field:'field1' }, { field:'field2' }], function(err,values){}); * store.getValues(['field1', 'field2'], function(err,values){}); * ``` * @param {Array.|Array.} fields An Array of field objects. If there are no fields provided, or value is null, all values in the store are returned. * @param {string} fields.field The field where the value is stored. * @param {Function} [cb] Will return the value if found. * @returns {Object} - returns an object of with the fields as keys. If no callback is given and the value is local, this will run synchronous */ getValues(fields: FieldOnlyParam[] | string[], cb?: StandardErrorCallback): any; /** * @deprecated - Use [store.getGlobal](#getglobal) instead. * * Get a single value from a *global* store. * * @param {string} field The field to fetch * @param {(err, data) => void} [cb] Optional callback to receive value. `err` will be string if an error occurred. `data` will contain the returned value or be undefined. * @return {Promise<{err, data}} `err` will be string if an error occurred. `data` will contain the returned value or be undefined. */ getGlobalValue(field: string, cb?: StandardErrorCallback): StandardPromise; /** * Get a single value from a *global* store. * * @param {PathArray} path The field where the value is stored. If value is null or empty array the whole store values will be returned. * @param {(err, data) => void} [cb] Optional callback to receive value. `err` will be string if an error occurred. `data` will contain the returned value or be undefined. * @return {Promise<{err, data}} `err` will be string if an error occurred. `data` will contain the returned value or be undefined. */ getGlobal(path: PathArray | null, cb?: StandardErrorCallback): StandardPromise; /** * Get values from the global store. * * @private Do not call this function directly. It will be converted to private member in a future release * @ignore * * @deprecated - use store.getGlobalMultiple */ getGlobalValues(params: FieldOnlyParam[] | null | string[], cb?: StandardErrorCallback>): void; /** * Get multiple values from the *global* store. * * @param chains * @param cb */ private getGlobalMultiple; /** * @deprecated - Use [store.remove](#remove) instead. * * Remove a value from the store. * * ```javascript * store.removeValue({ field: 'field1' }, function(err,bool){}); * ``` * @param {Object | String} params - Either an object (`{ field: string }`) or string * @param {String} param.field The name of the field * @param {Function} cb returns an error if there is one */ removeValue(params: string | { field: string; }, cb?: StandardErrorCallback): void; /** * Removes multiple values from the store. * * ```javascript * store.removeValues([{ field: 'field1' }], function(err,bool){}); * ``` * @param {Object[] | String[]} params - An Array of field objects * @param {String} params.field - The name of the field * @param {Function} cb - returns an error if there is one. */ removeValues(params: string[] | FieldOnlyParam[], cb: any): any; /** * Destroys the store. * @param {Function} cb Function to be invoked after the store is destroyed. */ destroy(cb?: StandardErrorCallback): void; /** * Adds a subscription for the desired dynamic store changes * @ignore */ changeSub(change: string): 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). * * ```javascript * const myFunction = function(err,data) { ... } * * store.addListener({ field:'field1' }, myFunction, cb); * store.addListener(['field1', 'property1'], myFunction, cb); // field1.property1 * ``` * @param {{ field: string | null } | PathArray} params The piece of data that you want to listen on. If this is empty it listens to all changes of the store. * @param {ListenerFunction} fn the function to call when the data changes * @param {Function} cb callback to be invoked */ addListener(params: { field?: string | null; } | PathArray, fn: ListenerFunction, cb?: () => void): void; /** * Add an array of listeners as objects, strings or path arrays. * If using strings, you must provide a function callback. * * ```javascript * 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); * ``` * @param {listenerParam[] | string[] | PathArrayListenerParam[]} params.field The piece of data that you want listen on. If this is empty it listen to all changes of the store. * @param {ListenerFunction} params.listener The function to call when the piece of data is modified. If this is empty, fn is used. * @param {function} fn The function to call when the piece of data is modified. * @param {function} cb callback to be invoked when the listeners are added. */ addListeners(params: ListenerParam[] | string[] | PathArrayListenerParam[], fn: ListenerFunction, cb?: () => void): void; /** * Remove a listener from store. If no field is given, we look for a store listener * @param {String} params.field - The data field with the listener that you want to remove. * @param {function} fn The handler passed into `addListener` or `addListeners`. * @param {function} cb returns true if it was successful in removing the listener. * * ```javascript * var myFunction = function(err,data){} * store.removeListener({ field: 'field1' }, MyFunction, function(bool){}); * ``` */ removeListener(params: FieldOnlyParam | PathArray, fn: ListenerFunction, cb?: StandardErrorCallback): void; /** * Remove an array of listeners from the store * @param {String} params.field The data field with the listener that you want to remove. * @param {String} params.listener The handler passed into `addListener` or `addListeners`. * @param {function} fn The handler passed into `addListener` or `addListeners`. * @param {function} cb 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){}); * ``` */ removeListeners(params: RemoveListenersType, fn?: ListenerFunction, cb?: StandardErrorCallback): void; /** * Handles all changes coming in from the service. * @private Do not call this function directly. It will be converted to private member in a future release * @ignore */ handleChanges: (err: StandardError, response: { data: { store: string; storeData: any; field: string; value: any; }; }) => void; /** * Trigger any function that is listening for changes * @private Do not call this function directly. It will be converted to private member in a future release * @ignore */ triggerListeners(listenerKey: string, data: any): void; /** * 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. * * ```javascript * store.set(['field1', 'property1'], "new value"); // field1.property1 * ``` * @param {PathArray} path The path array that represents the field where data will be stored * @param {String} params.value The value to be stored * @param {function} cb callback */ set(path: PathArray, value: any, cb?: StandardErrorCallback): StandardPromise; /** * 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. * * ```javascript * 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 * ``` * @param {PathArray} path The path array that represents the field where data will be stored * @param {String} params.value The value to be stored * @param {function} cb callback */ setMultiple(pathsAndValues: FieldPathArrayAndValue[], cb?: StandardErrorCallback): StandardPromise; /** * Get a value from the store. * * ```javascript * store.get(['field1', 'property1'], function(err,value){}); * ``` * @param {PathArray} path The field where the value is stored. If value is null or empty array the whole store values will be returned. * @param {StandardCallback} cb Callback that will receive the value if found, undefined if not found or an error if the parameters to the call were not correct. * @return {Promise<{err, data}} `err` will be string if an error occurred. `data` will contain the returned value or be undefined. */ get(path: PathArray | null, cb?: StandardCallback): StandardPromise; /** * Gets multiple values from the store. * * ```javascript * store.get([['field1', 'property1'], ['field1', 'property2']], function(err,value){}); * ``` * @param {PathArray} path The field where the value is stored. * @param {StandardCallback} cb Callback that will receive the value if found, undefined if not found or an error if the parameters to the call were not correct. * @return {Promise<{err, data}} `err` will be string if an error occurred. `data` will contain the returned value or be undefined. */ getMultiple(paths: PathArray[], cb?: StandardCallback): StandardPromise; /** * 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. * * ```javascript * store.remove(['field1', 'property1'], function(err,bool){}); * ``` * @param {PathArray} path - An array of strings representing a object property path (field) * @param {Function} cb returns an error if there is one * @return {Promise<{err, data}} `err` will be string if an error occurred. `data` will contain the returned value or be undefined. */ remove(path: PathArray, cb?: StandardErrorCallback): StandardPromise; /** * Removes multiple values from the store. * * ```javascript * store.removeMultiple([['field1', 'property1'], ['field2', 'property2']], function(err,bool){}); * ``` * @param {PathArray} paths - An array of strings representing a object property path (field) * @param {Function} cb returns an error if there is one * @return {Promise<{err, data}} `err` will be string if an error occurred. `data` will contain the returned value or be undefined. */ removeMultiple(paths: PathArray[], cb?: StandardErrorCallback): StandardPromise; } export default StoreModel; //# sourceMappingURL=StoreModel.d.ts.map