Skip to content

Commit ae0c295

Browse files
authored
Remove demo dependency on connected-react-router (#1159)
* Remove connected-react-router from inspector demo * test-tab
1 parent fe64194 commit ae0c295

File tree

13 files changed

+53
-151
lines changed

13 files changed

+53
-151
lines changed

packages/redux-devtools-inspector-monitor-test-tab/demo/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,13 @@
1515
"@redux-devtools/inspector-monitor": "^2.1.2",
1616
"@redux-devtools/inspector-monitor-test-tab": "^0.8.6",
1717
"@redux-devtools/ui": "^1.2.1",
18-
"connected-react-router": "^6.9.2",
19-
"history": "^4.10.1",
2018
"immutable": "^4.0.0",
2119
"lodash.shuffle": "^4.2.0",
2220
"react": "^17.0.2",
2321
"react-dom": "^17.0.2",
2422
"react-is": "^17.0.2",
2523
"react-redux": "^7.2.8",
26-
"react-router": "^5.3.1",
24+
"react-router-dom": "^5.3.1",
2725
"redux": "^4.2.0",
2826
"redux-logger": "^3.0.6",
2927
"styled-components": "^5.3.5"
@@ -33,13 +31,12 @@
3331
"@babel/preset-env": "^7.17.10",
3432
"@babel/preset-react": "^7.16.7",
3533
"@babel/preset-typescript": "^7.16.7",
36-
"@types/history": "^4.7.11",
3734
"@types/lodash.shuffle": "^4.2.7",
3835
"@types/node": "^16.11.33",
3936
"@types/react": "^17.0.45",
4037
"@types/react-dom": "^17.0.16",
4138
"@types/react-redux": "^7.1.24",
42-
"@types/react-router": "^5.1.18",
39+
"@types/react-router-dom": "^5.3.3",
4340
"@types/redux-logger": "^3.0.9",
4441
"@types/styled-components": "^5.1.25",
4542
"@types/webpack-env": "^1.16.4",

packages/redux-devtools-inspector-monitor-test-tab/demo/src/DemoApp.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import React, { CSSProperties } from 'react';
22
import { connect } from 'react-redux';
33
import { Button, Toolbar, Spacer } from '@redux-devtools/ui';
4-
import { push as pushRoute } from 'connected-react-router';
54
import pkg from '@redux-devtools/inspector-monitor-test-tab/package.json';
5+
import { RouteComponentProps, withRouter } from 'react-router-dom';
66
import getOptions from './getOptions';
77
import { DemoAppState } from './reducers';
88
import {
@@ -69,11 +69,11 @@ interface Props
6969
shuffleArray: () => void;
7070
}
7171

72-
class DemoApp extends React.Component<Props> {
72+
class DemoApp extends React.Component<Props & RouteComponentProps> {
7373
timeout?: number;
7474

7575
render() {
76-
const options = getOptions(this.props.router.location);
76+
const options = getOptions(this.props.location);
7777

7878
return (
7979
<div style={styles.wrapper}>
@@ -180,5 +180,4 @@ export default connect((state: DemoAppState) => state, {
180180
addFunction: (): AddFunctionAction => ({ type: 'ADD_FUNCTION' }),
181181
addSymbol: (): AddSymbolAction => ({ type: 'ADD_SYMBOL' }),
182182
shuffleArray: (): ShuffleArrayAction => ({ type: 'SHUFFLE_ARRAY' }),
183-
pushRoute,
184-
})(DemoApp);
183+
})(withRouter(DemoApp));

packages/redux-devtools-inspector-monitor-test-tab/demo/src/DevTools.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
import React from 'react';
2-
import { connect } from 'react-redux';
32
import { createDevTools } from '@redux-devtools/core';
43
import {
54
InspectorMonitor,
65
base16Themes,
76
Tab,
87
} from '@redux-devtools/inspector-monitor';
98
import { DockMonitor } from '@redux-devtools/dock-monitor';
10-
import { Location } from 'history';
9+
import { RouteComponentProps, withRouter } from 'react-router-dom';
1110
import getOptions from './getOptions';
1211
import { TestTab } from '@redux-devtools/inspector-monitor-test-tab';
13-
import { DemoAppState } from './reducers';
1412
import { Action } from 'redux';
1513

1614
export const getDevTools = (location: { search: string }) =>
@@ -38,13 +36,9 @@ export const getDevTools = (location: { search: string }) =>
3836
</DockMonitor>
3937
);
4038

41-
const UnconnectedDevTools = ({ location }: { location: Location }) => {
39+
const UnconnectedDevTools = ({ location }: RouteComponentProps) => {
4240
const DevTools = getDevTools(location);
4341
return <DevTools />;
4442
};
4543

46-
const mapStateToProps = (state: DemoAppState) => ({
47-
location: state.router.location,
48-
});
49-
50-
export const ConnectedDevTools = connect(mapStateToProps)(UnconnectedDevTools);
44+
export const ConnectedDevTools = withRouter(UnconnectedDevTools);

packages/redux-devtools-inspector-monitor-test-tab/demo/src/getOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export default function getOptions(location: { search: string }) {
99
return {
1010
useExtension: location.search.indexOf('ext') !== -1,
1111
supportImmutable: location.search.indexOf('immutable') !== -1,
12-
theme: getTheme(),
12+
theme: getTheme(location),
1313
dark: location.search.indexOf('dark') !== -1,
1414
};
1515
}
1616

17-
function getTheme() {
17+
function getTheme(location: { search: string }) {
1818
const match = /theme=([^&]+)/.exec(location.search);
1919
return match ? match[1] : 'inspector';
2020
}

packages/redux-devtools-inspector-monitor-test-tab/demo/src/index.tsx

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@ import {
1010
StoreEnhancerStoreCreator,
1111
} from 'redux';
1212
import logger from 'redux-logger';
13-
import { Route } from 'react-router';
14-
import { createBrowserHistory } from 'history';
15-
import { ConnectedRouter, routerMiddleware } from 'connected-react-router';
13+
import { BrowserRouter, Route } from 'react-router-dom';
1614
import { persistState } from '@redux-devtools/core';
1715
import DemoApp from './DemoApp';
18-
import createRootReducer from './reducers';
16+
import { rootReducer } from './reducers';
1917
import getOptions from './getOptions';
2018
import { ConnectedDevTools, getDevTools } from './DevTools';
2119

@@ -31,14 +29,12 @@ const ROOT =
3129

3230
const DevTools = getDevTools(window.location);
3331

34-
const history = createBrowserHistory();
35-
3632
const useDevtoolsExtension =
3733
!!(window as unknown as { __REDUX_DEVTOOLS_EXTENSION__: unknown }) &&
3834
getOptions(window.location).useExtension;
3935

4036
const enhancer = compose(
41-
applyMiddleware(logger, routerMiddleware(history)),
37+
applyMiddleware(logger),
4238
(next: StoreEnhancerStoreCreator) => {
4339
const instrument = useDevtoolsExtension
4440
? (
@@ -52,11 +48,11 @@ const enhancer = compose(
5248
persistState(getDebugSessionKey())
5349
);
5450

55-
const store = createStore(createRootReducer(history), enhancer);
51+
const store = createStore(rootReducer, enhancer);
5652

5753
render(
5854
<Provider store={store}>
59-
<ConnectedRouter history={history}>
55+
<BrowserRouter>
6056
<Container
6157
themeData={{
6258
theme: 'default',
@@ -69,7 +65,7 @@ render(
6965
</Route>
7066
{!useDevtoolsExtension && <ConnectedDevTools />}
7167
</Container>
72-
</ConnectedRouter>
68+
</BrowserRouter>
7369
</Provider>,
7470
document.getElementById('root')
7571
);

packages/redux-devtools-inspector-monitor-test-tab/demo/src/reducers.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,6 @@
11
import Immutable from 'immutable';
22
import shuffle from 'lodash.shuffle';
33
import { combineReducers, Reducer } from 'redux';
4-
import {
5-
connectRouter,
6-
LocationChangeAction,
7-
RouterState,
8-
} from 'connected-react-router';
9-
import { History } from 'history';
104

115
type Nested = { long: { nested: { path: { to: { a: string } } }[] } };
126

@@ -139,11 +133,9 @@ type DemoAppAction =
139133
| HugePayloadAction
140134
| AddFunctionAction
141135
| AddSymbolAction
142-
| ShuffleArrayAction
143-
| LocationChangeAction;
136+
| ShuffleArrayAction;
144137

145138
export interface DemoAppState {
146-
router: RouterState;
147139
timeoutUpdateEnabled: boolean;
148140
store: number;
149141
undefined: { val: undefined };
@@ -162,11 +154,8 @@ export interface DemoAppState {
162154
shuffleArray: unknown[];
163155
}
164156

165-
const createRootReducer = (
166-
history: History
167-
): Reducer<DemoAppState, DemoAppAction> =>
157+
export const rootReducer: Reducer<DemoAppState, DemoAppAction> =
168158
combineReducers<DemoAppState, DemoAppAction>({
169-
router: connectRouter(history) as Reducer<RouterState, DemoAppAction>,
170159
timeoutUpdateEnabled: (state = false, action) =>
171160
action.type === 'TOGGLE_TIMEOUT_UPDATE'
172161
? action.timeoutUpdateEnabled
@@ -231,5 +220,3 @@ const createRootReducer = (
231220
shuffleArray: (state = DEFAULT_SHUFFLE_ARRAY, action) =>
232221
action.type === 'SHUFFLE_ARRAY' ? shuffle(state) : state,
233222
});
234-
235-
export default createRootReducer;

packages/redux-devtools-inspector-monitor/demo/package.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,13 @@
1414
"@redux-devtools/dock-monitor": "^2.1.1",
1515
"@redux-devtools/inspector-monitor": "^2.1.2",
1616
"base16": "^1.0.0",
17-
"connected-react-router": "^6.9.2",
18-
"history": "^4.10.1",
1917
"immutable": "^4.0.0",
2018
"lodash.shuffle": "^4.2.0",
2119
"react": "^17.0.2",
2220
"react-bootstrap": "^2.3.1",
2321
"react-dom": "^17.0.2",
2422
"react-redux": "^7.2.8",
25-
"react-router": "^5.3.1",
23+
"react-router-dom": "^5.3.1",
2624
"redux": "^4.2.0",
2725
"redux-logger": "^3.0.6"
2826
},
@@ -32,13 +30,12 @@
3230
"@babel/preset-react": "^7.16.7",
3331
"@babel/preset-typescript": "^7.16.7",
3432
"@types/base16": "^1.0.2",
35-
"@types/history": "^4.7.11",
3633
"@types/lodash.shuffle": "^4.2.7",
3734
"@types/node": "^16.11.33",
3835
"@types/react": "^17.0.45",
3936
"@types/react-dom": "^17.0.16",
4037
"@types/react-redux": "^7.1.24",
41-
"@types/react-router": "^5.1.18",
38+
"@types/react-router-dom": "^5.3.3",
4239
"@types/redux-logger": "^3.0.9",
4340
"@types/webpack-env": "^1.16.4",
4441
"@typescript-eslint/eslint-plugin": "^5.22.0",

packages/redux-devtools-inspector-monitor/demo/src/DemoApp.tsx

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ import Col from 'react-bootstrap/Col';
1010
import InputGroup from 'react-bootstrap/InputGroup';
1111
import Row from 'react-bootstrap/Row';
1212
import * as base16 from 'base16';
13-
import { push as pushRoute } from 'connected-react-router';
14-
import { Path } from 'history';
1513
import { inspectorThemes } from '@redux-devtools/inspector-monitor';
14+
import { RouteComponentProps, withRouter } from 'react-router-dom';
1615
import getOptions, { Options } from './getOptions';
1716
import {
1817
AddFunctionAction,
@@ -140,14 +139,13 @@ interface Props
140139
addFunction: () => void;
141140
addSymbol: () => void;
142141
shuffleArray: () => void;
143-
pushRoute: (path: Path) => void;
144142
}
145143

146-
class DemoApp extends React.Component<Props> {
144+
class DemoApp extends React.Component<Props & RouteComponentProps> {
147145
timeout?: number;
148146

149147
render() {
150-
const options = getOptions(this.props.router.location);
148+
const options = getOptions(this.props.location);
151149

152150
return (
153151
<div style={styles.wrapper}>
@@ -265,7 +263,7 @@ class DemoApp extends React.Component<Props> {
265263
}
266264

267265
toggleExtension = () => {
268-
const options = getOptions(this.props.router.location);
266+
const options = getOptions(this.props.location);
269267

270268
window.location.href = buildUrl({
271269
...options,
@@ -274,21 +272,21 @@ class DemoApp extends React.Component<Props> {
274272
};
275273

276274
toggleImmutableSupport = () => {
277-
const options = getOptions(this.props.router.location);
275+
const options = getOptions(this.props.location);
278276

279-
this.props.pushRoute(
277+
this.props.history.push(
280278
buildUrl({ ...options, supportImmutable: !options.supportImmutable })
281279
);
282280
};
283281

284282
toggleTheme = () => {
285-
const options = getOptions(this.props.router.location);
283+
const options = getOptions(this.props.location);
286284

287-
this.props.pushRoute(buildUrl({ ...options, dark: !options.dark }));
285+
this.props.history.push(buildUrl({ ...options, dark: !options.dark }));
288286
};
289287

290288
setTheme = (options: Options, theme: string) => {
291-
this.props.pushRoute(buildUrl({ ...options, theme }));
289+
this.props.history.push(buildUrl({ ...options, theme }));
292290
};
293291

294292
toggleTimeoutUpdate = () => {
@@ -332,5 +330,4 @@ export default connect((state: DemoAppState) => state, {
332330
addFunction: (): AddFunctionAction => ({ type: 'ADD_FUNCTION' }),
333331
addSymbol: (): AddSymbolAction => ({ type: 'ADD_SYMBOL' }),
334332
shuffleArray: (): ShuffleArrayAction => ({ type: 'SHUFFLE_ARRAY' }),
335-
pushRoute,
336-
})(DemoApp);
333+
})(withRouter(DemoApp));

packages/redux-devtools-inspector-monitor/demo/src/DevTools.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
import React from 'react';
2-
import { connect } from 'react-redux';
32
import { createDevTools } from '@redux-devtools/core';
43
import { DockMonitor } from '@redux-devtools/dock-monitor';
5-
import { Location } from 'history';
64
import {
75
InspectorMonitor,
86
base16Themes,
97
} from '@redux-devtools/inspector-monitor';
8+
import { RouteComponentProps, withRouter } from 'react-router-dom';
109
import getOptions from './getOptions';
11-
import { DemoAppState } from './reducers';
1210

1311
const CustomComponent = () => (
1412
<div
@@ -48,13 +46,9 @@ export const getDevTools = (location: { search: string }) =>
4846
</DockMonitor>
4947
);
5048

51-
const UnconnectedDevTools = ({ location }: { location: Location }) => {
49+
const UnconnectedDevTools = ({ location }: RouteComponentProps) => {
5250
const DevTools = getDevTools(location);
5351
return <DevTools />;
5452
};
5553

56-
const mapStateToProps = (state: DemoAppState) => ({
57-
location: state.router.location,
58-
});
59-
60-
export const ConnectedDevTools = connect(mapStateToProps)(UnconnectedDevTools);
54+
export const ConnectedDevTools = withRouter(UnconnectedDevTools);

packages/redux-devtools-inspector-monitor/demo/src/getOptions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ export default function getOptions(location: { search: string }) {
99
return {
1010
useExtension: location.search.indexOf('ext') !== -1,
1111
supportImmutable: location.search.indexOf('immutable') !== -1,
12-
theme: getTheme(),
12+
theme: getTheme(location),
1313
dark: location.search.indexOf('dark') !== -1,
1414
};
1515
}
1616

17-
function getTheme() {
17+
function getTheme(location: { search: string }) {
1818
const match = /theme=([^&]+)/.exec(location.search);
1919
return match ? match[1] : 'inspector';
2020
}

0 commit comments

Comments
 (0)