diff --git a/examples/react-native/src/Rating.js b/examples/react-native/src/Rating.js index 6c6e54c238..2deea684fc 100644 --- a/examples/react-native/src/Rating.js +++ b/examples/react-native/src/Rating.js @@ -16,7 +16,6 @@ import { connectMenu, } from 'react-instantsearch/connectors'; import Stats from './components/Stats'; -import { isEmpty } from 'lodash'; const styles = StyleSheet.create({ mainContainer: { @@ -146,7 +145,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/package.json b/package.json index a20c0ed4c0..36c5208cac 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ }, { "path": "packages/react-instantsearch-core/dist/umd/ReactInstantSearchCore.min.js", - "maxSize": "42 kB" + "maxSize": "42.25 kB" }, { "path": "packages/react-instantsearch-dom/dist/umd/ReactInstantSearchDOM.min.js", 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 af8eddfcb8..bb1e42779c 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 bdcf45d510..15c5b0e91a 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 = algoliasearch => { const helper = algoliasearchHelper(client, sharedParameters.index); - if (isEmpty(derivedParameters)) { + if (Object.keys(derivedParameters).length === 0) { return singleIndexSearch(helper, sharedParameters); }