Skip to content

Commit

Permalink
Fix shouldComponentUpdate of Map component
Browse files Browse the repository at this point in the history
  • Loading branch information
klzns committed Aug 24, 2018
1 parent f0191d1 commit a2ff2b1
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.

## [Unreleased]

### Fixed
- Fix `shouldComponentUpdate` of `Map` component

## [2.1.0] - 2018-08-22

### Added
Expand Down
3 changes: 2 additions & 1 deletion src/geolocation/Map.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ class Map extends Component {

shouldComponentUpdate(prevProps) {
const rulesChanged = prevProps.rules.country !== this.props.rules.country
const loadingGoogleChanged = prevProps.loadingGoogle !== this.props.loadingGoogle
const geoCoordsChanged = this.isDifferentGeoCoords(
this.getCoordinatesFromProps(prevProps),
this.getCoordinatesFromProps(this.props),
)

return geoCoordsChanged || rulesChanged
return geoCoordsChanged || rulesChanged || loadingGoogleChanged
}

componentDidUpdate() {
Expand Down
12 changes: 12 additions & 0 deletions src/geolocation/Map.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,16 @@ describe('Map', () => {

expect(shouldUpdate).toBe(true)
})

it('should re-render if loadingGoogle changed', () => {
const currentProps = shallowInstance.props
const currentState = shallowInstance.state

const shouldUpdate = shallowInstance.shouldComponentUpdate(
{ ...currentProps, loadingGoogle: true },
currentState,
)

expect(shouldUpdate).toBe(true)
})
})

0 comments on commit a2ff2b1

Please sign in to comment.