Skip to content

Commit

Permalink
fix(numeric-refinement): Replace Array.find with lodash find/includes
Browse files Browse the repository at this point in the history
`Array.protoype.find` does not have a large enough support. Let's use
lodash instead.
  • Loading branch information
pixelastic committed Nov 6, 2015
1 parent e7cdb02 commit b3e815c
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions widgets/numeric-refinement-list/numeric-refinement-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ let ReactDOM = require('react-dom');
let utils = require('../../lib/utils.js');
let bem = utils.bemHelper('ais-refinement-list');
let cx = require('classnames');
let find = require('lodash/collection/find');
let includes = require('lodash/collection/includes');

let autoHideContainerHOC = require('../../decorators/autoHideContainer');
let headerFooterHOC = require('../../decorators/headerFooter');
Expand Down Expand Up @@ -131,9 +133,7 @@ function isRefined(state, attributeName, option) {
}

function refine(state, attributeName, options, facetValue) {
let refinedOption = options.find(function(option) {
return option.name === facetValue;
});
let refinedOption = find(options, {name: facetValue});

let currentRefinements = state.getNumericRefinements(attributeName);

Expand Down Expand Up @@ -181,10 +181,9 @@ function refine(state, attributeName, options, facetValue) {

function hasNumericRefinement(currentRefinements, operator, value) {
let hasOperatorRefinements = currentRefinements[operator] !== undefined;
let includesValue = includes(currentRefinements[operator], value);

return hasOperatorRefinements && currentRefinements[operator].find(function(refinement) {
return refinement === value;
}) !== undefined;
return hasOperatorRefinements && includesValue;
}

module.exports = numericRefinementList;

0 comments on commit b3e815c

Please sign in to comment.