UNPKG

7.14 kBPlain TextView Raw
1import type { Action, ActionCreator, StoreEnhancer } from 'redux'
2import { compose } from 'redux'
3
4/**
5 * @public
6 */
7export interface EnhancerOptions {
8 /**
9 * the instance name to be showed on the monitor page. Default value is `document.title`.
10 * If not specified and there's no document title, it will consist of `tabId` and `instanceId`.
11 */
12 name?: string
13 /**
14 * action creators functions to be available in the Dispatcher.
15 */
16 actionCreators?: ActionCreator<any>[] | { [key: string]: ActionCreator<any> }
17 /**
18 * if more than one action is dispatched in the indicated interval, all new actions will be collected and sent at once.
19 * It is the joint between performance and speed. When set to `0`, all actions will be sent instantly.
20 * Set it to a higher value when experiencing perf issues (also `maxAge` to a lower value).
21 *
22 * @default 500 ms.
23 */
24 latency?: number
25 /**
26 * (> 1) - maximum allowed actions to be stored in the history tree. The oldest actions are removed once maxAge is reached. It's critical for performance.
27 *
28 * @default 50
29 */
30 maxAge?: number
31 /**
32 * See detailed documentation at http://extension.remotedev.io/docs/API/Arguments.html#serialize
33 */
34 serialize?:
35 | boolean
36 | {
37 options?:
38 | boolean
39 | {
40 date?: boolean
41 regex?: boolean
42 undefined?: boolean
43 error?: boolean
44 symbol?: boolean
45 map?: boolean
46 set?: boolean
47 function?: boolean | Function
48 }
49 replacer?: (key: string, value: unknown) => unknown
50 reviver?: (key: string, value: unknown) => unknown
51 immutable?: unknown
52 refs?: unknown[]
53 }
54 /**
55 * function which takes `action` object and id number as arguments, and should return `action` object back.
56 */
57 actionSanitizer?: <A extends Action>(action: A, id: number) => A
58 /**
59 * function which takes `state` object and index as arguments, and should return `state` object back.
60 */
61 stateSanitizer?: <S>(state: S, index: number) => S
62 /**
63 * *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).
64 * If `actionsWhitelist` specified, `actionsBlacklist` is ignored.
65 */
66 actionsBlacklist?: string | string[]
67 /**
68 * *string or array of strings as regex* - actions types to be hidden / shown in the monitors (while passed to the reducers).
69 * If `actionsWhitelist` specified, `actionsBlacklist` is ignored.
70 */
71 actionsWhitelist?: string | string[]
72 /**
73 * called for every action before sending, takes `state` and `action` object, and returns `true` in case it allows sending the current data to the monitor.
74 * Use it as a more advanced version of `actionsBlacklist`/`actionsWhitelist` parameters.
75 */
76 predicate?: <S, A extends Action>(state: S, action: A) => boolean
77 /**
78 * if specified as `false`, it will not record the changes till clicking on `Start recording` button.
79 * Available only for Redux enhancer, for others use `autoPause`.
80 *
81 * @default true
82 */
83 shouldRecordChanges?: boolean
84 /**
85 * if specified, whenever clicking on `Pause recording` button and there are actions in the history log, will add this action type.
86 * If not specified, will commit when paused. Available only for Redux enhancer.
87 *
88 * @default "@@PAUSED""
89 */
90 pauseActionType?: string
91 /**
92 * auto pauses when the extensions window is not opened, and so has zero impact on your app when not in use.
93 * Not available for Redux enhancer (as it already does it but storing the data to be sent).
94 *
95 * @default false
96 */
97 autoPause?: boolean
98 /**
99 * if specified as `true`, it will not allow any non-monitor actions to be dispatched till clicking on `Unlock changes` button.
100 * Available only for Redux enhancer.
101 *
102 * @default false
103 */
104 shouldStartLocked?: boolean
105 /**
106 * if set to `false`, will not recompute the states on hot reloading (or on replacing the reducers). Available only for Redux enhancer.
107 *
108 * @default true
109 */
110 shouldHotReload?: boolean
111 /**
112 * if specified as `true`, whenever there's an exception in reducers, the monitors will show the error message, and next actions will not be dispatched.
113 *
114 * @default false
115 */
116 shouldCatchErrors?: boolean
117 /**
118 * If you want to restrict the extension, specify the features you allow.
119 * If not specified, all of the features are enabled. When set as an object, only those included as `true` will be allowed.
120 * Note that except `true`/`false`, `import` and `export` can be set as `custom` (which is by default for Redux enhancer), meaning that the importing/exporting occurs on the client side.
121 * Otherwise, you'll get/set the data right from the monitor part.
122 */
123 features?: {
124 /**
125 * start/pause recording of dispatched actions
126 */
127 pause?: boolean
128 /**
129 * lock/unlock dispatching actions and side effects
130 */
131 lock?: boolean
132 /**
133 * persist states on page reloading
134 */
135 persist?: boolean
136 /**
137 * export history of actions in a file
138 */
139 export?: boolean | 'custom'
140 /**
141 * import history of actions from a file
142 */
143 import?: boolean | 'custom'
144 /**
145 * jump back and forth (time travelling)
146 */
147 jump?: boolean
148 /**
149 * skip (cancel) actions
150 */
151 skip?: boolean
152 /**
153 * drag and drop actions in the history list
154 */
155 reorder?: boolean
156 /**
157 * dispatch custom actions or action creators
158 */
159 dispatch?: boolean
160 /**
161 * generate tests for the selected actions
162 */
163 test?: boolean
164 }
165 /**
166 * Set to true or a stacktrace-returning function to record call stack traces for dispatched actions.
167 * Defaults to false.
168 */
169 trace?: boolean | (<A extends Action>(action: A) => string)
170 /**
171 * The maximum number of stack trace entries to record per action. Defaults to 10.
172 */
173 traceLimit?: number
174}
175
176/**
177 * @public
178 */
179export const composeWithDevTools: {
180 (options: EnhancerOptions): typeof compose
181 <StoreExt>(...funcs: Array<StoreEnhancer<StoreExt>>): StoreEnhancer<StoreExt>
182} =
183 typeof window !== 'undefined' &&
184 (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
185 ? (window as any).__REDUX_DEVTOOLS_EXTENSION_COMPOSE__
186 : function () {
187 if (arguments.length === 0) return undefined
188 if (typeof arguments[0] === 'object') return compose
189 return compose.apply(null, arguments as any as Function[])
190 }
191
192/**
193 * @public
194 */
195export const devToolsEnhancer: {
196 (options: EnhancerOptions): StoreEnhancer<any>
197} =
198 typeof window !== 'undefined' && (window as any).__REDUX_DEVTOOLS_EXTENSION__
199 ? (window as any).__REDUX_DEVTOOLS_EXTENSION__
200 : function () {
201 return function (noop) {
202 return noop
203 }
204 }
205
\No newline at end of file