Skip to content

Commit

Permalink
[fix] Use 'deep-equal' to compare whether arrays are equal
Browse files Browse the repository at this point in the history
Using `JSON.stringify()`, when a marker has a popup created with `L.popup()`,
rather than a straight string, then the following error is thrown:

    Uncaught TypeError: Converting circular structure to JSON
        at JSON.stringify (<anonymous>)
        at isArraysEqual

See #55
  • Loading branch information
rm-hull authored and yuzhva committed Jan 27, 2018
1 parent e6f8208 commit 8df6be6
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 7 deletions.
8 changes: 6 additions & 2 deletions dist/react-leaflet-markercluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ var _leaflet = require('leaflet');

var _leaflet2 = _interopRequireDefault(_leaflet);

var _deepEqual = require('deep-equal');

var _deepEqual2 = _interopRequireDefault(_deepEqual);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
Expand All @@ -42,7 +46,7 @@ function havingDeprecatedProps(markers) {

// NOTE: Helpers
function isArraysEqual(firstArray, secondArray) {
return JSON.stringify(firstArray) === JSON.stringify(secondArray);
return firstArray.length === secondArray.length && (0, _deepEqual2.default)(firstArray, secondArray);
}

function removeMarkersWithSameCoordinates(markers) {
Expand Down Expand Up @@ -252,4 +256,4 @@ MarkerClusterGroup.propTypes = {

MarkerClusterGroup.defaultProps = {
markers: []
};
};
2 changes: 1 addition & 1 deletion dist/react-leaflet-markercluster.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,8 @@
"prop-types": "^15.5.7",
"react": "^15.0.0 || ^16.0.0",
"react-leaflet": "^1.4.0"
},
"dependencies": {
"deep-equal": "^1.0.1"
}
}
3 changes: 2 additions & 1 deletion src/react-leaflet-markercluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import PropTypes from 'prop-types';

import { LayerGroup } from 'react-leaflet';
import L from 'leaflet';
import deepEqual from 'deep-equal';

require('leaflet.markercluster');

Expand All @@ -16,7 +17,7 @@ function havingDeprecatedProps(markers) {

// NOTE: Helpers
function isArraysEqual(firstArray, secondArray) {
return (JSON.stringify(firstArray) === JSON.stringify(secondArray));
return firstArray.length === secondArray.length && deepEqual(firstArray, secondArray);
}

function removeMarkersWithSameCoordinates(markers) {
Expand Down

0 comments on commit 8df6be6

Please sign in to comment.