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

refactor(lodash): replace isEqual #2467

Merged
merged 2 commits into from
May 20, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have fast-deep-equal inside the package since it's already used in core. I would have leverage it rather than this two custom functions. The simpler, the better.

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