Skip to content
This repository has been archived by the owner on Dec 30, 2022. It is now read-only.

Commit

Permalink
refactor(lodash): replace isEqual (#2467)
Browse files Browse the repository at this point in the history
* refactor(lodash): replace isEqual

1. specified function for maps

IFW-735

* refactor(lodash): replace isEqual with fast-deep-equal
  • Loading branch information
Haroenv committed Jun 27, 2019
1 parent 75a4a15 commit 1c573b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
1 change: 1 addition & 0 deletions packages/react-instantsearch-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
22 changes: 19 additions & 3 deletions packages/react-instantsearch-dom-maps/src/Connector.js
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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
);
Expand Down

0 comments on commit 1c573b7

Please sign in to comment.