import { IActionPayload } from './BaseAction'; import { Metas, MetasLoading, IMetaAction, Meta } from '../reducers/MetaReducer'; import { State, StateReturn } from '../models/BaseModel'; import { HTTP_STATUS_CODE } from '../utils/httpStatusCode'; import { HttpServiceBuilder } from '../services/HttpServiceBuilder'; import { METHOD } from '../utils/method'; import { ThrottleKeyOption, BaseHttpService } from '../services/BaseHttpService'; import { BaseAsyncAction } from './BaseAsyncAction'; export interface Types { prepare: string; success: string; fail: string; } export interface IBaseRequestAction extends IActionPayload, IMetaAction { method: METHOD; uri: string; body: Record; query: Record; successText: string; failText: string; hideError: boolean | ((response: IResponseAction) => boolean); requestOptions: object; modelName: string; throttle: { enable: boolean; duration: number; key: string; transfer: ThrottleKeyOption['transfer']; }; onPrepare?: (state: State, action: IActionPayload) => StateReturn; afterPrepare?: (action: IActionPayload) => void; afterPrepareDuration?: number; onSuccess?: (state: State, action: IResponseAction) => StateReturn; afterSuccess?: (action: IResponseAction) => void; afterSuccessDuration?: number; onFail?: (state: State, action: IResponseAction) => StateReturn; afterFail?: (action: IResponseAction) => void; afterFailDuration?: number; } export interface HttpTransform { httpStatus?: HTTP_STATUS_CODE; message?: string; businessCode?: string; } export interface IResponseAction extends IActionPayload, HttpTransform { response: Response; } export interface RequestPrepareAction extends IBaseRequestAction { loading: boolean; effect: IBaseRequestAction['onPrepare']; after: IBaseRequestAction['afterPrepare']; afterDuration: IBaseRequestAction['afterPrepareDuration']; } export interface RequestSuccessAction extends IBaseRequestAction, IResponseAction { loading: boolean; effect: IBaseRequestAction['onSuccess']; after: IBaseRequestAction['afterSuccess']; afterDuration: IBaseRequestAction['afterSuccessDuration']; } export interface RequestFailAction extends IBaseRequestAction, IResponseAction { loading: boolean; effect: IBaseRequestAction['onFail']; after: IBaseRequestAction['afterFail']; afterDuration: IBaseRequestAction['afterFailDuration']; } export interface RequestSubscriber { when: string; duration?: number; } export interface RequestPrepareSubscriber extends RequestSubscriber { then?: (state: State, action: IActionPayload) => StateReturn; after?: (action: IActionPayload) => void; } export interface RequestSuccessSubscriber extends RequestSubscriber { then?: (state: State, action: IResponseAction) => StateReturn; after?: (action: IResponseAction) => void; } export interface RequestFailSubscriber extends RequestSubscriber { then?: (state: State, action: IResponseAction) => StateReturn; after?: (action: IResponseAction) => void; } export declare class BaseRequestAction HttpServiceBuilder, Response, Payload, M> extends BaseAsyncAction { protected readonly builder: Builder; protected loadingsCache?: [Metas, MetasLoading]; protected readonly service: BaseHttpService; constructor(builder: Builder, service: BaseHttpService, fromSubClass?: boolean); /** * Clear throttle cache for this action */ clearThrottle(): void; /** * Information collected from service * * ```javascript * class TestModel extends Model { * getUser = $api.action(() => { * return this * .get('/api') * .onSuccess(() => {}) * }); * } * * const testModel = new TestModel(); * * // Get information * testModel.getUser.meta.httpStatus; * // Dispatch action * testModel.getUser(); * ``` */ get meta(): Meta; /** * @see get meta() * * ```javascript * testModel.getUser.loading; * ``` */ get loading(): boolean; /** * Information collected from service. * ```javascript * class TestModel extends Model { * getUser = $api.action((id: number) => { * return this * .get('/api') * .metas(id) * .onSuccess(() => {}) * }); * } * * const testModel = new TestModel(); * * // Get information * testModel.getUser.metas.pick(1).httpStatus; * // Dispatch action * testModel.getUser(1); * ``` */ get metas(): Metas; /** * @see get metas() * * ```javascript * testModel.getUser.loadings.pick(1); * ``` */ get loadings(): MetasLoading; /** * For model.subscriptions() */ onSuccess(changeState: NonNullable['then']>): RequestSuccessSubscriber; /** * For model.subscriptions() */ afterSuccess(callback: NonNullable['after']>, duration?: number): RequestSuccessSubscriber; /** * For model.subscriptions() */ onPrepare(changeState: NonNullable['then']>): RequestPrepareSubscriber; /** * For model.subscriptions() */ afterPrepare(callback: NonNullable['after']>, duration?: number): RequestPrepareSubscriber; /** * For model.subscriptions() */ onFail(changeState: NonNullable['then']>): RequestFailSubscriber; /** * For model.subscriptions() */ afterFail(callback: NonNullable['after']>, duration?: number): RequestFailSubscriber; protected getLoadingHandler(metas: Metas): MetasLoading; /** * @override */ protected methods(): string[]; /** * @override */ protected getters(): string[]; /** * @implements */ protected action(): Function; }