Skip to content

Commit 3bb7d8c

Browse files
authored
Fork redux-devtools-extension (#384)
* Only check format for Markdown files in /docs * Add TS port of redux-devtools extension and use it * Remove redux-devtools-extension dependency * Remove stray console logs from tests
1 parent 1314ba4 commit 3bb7d8c

8 files changed

+205
-13
lines changed

etc/redux-toolkit.api.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
```ts
66

77
import { Action } from 'redux';
8+
import { ActionCreator } from 'redux';
89
import { AnyAction } from 'redux';
910
import { default as createNextState } from 'immer';
1011
import { createSelector } from 'reselect';
1112
import { DeepPartial } from 'redux';
1213
import { Dispatch } from 'redux';
1314
import { Draft } from 'immer';
14-
import { EnhancerOptions } from 'redux-devtools-extension';
1515
import { Middleware } from 'redux';
1616
import { Reducer } from 'redux';
1717
import { ReducersMapObject } from 'redux';

package-lock.json

Lines changed: 0 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"build": "tsdx build --format cjs,esm,umd --name redux-toolkit && api-extractor run --local",
4343
"dev": "tsdx watch --format cjs,esm,umd",
4444
"format": "prettier --write \"src/*.ts\" \"**/*.md\"",
45-
"format:check": "prettier --list-different \"src/*.ts\" \"**/*.md\"",
45+
"format:check": "prettier --list-different \"src/*.ts\" \"docs/*/**.md\"",
4646
"lint": "tsdx lint src",
4747
"prepare": "npm run lint && npm run format:check && npm test && npm run build-ci",
4848
"test": "tsdx test"
@@ -58,7 +58,6 @@
5858
"immer": "^4.0.1",
5959
"nanoid": "^2.1.11",
6060
"redux": "^4.0.0",
61-
"redux-devtools-extension": "^2.13.8",
6261
"redux-immutable-state-invariant": "^2.1.0",
6362
"redux-thunk": "^2.3.0",
6463
"reselect": "^4.0.0"

src/configureStore.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { configureStore } from './configureStore'
22
import * as redux from 'redux'
3-
import * as devtools from 'redux-devtools-extension'
3+
import * as devtools from './devtoolsExtension'
44
import { StoreEnhancer, StoreEnhancerStoreCreator } from 'redux'
55

66
describe('configureStore', () => {

src/configureStore.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
import {
1717
composeWithDevTools,
1818
EnhancerOptions as DevToolsOptions
19-
} from 'redux-devtools-extension'
19+
} from './devtoolsExtension'
2020

2121
import isPlainObject from './isPlainObject'
2222
import {

src/devtoolsExtension.ts

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

src/entities/sorted_state_adapter.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ describe('Sorted State Adapter', () => {
2929
adapter = createEntityAdapter({
3030
selectId: (book: BookModel) => book.id,
3131
sortComparer: (a, b) => {
32-
//console.log(`${a.title}, ${b.title}`)
3332
return a.title.localeCompare(b.title)
3433
}
3534
})

src/entities/unsorted_state_adapter.test.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,6 @@ describe('Unsorted State Adapter', () => {
228228

229229
const { ids, entities } = withUpdates
230230

231-
console.log(withUpdates)
232-
233231
/*
234232
Original code failed with a mish-mash of values, like:
235233

0 commit comments

Comments
 (0)