From 5d38adc4513931c5dfa25121fce4a4c1502f7aec Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Fri, 17 May 2019 17:17:01 +0200 Subject: [PATCH 1/2] refactor(lodash): replace isEqual 1. specified function for maps IFW-735 --- .../src/Connector.js | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/packages/react-instantsearch-dom-maps/src/Connector.js b/packages/react-instantsearch-dom-maps/src/Connector.js index 39e3eb81e8..96bc4c4c1e 100644 --- a/packages/react-instantsearch-dom-maps/src/Connector.js +++ b/packages/react-instantsearch-dom-maps/src/Connector.js @@ -1,10 +1,26 @@ -import { isEqual } from 'lodash'; import { Component } from 'react'; import { polyfill } from 'react-lifecycles-compat'; import PropTypes from 'prop-types'; import { connectGeoSearch } from 'react-instantsearch-dom'; import { LatLngPropType, BoundingBoxPropType } from './propTypes'; +function isEqualPosition(a, b) { + if (a === b) { + return true; + } + return a.lat === b.lat && a.lng === b.lng; +} + +function isEqualCurrentRefinement(a, b) { + if (a === b) { + return true; + } + return ( + isEqualPosition(a.northEast, b.northEast) && + isEqualPosition(a.southWest, b.southWest) + ); +} + export class Connector extends Component { static propTypes = { hits: PropTypes.arrayOf(PropTypes.object).isRequired, @@ -20,8 +36,8 @@ export class Connector extends Component { const { position, currentRefinement } = props; const { previousPosition, previousCurrentRefinement } = state; - const positionChanged = !isEqual(previousPosition, position); - const currentRefinementChanged = !isEqual( + const positionChanged = !isEqualPosition(previousPosition, position); + const currentRefinementChanged = !isEqualCurrentRefinement( previousCurrentRefinement, currentRefinement ); From 17c9d736c00162947b1f67b7f8b73abe5a04f0df Mon Sep 17 00:00:00 2001 From: Haroen Viaene Date: Fri, 17 May 2019 17:32:36 +0200 Subject: [PATCH 2/2] refactor(lodash): replace isEqual with fast-deep-equal --- packages/react-instantsearch-core/package.json | 1 + packages/react-instantsearch-core/src/core/createConnector.tsx | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/react-instantsearch-core/package.json b/packages/react-instantsearch-core/package.json index 8818210d66..897b8e088f 100644 --- a/packages/react-instantsearch-core/package.json +++ b/packages/react-instantsearch-core/package.json @@ -40,6 +40,7 @@ "dependencies": { "@babel/runtime": "^7.1.2", "algoliasearch-helper": "^2.26.0", + "fast-deep-equal": "^2.0.1", "lodash": "^4.17.4", "prop-types": "^15.5.10" }, diff --git a/packages/react-instantsearch-core/src/core/createConnector.tsx b/packages/react-instantsearch-core/src/core/createConnector.tsx index f0862c9cbc..7bfaeb6390 100644 --- a/packages/react-instantsearch-core/src/core/createConnector.tsx +++ b/packages/react-instantsearch-core/src/core/createConnector.tsx @@ -1,5 +1,5 @@ -import { isEqual } from 'lodash'; import React, { Component, ReactType } from 'react'; +import isEqual from 'fast-deep-equal'; import { shallowEqual, getDisplayName, removeEmptyKey } from './utils'; import { InstantSearchConsumer,