Skip to content

Commit b3e815c

Browse files
committed
fix(numeric-refinement): Replace Array.find with lodash find/includes
`Array.protoype.find` does not have a large enough support. Let's use lodash instead.
1 parent e7cdb02 commit b3e815c

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

widgets/numeric-refinement-list/numeric-refinement-list.js

+5-6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ let ReactDOM = require('react-dom');
44
let utils = require('../../lib/utils.js');
55
let bem = utils.bemHelper('ais-refinement-list');
66
let cx = require('classnames');
7+
let find = require('lodash/collection/find');
8+
let includes = require('lodash/collection/includes');
79

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

133135
function refine(state, attributeName, options, facetValue) {
134-
let refinedOption = options.find(function(option) {
135-
return option.name === facetValue;
136-
});
136+
let refinedOption = find(options, {name: facetValue});
137137

138138
let currentRefinements = state.getNumericRefinements(attributeName);
139139

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

182182
function hasNumericRefinement(currentRefinements, operator, value) {
183183
let hasOperatorRefinements = currentRefinements[operator] !== undefined;
184+
let includesValue = includes(currentRefinements[operator], value);
184185

185-
return hasOperatorRefinements && currentRefinements[operator].find(function(refinement) {
186-
return refinement === value;
187-
}) !== undefined;
186+
return hasOperatorRefinements && includesValue;
188187
}
189188

190189
module.exports = numericRefinementList;

0 commit comments

Comments
 (0)