UNPKG

redux-promise-middleware-actions

Version:

Redux action creator for making async actions with redux-promise-middleware

67 lines (66 loc) 2.69 kB
export declare const onPending: (type: any, delimiter?: string) => string; export declare const onFulfilled: (type: any, delimiter?: string) => string; export declare const onRejected: (type: any, delimiter?: string) => string; export declare type Action<Type extends string, Payload = undefined, Meta = undefined> = Payload extends undefined ? Meta extends undefined ? { type: Type; } : { type: Type; meta: Meta; } : Payload extends Error ? Meta extends undefined ? { type: Type; payload: Payload; error: true; } : { type: Type; payload: Payload; meta: Meta; error: true; } : Meta extends undefined ? { type: Type; payload: Payload; } : { type: Type; payload: Payload; meta: Meta; }; export declare type AnyAction = Action<string>; export declare type ActionCreator<T extends AnyAction, U extends any[] = any> = { (...args: U): T; toString(): T['type']; }; export declare function createAction<Type extends string>(type: Type): ActionCreator<Action<Type>>; export declare function createAction<Type extends string, Payload, U extends any[]>(type: Type, payloadCreator: (...args: U) => Payload): ActionCreator<Action<Type, Payload>, U>; export declare function createAction<Type extends string, Payload, Metadata, U extends any[]>(type: Type, payloadCreator: (...args: U) => Payload, metadataCreator?: (...args: U) => Metadata): ActionCreator<Action<Type, Payload, Metadata>, U>; export interface AsyncActionCreator<Type extends string, Payload, Metadata> extends ActionCreator<Action<Type, Promise<Payload>, Metadata>> { pending: ActionCreator<Action<string>>; fulfilled: ActionCreator<Action<string, Payload>>; rejected: ActionCreator<Action<string, Error>>; } /** * Asynchronous action creator factory. * @param type Action type. * @example * const getTodos = createAsyncAction('TODOS_GET', () => fetch('https://todos.com/todos')); */ export declare function createAsyncAction<Type extends string, Payload, Metadata, U extends any[]>(type: Type, payloadCreator: (...args: U) => Promise<Payload>, metadataCreator?: (...args: U) => Metadata, { promiseTypeDelimiter: delimiter, }?: { promiseTypeDelimiter?: string; }): ActionCreator<Metadata extends undefined ? { type: Type; payload: Promise<Payload>; } : { type: Type; payload: Promise<Payload>; meta: Metadata; }, U> & { toString: () => never; } & { pending: ActionCreator<{ type: string; }, any>; fulfilled: ActionCreator<Action<string, Payload, undefined>, [payload: Payload]>; rejected: ActionCreator<{ type: string; payload: Error; error: true; }, [payload: Error]>; };