Skip to content

Commit

Permalink
Changed to isEqualWith with optional comparator prop (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
BlazPocrnja committed Mar 16, 2020
1 parent 55c7447 commit 4025c05
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@
"prop-types": "^15.7.2"
},
"peerDependencies": {
"immutable": "^3.8.1 || ^4.0.0-rc.1",
"history": "^4.7.2",
"immutable": "^3.8.1 || ^4.0.0-rc.1",
"lodash.isequalwith": "^4.4.0",
"react": "^16.4.0",
"react-redux": "^6.0.0 || ^7.1.0",
"react-router": "^4.3.1 || ^5.0.0",
Expand Down
11 changes: 6 additions & 5 deletions src/ConnectedRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 { isEqual } from 'lodash'
import isEqualWith from 'lodash.isequalwith'
import { onLocationChanged } from './actions'
import createSelectors from './selectors'

Expand All @@ -19,7 +19,7 @@ const createConnectedRouter = (structure) => {
constructor(props) {
super(props)

const { store, history, onLocationChanged } = props
const { store, history, onLocationChanged, stateCompareFunction} = props

this.inTimeTravelling = false

Expand All @@ -38,15 +38,15 @@ const createConnectedRouter = (structure) => {
search: searchInHistory,
hash: hashInHistory,
state: stateInHistory,
} = history.location
} = history.location

// If we do time travelling, the location in store is changed but location in history is not changed
if (
props.history.action === 'PUSH' &&
(pathnameInHistory !== pathnameInStore ||
searchInHistory !== searchInStore ||
hashInHistory !== hashInStore ||
!isEqual(stateInStore, stateInHistory))
!isEqualWith(stateInStore, stateInHistory, stateCompareFunction))
) {
this.inTimeTravelling = true
// Update history's location to match store's location
Expand Down Expand Up @@ -105,7 +105,8 @@ const createConnectedRouter = (structure) => {
}).isRequired,
basename: PropTypes.string,
children: PropTypes.oneOfType([ PropTypes.func, PropTypes.node ]),
onLocationChanged: PropTypes.func.isRequired,
onLocationChanged: PropTypes.func.isRequired,
stateCompareFunction: PropTypes.func,
}

const mapDispatchToProps = dispatch => ({
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4738,6 +4738,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"
Expand Down

0 comments on commit 4025c05

Please sign in to comment.