Added type definition for redux-optimistic-ui

This commit is contained in:
Alexey Svetliakov
2016-07-06 03:02:52 +02:00
parent 8df97176d2
commit e722612c5f
2 changed files with 116 additions and 0 deletions
@@ -0,0 +1,38 @@
/// <reference path="../redux/redux.d.ts" />
/// <reference path="./redux-optimistic-ui.d.ts" />
import { Action } from "redux";
import { OptimisticState, OptimisticAction, BEGIN, optimistic, ensureState, } from "redux-optimistic-ui";
interface TestState {
a: number;
b: string;
}
declare const testState: TestState;
declare const optimisticState: OptimisticState<TestState>;
function myReducer(state: TestState, action: Action) {
return state;
}
const optimisticReducer = optimistic(myReducer);
const nextState = optimisticReducer(optimisticState, { type: "test" });
nextState.current.a;
nextState.current.b;
nextState.beforeState;
nextState.history;
ensureState(testState).a;
ensureState(optimisticState).a;
const myOptimisticAction: Action & OptimisticAction = {
type: "test",
meta: {
optimistic: {
type: BEGIN,
id: 1
}
}
}
+78
View File
@@ -0,0 +1,78 @@
// Type definitions for redux-optimistic-ui 0.4.0
// Project: https://github.com/mattkrick/redux-optimistic-ui
// Definitions by: Alexey Svetliakov <https://github.com/asvetliakov>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/// <reference path="../redux/redux.d.ts" />
declare module "redux-optimistic-ui" {
import { Reducer } from "redux";
/**
* Enhanced state by redux-optimistic-ui
*/
export interface OptimisticState<TState> {
/**
* History list
* List is Immutable.List<>
*/
history: any;
/**
* Before state
*/
beforeState: TState;
/**
* Current state
*/
current: TState;
}
/**
* Enhances and wraps your root reducer into optimistic state
*/
export function optimistic<TState>(reducer: Reducer<TState>): Reducer<OptimisticState<TState>>;
/**
* Returns your current state or state if it wasn't enhanced yet
*/
export function ensureState<TState>(state: OptimisticState<TState> | TState): TState;
/**
* Optimistic action slice
*/
export interface OptimisticAction {
meta: {
/**
* Optimistic information
*/
optimistic: {
/**
* Type, BEGIN, COMMIT or REVERT
*
* @type {string}
*/
type: string;
/**
* Transaction id. Id should be unique for each optimistic action
*
* @type {number}
*/
id: number;
}
}
}
/**
* Start optimistic action
*/
export const BEGIN: string;
/**
* Finish optimistic action and commit results
*/
export const COMMIT: string;
/**
* Revert optimistic action
*/
export const REVERT: string;
}