diff --git a/examples/react-native/src/Rating.js b/examples/react-native/src/Rating.js index 31d605428e..782ab4b3cf 100644 --- a/examples/react-native/src/Rating.js +++ b/examples/react-native/src/Rating.js @@ -17,7 +17,6 @@ import { connectMenu, } from 'react-instantsearch/connectors'; import Stats from './components/Stats'; -import { isEmpty } from 'lodash'; const searchClient = algoliasearch( 'latency', @@ -151,7 +150,8 @@ class Rating extends Component { const { refine, min, max, count, createURL } = this.props; const items = []; for (let i = max; i >= min; i--) { - const hasCount = !isEmpty(count.filter(item => Number(item.value) === i)); + const hasCount = + count.filter(item => Number(item.value) === i).length > 0; const lastSelectableItem = count.reduce( (acc, item) => item.value < acc.value || (!acc.value && hasCount) ? item : acc, diff --git a/packages/react-instantsearch-core/src/connectors/connectGeoSearch.js b/packages/react-instantsearch-core/src/connectors/connectGeoSearch.js index 16b6fd06fc..c8eac4ad4c 100644 --- a/packages/react-instantsearch-core/src/connectors/connectGeoSearch.js +++ b/packages/react-instantsearch-core/src/connectors/connectGeoSearch.js @@ -1,4 +1,4 @@ -import { isEmpty } from 'lodash'; +import { objectHasKeys } from '../core/utils'; import createConnector from '../core/createConnector'; import { getResults, @@ -73,7 +73,7 @@ const getCurrentRefinement = (props, searchState, context) => { {} ); - if (isEmpty(refinement)) { + if (!objectHasKeys(refinement)) { return; } diff --git a/packages/react-instantsearch-core/src/connectors/connectNumericMenu.js b/packages/react-instantsearch-core/src/connectors/connectNumericMenu.js index 67c8e724ee..f93a453251 100644 --- a/packages/react-instantsearch-core/src/connectors/connectNumericMenu.js +++ b/packages/react-instantsearch-core/src/connectors/connectNumericMenu.js @@ -1,4 +1,3 @@ -import { isEmpty } from 'lodash'; import PropTypes from 'prop-types'; import createConnector from '../core/createConnector'; import { find } from '../core/utils'; @@ -157,7 +156,7 @@ export default createConnector({ if (!items.some(item => item.value === '')) { items.push({ value: '', - isRefined: isEmpty(refinedItem), + isRefined: refinedItem === undefined, noRefinement: !stats, label: 'All', }); diff --git a/packages/react-instantsearch-core/src/core/utils.ts b/packages/react-instantsearch-core/src/core/utils.ts index ff6a297e8a..6d9cf12c75 100644 --- a/packages/react-instantsearch-core/src/core/utils.ts +++ b/packages/react-instantsearch-core/src/core/utils.ts @@ -1,5 +1,3 @@ -import { isEmpty } from 'lodash'; - // From https://github.com/reactjs/react-redux/blob/master/src/utils/shallowEqual.js export const shallowEqual = (objA, objB) => { if (objA === objB) { @@ -43,7 +41,7 @@ export const removeEmptyKey = (obj: object) => { return; } - if (isEmpty(value)) { + if (!objectHasKeys(value)) { delete obj[key]; } else { removeEmptyKey(value); @@ -86,6 +84,10 @@ export function find( return undefined; } +export function objectHasKeys(object: object | undefined) { + return object && Object.keys(object).length > 0; +} + // https://github.com/babel/babel/blob/3aaafae053fa75febb3aa45d45b6f00646e30ba4/packages/babel-helpers/src/helpers.js#L604-L620 export function omit(source: { [key: string]: any }, excluded: string[]) { if (source === null || source === undefined) { diff --git a/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js b/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js index e9c03d7e2c..84db107a67 100644 --- a/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js +++ b/packages/react-instantsearch-dom/src/core/createInstantSearchServer.js @@ -1,4 +1,3 @@ -import { isEmpty } from 'lodash'; import React, { Component } from 'react'; import { renderToString } from 'react-dom/server'; import PropTypes from 'prop-types'; @@ -116,7 +115,7 @@ const createInstantSearchServer = () => { const helper = algoliasearchHelper(client, sharedParameters.index); - if (isEmpty(derivedParameters)) { + if (Object.keys(derivedParameters).length === 0) { return singleIndexSearch(helper, sharedParameters); }