From cfefe8a144de4a7ee8640858f75df8e83f77b1b4 Mon Sep 17 00:00:00 2001 From: y0on2q Date: Mon, 22 Feb 2021 17:19:17 +0900 Subject: [PATCH 1/5] [lodash.isequalwith] remove redundant peerDependency --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index ddf15a4c..a1078343 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,6 @@ "eslint-plugin-react": "^7.11.1", "immutable": "^4.0.0-rc.12", "jest": "^24.3.1", - "lodash.isequalwith": "^4.4.0", "raf": "^3.4.0", "react": "^16.4.0", "react-dom": "^16.4.0", From 0a3e0cdd1ed53363836aee79b9e9f04aacea8803 Mon Sep 17 00:00:00 2001 From: y0on2q Date: Mon, 22 Feb 2021 17:34:01 +0900 Subject: [PATCH 2/5] [lodash.isequalwith] Change lodash.isequalwidth to use lodash --- package.json | 2 +- src/ConnectedRouter.js | 65 +++++++++++++----------------------------- yarn.lock | 10 +++---- 3 files changed, 26 insertions(+), 51 deletions(-) diff --git a/package.json b/package.json index a1078343..4cc8445f 100644 --- a/package.json +++ b/package.json @@ -28,11 +28,11 @@ "posttest": "npm run lint" }, "dependencies": { + "lodash": "^4.17.21", "prop-types": "^15.7.2" }, "peerDependencies": { "history": "^4.7.2", - "lodash.isequalwith": "^4.4.0", "react": "^16.4.0 || ^17.0.0", "react-redux": "^6.0.0 || ^7.1.0", "react-router": "^4.3.1 || ^5.0.0", diff --git a/src/ConnectedRouter.js b/src/ConnectedRouter.js index 95a176ad..c8be66c7 100644 --- a/src/ConnectedRouter.js +++ b/src/ConnectedRouter.js @@ -1,10 +1,10 @@ -import React, { PureComponent } from 'react' -import PropTypes from 'prop-types' -import { connect, ReactReduxContext } from 'react-redux' -import { Router } from 'react-router' -import isEqualWith from 'lodash.isequalwith' -import { onLocationChanged } from './actions' -import createSelectors from './selectors' +import React, { PureComponent } from "react" +import PropTypes from "prop-types" +import { connect, ReactReduxContext } from "react-redux" +import { Router } from "react-router" +import { isEqualWith } from "lodash" +import { onLocationChanged } from "./actions" +import createSelectors from "./selectors" const createConnectedRouter = (structure) => { const { getLocation } = createSelectors(structure) @@ -33,29 +33,12 @@ const createConnectedRouter = (structure) => { const isTimeTravelDebuggingAllowed = !props.noTimeTravelDebugging // Extract store's location - const { - pathname: pathnameInStore, - search: searchInStore, - hash: hashInStore, - state: stateInStore, - } = getLocation(store.getState()) + const { pathname: pathnameInStore, search: searchInStore, hash: hashInStore, state: stateInStore } = getLocation(store.getState()) // Extract history's location - const { - pathname: pathnameInHistory, - search: searchInHistory, - hash: hashInHistory, - state: stateInHistory, - } = history.location + const { pathname: pathnameInHistory, search: searchInHistory, hash: hashInHistory, state: stateInHistory } = history.location // If we do time travelling, the location in store is changed but location in history is not changed - if ( - isTimeTravelDebuggingAllowed && - props.history.action === 'PUSH' && - (pathnameInHistory !== pathnameInStore || - searchInHistory !== searchInStore || - hashInHistory !== hashInStore || - !isEqualWith(stateInStore, stateInHistory, stateCompareFunction)) - ) { + if (isTimeTravelDebuggingAllowed && props.history.action === "PUSH" && (pathnameInHistory !== pathnameInStore || searchInHistory !== searchInStore || hashInHistory !== hashInStore || !isEqualWith(stateInStore, stateInHistory, stateCompareFunction))) { this.inTimeTravelling = true // Update history's location to match store's location history.push({ @@ -78,7 +61,7 @@ const createConnectedRouter = (structure) => { // Listen to history changes this.unlisten = history.listen(handleLocationChange) - + if (!props.noInitialPop) { // Dispatch a location change action for the initial location. // This makes it backward-compatible with react-router-redux. @@ -94,20 +77,16 @@ const createConnectedRouter = (structure) => { render() { const { omitRouter, history, children } = this.props - + // The `omitRouter` option is available for applications that must // have a Router instance higher in the component tree but still desire // to use connected-react-router for its Redux integration. if (omitRouter) { - return <>{ children } + return <>{children} } - return ( - - { children } - - ) + return {children} } } @@ -123,7 +102,7 @@ const createConnectedRouter = (structure) => { push: PropTypes.func.isRequired, }).isRequired, basename: PropTypes.string, - children: PropTypes.oneOfType([ PropTypes.func, PropTypes.node ]), + children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), onLocationChanged: PropTypes.func.isRequired, noInitialPop: PropTypes.bool, noTimeTravelDebugging: PropTypes.bool, @@ -131,22 +110,18 @@ const createConnectedRouter = (structure) => { omitRouter: PropTypes.bool, } - const mapDispatchToProps = dispatch => ({ - onLocationChanged: (location, action, isFirstRendering) => dispatch(onLocationChanged(location, action, isFirstRendering)) + const mapDispatchToProps = (dispatch) => ({ + onLocationChanged: (location, action, isFirstRendering) => dispatch(onLocationChanged(location, action, isFirstRendering)), }) - const ConnectedRouterWithContext = props => { + const ConnectedRouterWithContext = (props) => { const Context = props.context || ReactReduxContext if (Context == null) { - throw 'Please upgrade to react-redux v6' + throw "Please upgrade to react-redux v6" } - return ( - - {({ store }) => } - - ) + return {({ store }) => } } ConnectedRouterWithContext.propTypes = { diff --git a/yarn.lock b/yarn.lock index c33abbe5..36b1cec9 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4645,11 +4645,6 @@ lodash.flattendeep@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2" integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI= -lodash.isequalwith@^4.4.0: - version "4.4.0" - resolved "https://registry.yarnpkg.com/lodash.isequalwith/-/lodash.isequalwith-4.4.0.tgz#266726ddd528f854f21f4ea98a065606e0fbc6b0" - integrity sha1-Jmcm3dUo+FTyH06pigZWBuD7xrA= - lodash.isplainobject@^4.0.6: version "4.0.6" resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" @@ -4665,6 +4660,11 @@ lodash@^4.15.0, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17. resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== +lodash@^4.17.21: + version "4.17.21" + resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" + integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== + loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf" From a9edb7f84937e5ef47576ddf66cd73e7d123b94d Mon Sep 17 00:00:00 2001 From: y0on2q Date: Mon, 22 Feb 2021 17:39:08 +0900 Subject: [PATCH 3/5] [lodash.isequalwith] eslint error fix --- src/ConnectedRouter.js | 65 +++++++++++++++++++++++++++++------------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/src/ConnectedRouter.js b/src/ConnectedRouter.js index c8be66c7..95a176ad 100644 --- a/src/ConnectedRouter.js +++ b/src/ConnectedRouter.js @@ -1,10 +1,10 @@ -import React, { PureComponent } from "react" -import PropTypes from "prop-types" -import { connect, ReactReduxContext } from "react-redux" -import { Router } from "react-router" -import { isEqualWith } from "lodash" -import { onLocationChanged } from "./actions" -import createSelectors from "./selectors" +import React, { PureComponent } from 'react' +import PropTypes from 'prop-types' +import { connect, ReactReduxContext } from 'react-redux' +import { Router } from 'react-router' +import isEqualWith from 'lodash.isequalwith' +import { onLocationChanged } from './actions' +import createSelectors from './selectors' const createConnectedRouter = (structure) => { const { getLocation } = createSelectors(structure) @@ -33,12 +33,29 @@ const createConnectedRouter = (structure) => { const isTimeTravelDebuggingAllowed = !props.noTimeTravelDebugging // Extract store's location - const { pathname: pathnameInStore, search: searchInStore, hash: hashInStore, state: stateInStore } = getLocation(store.getState()) + const { + pathname: pathnameInStore, + search: searchInStore, + hash: hashInStore, + state: stateInStore, + } = getLocation(store.getState()) // Extract history's location - const { pathname: pathnameInHistory, search: searchInHistory, hash: hashInHistory, state: stateInHistory } = history.location + const { + pathname: pathnameInHistory, + search: searchInHistory, + hash: hashInHistory, + state: stateInHistory, + } = history.location // If we do time travelling, the location in store is changed but location in history is not changed - if (isTimeTravelDebuggingAllowed && props.history.action === "PUSH" && (pathnameInHistory !== pathnameInStore || searchInHistory !== searchInStore || hashInHistory !== hashInStore || !isEqualWith(stateInStore, stateInHistory, stateCompareFunction))) { + if ( + isTimeTravelDebuggingAllowed && + props.history.action === 'PUSH' && + (pathnameInHistory !== pathnameInStore || + searchInHistory !== searchInStore || + hashInHistory !== hashInStore || + !isEqualWith(stateInStore, stateInHistory, stateCompareFunction)) + ) { this.inTimeTravelling = true // Update history's location to match store's location history.push({ @@ -61,7 +78,7 @@ const createConnectedRouter = (structure) => { // Listen to history changes this.unlisten = history.listen(handleLocationChange) - + if (!props.noInitialPop) { // Dispatch a location change action for the initial location. // This makes it backward-compatible with react-router-redux. @@ -77,16 +94,20 @@ const createConnectedRouter = (structure) => { render() { const { omitRouter, history, children } = this.props - + // The `omitRouter` option is available for applications that must // have a Router instance higher in the component tree but still desire // to use connected-react-router for its Redux integration. if (omitRouter) { - return <>{children} + return <>{ children } } - return {children} + return ( + + { children } + + ) } } @@ -102,7 +123,7 @@ const createConnectedRouter = (structure) => { push: PropTypes.func.isRequired, }).isRequired, basename: PropTypes.string, - children: PropTypes.oneOfType([PropTypes.func, PropTypes.node]), + children: PropTypes.oneOfType([ PropTypes.func, PropTypes.node ]), onLocationChanged: PropTypes.func.isRequired, noInitialPop: PropTypes.bool, noTimeTravelDebugging: PropTypes.bool, @@ -110,18 +131,22 @@ const createConnectedRouter = (structure) => { omitRouter: PropTypes.bool, } - const mapDispatchToProps = (dispatch) => ({ - onLocationChanged: (location, action, isFirstRendering) => dispatch(onLocationChanged(location, action, isFirstRendering)), + const mapDispatchToProps = dispatch => ({ + onLocationChanged: (location, action, isFirstRendering) => dispatch(onLocationChanged(location, action, isFirstRendering)) }) - const ConnectedRouterWithContext = (props) => { + const ConnectedRouterWithContext = props => { const Context = props.context || ReactReduxContext if (Context == null) { - throw "Please upgrade to react-redux v6" + throw 'Please upgrade to react-redux v6' } - return {({ store }) => } + return ( + + {({ store }) => } + + ) } ConnectedRouterWithContext.propTypes = { From ca5217f3dba23a5cdfbe2336bb668f110dba01e1 Mon Sep 17 00:00:00 2001 From: y0on2q Date: Mon, 22 Feb 2021 17:42:08 +0900 Subject: [PATCH 4/5] [lodash.isequalwith] Change lodash.isequalwidth to use lodash --- src/ConnectedRouter.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ConnectedRouter.js b/src/ConnectedRouter.js index 95a176ad..2a173229 100644 --- a/src/ConnectedRouter.js +++ b/src/ConnectedRouter.js @@ -2,7 +2,7 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import { connect, ReactReduxContext } from 'react-redux' import { Router } from 'react-router' -import isEqualWith from 'lodash.isequalwith' +import { isEqualWith } from 'lodash' import { onLocationChanged } from './actions' import createSelectors from './selectors' From 01907892b793f23c7c72d986da0b3a35456a4e0b Mon Sep 17 00:00:00 2001 From: y0on2q Date: Mon, 22 Feb 2021 19:13:45 +0900 Subject: [PATCH 5/5] [lodash.isequalwith] To reduce module size, set non-lodash.isequalwith to peerdependency, non-devdependency --- package.json | 6 +++--- src/ConnectedRouter.js | 2 +- yarn.lock | 10 +++++----- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/package.json b/package.json index 4cc8445f..c0c08f3e 100644 --- a/package.json +++ b/package.json @@ -28,8 +28,8 @@ "posttest": "npm run lint" }, "dependencies": { - "lodash": "^4.17.21", - "prop-types": "^15.7.2" + "prop-types": "^15.7.2", + "lodash.isequalwith": "^4.4.0" }, "peerDependencies": { "history": "^4.7.2", @@ -89,4 +89,4 @@ "bugs": { "url": "https://github.com/supasate/connected-react-router/issues" } -} +} \ No newline at end of file diff --git a/src/ConnectedRouter.js b/src/ConnectedRouter.js index 2a173229..95a176ad 100644 --- a/src/ConnectedRouter.js +++ b/src/ConnectedRouter.js @@ -2,7 +2,7 @@ import React, { PureComponent } from 'react' import PropTypes from 'prop-types' import { connect, ReactReduxContext } from 'react-redux' import { Router } from 'react-router' -import { isEqualWith } from 'lodash' +import isEqualWith from 'lodash.isequalwith' import { onLocationChanged } from './actions' import createSelectors from './selectors' diff --git a/yarn.lock b/yarn.lock index 36b1cec9..c33abbe5 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4645,6 +4645,11 @@ lodash.flattendeep@^4.4.0: resolved "https://registry.yarnpkg.com/lodash.flattendeep/-/lodash.flattendeep-4.4.0.tgz#fb030917f86a3134e5bc9bec0d69e0013ddfedb2" integrity sha1-+wMJF/hqMTTlvJvsDWngAT3f7bI= +lodash.isequalwith@^4.4.0: + version "4.4.0" + resolved "https://registry.yarnpkg.com/lodash.isequalwith/-/lodash.isequalwith-4.4.0.tgz#266726ddd528f854f21f4ea98a065606e0fbc6b0" + integrity sha1-Jmcm3dUo+FTyH06pigZWBuD7xrA= + lodash.isplainobject@^4.0.6: version "4.0.6" resolved "https://registry.yarnpkg.com/lodash.isplainobject/-/lodash.isplainobject-4.0.6.tgz#7c526a52d89b45c45cc690b88163be0497f550cb" @@ -4660,11 +4665,6 @@ lodash@^4.15.0, lodash@^4.17.11, lodash@^4.17.12, lodash@^4.17.13, lodash@^4.17. resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.19.tgz#e48ddedbe30b3321783c5b4301fbd353bc1e4a4b" integrity sha512-JNvd8XER9GQX0v2qJgsaN/mzFCNA5BRe/j8JN9d+tWyGLSodKQHKFicdwNYzWwI3wjRnaKPsGj1XkBjx/F96DQ== -lodash@^4.17.21: - version "4.17.21" - resolved "https://registry.yarnpkg.com/lodash/-/lodash-4.17.21.tgz#679591c564c3bffaae8454cf0b3df370c3d6911c" - integrity sha512-v2kDEe57lecTulaDIuNTPy3Ry4gLGJ6Z1O3vE1krgXZNrsQ+LFTGHVxVjcXPs17LhbZVGedAJv8XZ1tvj5FvSg== - loose-envify@^1.0.0, loose-envify@^1.1.0, loose-envify@^1.2.0, loose-envify@^1.3.1, loose-envify@^1.4.0: version "1.4.0" resolved "https://registry.yarnpkg.com/loose-envify/-/loose-envify-1.4.0.tgz#71ee51fa7be4caec1a63839f7e682d8132d30caf"