From 5077b3af1cfefcc668e6391f7d84172ec90eca35 Mon Sep 17 00:00:00 2001 From: deadkff01 Date: Sun, 27 Jan 2019 23:05:22 -0200 Subject: [PATCH 1/3] fix marker rerender --- src/components/Marker.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/Marker.js b/src/components/Marker.js index 0b233241..5f3846be 100644 --- a/src/components/Marker.js +++ b/src/components/Marker.js @@ -36,7 +36,9 @@ export class Marker extends React.Component { componentDidUpdate(prevProps) { if ((this.props.map !== prevProps.map) || - (this.props.position !== prevProps.position) || + ((this.props.position && prevProps.position) + ? this.props.position.lat !== prevProps.position.lat || this.props.position.lng !== prevProps.position.lng + : this.props.position !== prevProps.position) || (this.props.icon !== prevProps.icon)) { if (this.marker) { this.marker.setMap(null); From c71e463289b4dfb19af06148c7e1a7348277660b Mon Sep 17 00:00:00 2001 From: deadkff01 Date: Thu, 3 Sep 2020 00:03:54 -0300 Subject: [PATCH 2/3] feat(Marker): add verify marker position function --- dist/components/Marker.js | 2 +- src/components/Marker.js | 9 ++++----- src/lib/verifyMarkerPosition.js | 6 ++++++ 3 files changed, 11 insertions(+), 6 deletions(-) create mode 100644 src/lib/verifyMarkerPosition.js diff --git a/dist/components/Marker.js b/dist/components/Marker.js index 7cc80544..bdbe3adf 100644 --- a/dist/components/Marker.js +++ b/dist/components/Marker.js @@ -135,7 +135,7 @@ }, { key: 'componentDidUpdate', value: function componentDidUpdate(prevProps) { - if (this.props.map !== prevProps.map || this.props.position !== prevProps.position || this.props.icon !== prevProps.icon) { + if (this.props.map !== prevProps.map || (this.props.position && prevProps.position ? this.props.position.lat !== prevProps.position.lat || this.props.position.lng !== prevProps.position.lng : this.props.position !== prevProps.position) || this.props.icon !== prevProps.icon) { if (this.marker) { this.marker.setMap(null); } diff --git a/src/components/Marker.js b/src/components/Marker.js index 5f3846be..5cde2119 100644 --- a/src/components/Marker.js +++ b/src/components/Marker.js @@ -2,6 +2,7 @@ import React from 'react' import PropTypes from 'prop-types' import { camelize } from '../lib/String' +import { verifyMarkerPosition } from '../lib/verifyMarkerPosition' const evtNames = [ 'click', @@ -35,11 +36,9 @@ export class Marker extends React.Component { } componentDidUpdate(prevProps) { - if ((this.props.map !== prevProps.map) || - ((this.props.position && prevProps.position) - ? this.props.position.lat !== prevProps.position.lat || this.props.position.lng !== prevProps.position.lng - : this.props.position !== prevProps.position) || - (this.props.icon !== prevProps.icon)) { + if (this.props.map !== prevProps.map || + this.props.icon !== prevProps.icon || + verifyMarkerPosition(this.props.position, prevProps.position)) { if (this.marker) { this.marker.setMap(null); } diff --git a/src/lib/verifyMarkerPosition.js b/src/lib/verifyMarkerPosition.js new file mode 100644 index 00000000..7b2acc64 --- /dev/null +++ b/src/lib/verifyMarkerPosition.js @@ -0,0 +1,6 @@ +export function verifyMarkerPosition(currentPosition, prevPosition) { + if(currentPosition && prevPosition) { + return currentPosition.lat !== prevPosition.lat || currentPosition.lng !== prevPosition.lng; + } + return false; +} \ No newline at end of file From c152ceeb905763640b89d435951485c5b2800e52 Mon Sep 17 00:00:00 2001 From: deadkff01 Date: Thu, 3 Sep 2020 00:06:19 -0300 Subject: [PATCH 3/3] feat(Marker): add verify marker position function --- src/lib/verifyMarkerPosition.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/verifyMarkerPosition.js b/src/lib/verifyMarkerPosition.js index 7b2acc64..11ae30a7 100644 --- a/src/lib/verifyMarkerPosition.js +++ b/src/lib/verifyMarkerPosition.js @@ -3,4 +3,4 @@ export function verifyMarkerPosition(currentPosition, prevPosition) { return currentPosition.lat !== prevPosition.lat || currentPosition.lng !== prevPosition.lng; } return false; -} \ No newline at end of file +}