import { StandardError, StandardErrorCallback, StandardPromise } from "../types"; import { IRouterClient } from "./routerClient"; export declare type ListenerFunction = (err: StandardError, response: { field: string; value: T; }) => void; export declare type DispatchListenerFunction = (any: any) => void; export declare type FieldOnlyParam = { field: string; }; export declare type ListenerParam = { field: string; listener: ListenerFunction; }; export declare type RemoveListenersType = ListenerParam | ListenerParam[]; export declare type Mappings = Record; export declare 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; /** * 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: { field: string; value: any; }, 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(startField: string, 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 */ sendRemovals(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: { field: string; value: any; }[], cb?: StandardErrorCallback): void; /** * 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 Will return the value if found. * @returns any Don't use the return statement. Always use the cb. */ getValue(params: { field: string; } | 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; /** * 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: { field: string; }[] | string[], cb?: StandardErrorCallback): any; /** * Get a single value from a *global* store. This function is promisifed. * * @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 values from the global store. * @private Do not call this function directly. It will be converted to private member in a future release * @ignore */ getGlobalValues(params: { field: string; }[] | string[] | null, cb?: StandardErrorCallback>): void; /** * 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[] | { field: string; }[], 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 * var myFunction = function(err,data) { * } * store.addListener({ field:'field1' }, myFunction, cb); * ``` * @param {String} params.field The piece of data that you want to listen on. If this is empty it listens to all changes of the store. * @param {Function} fn the function to call when the data changes * @param {Function} cb callback to be invoked */ addListener(params: { field?: string; }, fn: ListenerFunction, cb?: () => void): void; /** * Add an array of listeners as objects or strings. If using strings, you must provide a function callback. * * ```javascript * 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); * ``` * @param {String} params.field The piece of data that you want listen on. If this is empty it listen to all changes of the store. * @param {String} 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: { field: string; listener: ListenerFunction; } | { field: string; listener: ListenerFunction; }[] | string[], 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: { field?: string; }, 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; } export default StoreModel; //# sourceMappingURL=StoreModel.d.ts.map