import { AnyAction, Reducer } from 'redux'; import { ForkEffect } from 'redux-saga/effects'; import { Observable } from 'rxjs'; /** * Base structure of each store state section * * @export * @interface IStoreFetchableDataState * @template REQ * @template RES */ export interface IStoreFetchableDataState { readonly isFetching: boolean; readonly request: REQ | null; readonly chainStarter: string; readonly response: RES | null; readonly error: Error | null; } /** * Dispatch action payload which helps with dispatch tracking and promise * style usage * * @export * @interface IStoreFetchActionPayload * @template REQ The action request type * @template RES The action response type */ export interface IStoreFetchActionPayload { request: REQ; dispatchId?: string; fetchResolve?: any; fetchReject?: any; chainResolve?: any; chainReject?: any; chainStarter: string; timeout?: number; elevationToken?: string; serviceContext?: string; chainContext?: string; } export interface IStoreFetchActionRequestOptions { /** * If set will contain the path to set the default product properties on * * @type {string} */ addDefaultProductPropertiesPath?: string; } /** * Reusable fetchable data implementation for the Redux store * * @export * @class StoreFetchableData * @template REQ * @template RES */ export declare class StoreFetchableData { protected url: string; protected fetchOptions?: any; protected requestOptions?: IStoreFetchActionRequestOptions | undefined; /** * The store section name * Used to name the rootState member and postfixed to all actions * * @type {string} * @memberof StoreFetchableData */ name: string; /** * The actions for the fetchable data * * @memberof StoreFetchableData */ actions: { [key: string]: any; }; /** * The reducers for the fetchable data * * @memberof StoreFetchableData */ reducer: Reducer; /** * Initial state * * @type {IStoreFetchableDataState} * @memberof StoreFetchableData */ get initialState(): IStoreFetchableDataState; /** * The dispatch count. Used for the dispatchId * * @protected * @type {number} * @memberof StoreFetchableData */ protected dispatchCount: number; /** * Creates an instance of StoreFetchableData * * @param {string} name The name of this piece of state * @param {string} url The url to fetch the data from * @param {*} [fetchOptions] Optional additional parameters for the fetch * @memberof StoreFetchableData */ constructor(name: string, url: string, fetchOptions?: any, requestOptions?: IStoreFetchActionRequestOptions | undefined, additionalActions?: { [key: string]: any; }); /** * Expose a helper function to get the full url * * @returns * @memberof StoreFetchableData */ getUrl(): string; /** * Create a fetch action using the class request type * This helper will setup and add promises for the fetch call * and any chain that is triggered * * TODO: If typings provide optional-ness correctly we can remove the Partial * * NOTE: omitSessionId is deprecated but remains to not mess up parameter ordering * * @param {REQ} [request] The request payload * @returns * @memberof StoreFetchableData */ createFetchAction(request?: Partial, chainStarter?: string, timeout?: number, omitSessionIdDeprecated?: boolean, elevationToken?: string, serviceContext?: string, chainContext?: string): [AnyAction, Promise, Promise]; /** * Create a response action using the class response type * * @param {RES} [response] The response payload * @returns * @memberof StoreFetchableData */ createResponseAction(response?: RES): any; /** * Retrieves the requested data from the EVA backend * * @public * @param {*} action The redux action * @param {number} [timeout] Optional service timeout to replace the default * @param {string} [authorisationToken] Authentication token to use for the call. Set to 'none' to force empty * @returns {Promise} * @memberof StoreFetchableData */ fetchData(action: any, timeout?: number, authorisationToken?: string, endPointURL?: string): Promise; /** * Retrieves section specific state from the root state * * @returns {STATE} * @memberof StoreFetchableData */ getState(): STATE; /** * Retrieves section specific state from the root state as an observable stream * * @returns {Observable} The observable stream * @memberof StoreFetchableData */ getState$(): Observable; /** * Retrieves a specific property path from this reducers state from the * root state as an observable stream * * @param {string} propertyPath * @returns {Observable} * @memberof StoreFetchableData */ getPropertyState$(propertyPath: string | string[]): Observable; /** * Returns the response property as an observable stream * * @returns {Observable} * @memberof StoreFetchableData */ getResponse$(): Observable; /** * Returns the response property as an observable stream * * @returns {Observable} * @memberof StoreFetchableData */ getRequest$(): Observable; /** * Returns the isFetching property as an observable stream * * @returns {Observable} * @memberof StoreFetchableData */ isFetching$(): Observable; /** * Returns the error property as an observable stream * * @returns {(Observable)} * @memberof StoreFetchableData */ getError$(): Observable; /** * The saga listener for this store section * * @memberof StoreFetchableData */ saga(): Iterable; /** * Helper method for an async-awaitable timeout * * @param {number} ms * @returns * @memberof StoreFetchableData */ timeout(ms: number): Promise; /** * The collection of reducer functions * * @protected * @returns {{ [ reducerName: string ]: ( state: any, action: AnyAction ) => any }} * @memberof StoreFetchableData */ protected getReducerFunctions(): { [reducerName: string]: (state: any, action: AnyAction) => any; }; } /** * The interface implemented by all reducers * * @export * @interface IReducer * @extends {StoreFetchableData} */ export interface IReducer extends StoreFetchableData { }