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 isFinite (#2458)
Browse files Browse the repository at this point in the history
* refactor(lodash): replace isFinite

lodash.isFinite is just `typeof value == 'number' && nativeIsFinite(value);`, so that's what I implemented

IFW-745

* chore: remove needless typeof
  • Loading branch information
Haroenv committed May 22, 2019
1 parent 6913f04 commit 4423fa3
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions packages/react-instantsearch-core/src/connectors/connectRange.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { isFinite as _isFinite } from 'lodash';
import PropTypes from 'prop-types';
import createConnector from '../core/createConnector';
import {
Expand Down Expand Up @@ -41,18 +40,18 @@ function getCurrentRange(boundaries, stats, precision) {
const pow = Math.pow(10, precision);

let min;
if (_isFinite(boundaries.min)) {
if (typeof boundaries.min === 'number' && isFinite(boundaries.min)) {
min = boundaries.min;
} else if (_isFinite(stats.min)) {
} else if (typeof stats.min === 'number' && isFinite(stats.min)) {
min = stats.min;
} else {
min = undefined;
}

let max;
if (_isFinite(boundaries.max)) {
if (typeof boundaries.max === 'number' && isFinite(boundaries.max)) {
max = boundaries.max;
} else if (_isFinite(stats.max)) {
} else if (typeof stats.max === 'number' && isFinite(stats.max)) {
max = stats.max;
} else {
max = undefined;
Expand Down Expand Up @@ -151,8 +150,8 @@ function refine(props, searchState, nextRefinement, currentRange, context) {
const nextMinAsNumber = !isMinReset ? parseFloat(nextMin) : undefined;
const nextMaxAsNumber = !isMaxReset ? parseFloat(nextMax) : undefined;

const isNextMinValid = isMinReset || _isFinite(nextMinAsNumber);
const isNextMaxValid = isMaxReset || _isFinite(nextMaxAsNumber);
const isNextMinValid = isMinReset || isFinite(nextMinAsNumber);
const isNextMaxValid = isMaxReset || isFinite(nextMaxAsNumber);

if (!isNextMinValid || !isNextMaxValid) {
throw Error("You can't provide non finite values to the range connector.");
Expand Down

0 comments on commit 4423fa3

Please sign in to comment.