forked from BetterWorldBetterPlace/simple-react-redux
-
Notifications
You must be signed in to change notification settings - Fork 0
/
typings.d.ts
109 lines (83 loc) · 3.91 KB
/
typings.d.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
declare module 'redux-undo' {
import { Reducer, Action, AnyAction } from 'redux';
export interface StateWithHistory<State> {
past: State[];
present: State;
future: State[];
_latestUnfiltered?: State;
group?: any;
index?: number;
limit?: number;
}
export type FilterFunction<S = any, A extends Action = AnyAction> = (action: A, currentState: S, previousHistory: StateWithHistory<S>) => boolean;
export type GroupByFunction<S = any, A extends Action = AnyAction> = (action: A, currentState: S, previousHistory: StateWithHistory<S>) => any;
export type CombineFilters = <S = any, A extends Action = AnyAction>(...filters: FilterFunction<S, A>[]) => FilterFunction<S, A>;
export class ActionCreators {
static undo: () => Action;
static redo: () => Action;
static jump: (point: number) => Action;
static jumpToPast: (index: number) => Action;
static jumpToFuture: (index: number) => Action;
static clearHistory: () => Action;
}
export class ActionTypes {
static UNDO: string;
static REDO: string;
static JUMP: string;
static JUMP_TO_PAST: string;
static JUMP_TO_FUTURE: string;
static CLEAR_HISTORY: string;
}
export interface UndoableOptions<S = any, A extends Action = AnyAction> {
/* Set a limit for the history */
limit?: number;
/** If you don't want to include every action in the undo/redo history, you can add a filter function to undoable */
filter?: FilterFunction<S, A>;
/** Groups actions together into one undo step */
groupBy?: GroupByFunction<S, A>;
/** Define a custom action type for this undo action */
undoType?: string;
/** Define a custom action type for this redo action */
redoType?: string;
/** Define custom action type for this jump action */
jumpType?: string;
/** Define custom action type for this jumpToPast action */
jumpToPastType?: string;
/** Define custom action type for this jumpToFuture action */
jumpToFutureType?: string;
/** Define custom action type for this clearHistory action */
clearHistoryType?: string | string[];
/** History will be (re)set upon init action type */
initTypes?: string[];
/** Set to `true` to turn on debugging */
debug?: boolean;
/** Set to `true` to prevent undoable from skipping the reducer on undo/redo **/
neverSkipReducer?: boolean;
/** Set to `true` to prevent the user from undoing to the initial state **/
ignoreInitialState?: boolean;
/** Set to `true` to synchronize the _latestUnfiltered state with present wen a excluded action is dispatched **/
syncFilter?: boolean;
}
interface Undoable {
<State, A extends Action = AnyAction>(reducer: Reducer<State, A>, options?: UndoableOptions<State, A>): Reducer<StateWithHistory<State>>;
}
type IncludeAction = <S = any, A extends Action = AnyAction>(actions: A['type'] | A['type'][]) => FilterFunction<S, A>;
type ExcludeAction = IncludeAction;
type GroupByActionTypes = <S = any, A extends Action = AnyAction>(actions: A['type'] | A['type'][]) => GroupByFunction<S, A>;
type NewHistory = <State>(past: State[], present: State, future: State[], group?: any) => StateWithHistory<State>;
const undoable: Undoable;
export default undoable;
/**
* If you don't want to include every action in the undo/redo history, you can add a filter function to undoable.
* redux-undo provides you with the includeAction and excludeAction helpers for basic filtering.
*/
export const includeAction: IncludeAction;
/**
* If you don't want to include every action in the undo/redo history, you can add a filter function to undoable.
* redux-undo provides you with the includeAction and excludeAction helpers for basic filtering.
*/
export const excludeAction: ExcludeAction;
export const combineFilters: CombineFilters;
export const groupByActionTypes: GroupByActionTypes;
export const newHistory: NewHistory;
}