Skip to content

Commit

Permalink
refactor(lodash): partial & partialRight (algolia/algoliasearch-helpe…
Browse files Browse the repository at this point in the history
  • Loading branch information
Haroenv committed Nov 18, 2019
1 parent 3814749 commit 9207896
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions packages/algoliasearch-helper/src/SearchResults/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ var merge = require('lodash/merge');

var isFunction = require('lodash/isFunction');

var partial = require('lodash/partial');
var partialRight = require('lodash/partialRight');

var defaultsPure = require('../functions/defaultsPure');
var compact = require('../functions/compact');
var find = require('../functions/find');
Expand Down Expand Up @@ -636,7 +633,9 @@ function recSort(sortFn, node) {
return node;
}

var children = node.data.map(partial(recSort, sortFn));
var children = node.data.map(function(childNode) {
return recSort(sortFn, childNode);
});
var sortedChildren = sortFn(children);
var newNode = merge({}, node, {data: sortedChildren});
return newNode;
Expand Down Expand Up @@ -705,13 +704,17 @@ SearchResults.prototype.getFacetValues = function(attribute, opts) {
return orderBy(facetValues, order[0], order[1]);
}
// If facetValues is not an array, it's an object thus a hierarchical facet object
return recSort(partialRight(orderBy, order[0], order[1]), facetValues);
return recSort(function(hierarchicalFacetValues) {
return orderBy(hierarchicalFacetValues, order[0], order[1]);
}, facetValues);
} else if (isFunction(options.sortBy)) {
if (Array.isArray(facetValues)) {
return facetValues.sort(options.sortBy);
}
// If facetValues is not an array, it's an object thus a hierarchical facet object
return recSort(partial(vanillaSortFn, options.sortBy), facetValues);
return recSort(function(data) {
return vanillaSortFn(options.sortBy, data);
}, facetValues);
}
throw new Error(
'options.sortBy is optional but if defined it must be ' +
Expand Down

0 comments on commit 9207896

Please sign in to comment.