mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-21 05:20:24 +08:00
First version of types for redux-pack: https://github.com/lelandrichardson/redux-pack/tree/v0.1.5
53 lines
1.9 KiB
TypeScript
53 lines
1.9 KiB
TypeScript
// Type definitions for redux-pack 0.1
|
|
// Project: https://github.com/lelandrichardson/redux-pack
|
|
// Definitions by: tansongyang <https://github.com/tansongyang>
|
|
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
|
// TypeScript Version: 2.4
|
|
import {
|
|
Action as ReduxAction,
|
|
Middleware,
|
|
Reducer,
|
|
} from 'redux';
|
|
|
|
export const KEY: {
|
|
readonly LIFECYCLE: 'redux-pack/LIFECYCLE'
|
|
readonly TRANSACTION: 'redux-pack/TRANSACTION'
|
|
};
|
|
|
|
export const LIFECYCLE: {
|
|
readonly START: 'start'
|
|
readonly SUCCESS: 'success'
|
|
readonly FAILURE: 'failure'
|
|
};
|
|
export type LIFECYCLEValues = 'start'| 'succes'| 'failure';
|
|
|
|
export const middleware: Middleware;
|
|
|
|
export interface Handlers<S> {
|
|
start?: Reducer<S>;
|
|
finish?: Reducer<S>;
|
|
failure?: Reducer<S>;
|
|
success?: Reducer<S>;
|
|
always?: Reducer<S>;
|
|
}
|
|
export type GetState<S> = () => S;
|
|
export interface ActionMeta<TState = {}, TSuccessPayload = {}, TErrorPayload = {}, TStartPayload = {}> {
|
|
startPayload?: TStartPayload;
|
|
onStart?(payload: TStartPayload, getState: GetState<TState>): void;
|
|
onFinish?(resolved: boolean, getState: GetState<TState>): void;
|
|
onSuccess?(response: TSuccessPayload, getState: GetState<TState>): void;
|
|
onFailure?(error: TErrorPayload, getState: GetState<TState>): void;
|
|
['redux-pack/LIFECYCLE']?: keyof LIFECYCLEValues;
|
|
['redux-pack/TRANSACTION']?: string;
|
|
}
|
|
export interface Action<TState = {}, TSuccessPayload = {}, TErrorPayload = {}, TStartPayload = {}> extends ReduxAction {
|
|
promise?: Promise<TSuccessPayload>;
|
|
payload?: TSuccessPayload | TErrorPayload | TStartPayload;
|
|
meta?: ActionMeta<TState, TSuccessPayload, TErrorPayload, TStartPayload>;
|
|
}
|
|
export function handle<TState, TSuccessPayload, TErrorPayload, TStartPayload>(
|
|
state: TState,
|
|
action: Action<TState, TSuccessPayload, TErrorPayload, TStartPayload>,
|
|
handlers: Handlers<TState>)
|
|
: TState;
|