src/lib/utils.js
/**
 * Clears the refinements of a SearchParameters object based on rules provided.
 * The white list is first used then the black list is applied. If no white list
 * is provided, all the current refinements are used.
 * @param {object} $0 parameters
 * @param {Helper} $0.helper instance of the Helper
 * @param {string[]} [$0.whiteList] list of parameters to clear
 * @param {string[]} [$0.blackList=[]] list of parameters not to remove (will impact the white list)
 * @param {boolean} [$0.clearsQuery=false] clears the query if need be
 * @returns {SearchParameters} search parameters with refinements cleared
 */
Clears the refinements of a SearchParameters object based on rules provided.
The white list is first used then the black list is applied. If no white list
is provided, all the current refinements are used.
Clears the refinements of a SearchParameters object based on rules provided . The white list is first used then the black list is applied . If no white list is provided all the current refinements are used .
function clearRefinements({
  helper,
  whiteList,
  blackList = [],
  clearsQuery = false,
}) {
  const attributesToClear = getAttributesToClear({
    helper,
    whiteList,
    blackList,
  });
  let finalState = helper.state;
  attributesToClear.forEach(attribute => {
    if (attribute === '_tags') {
      finalState = finalState.clearTags();
    } else {
      finalState = finalState.clearRefinements(attribute);
    }
  });
  if (clearsQuery) {
    finalState = finalState.setQuery('');
  }
  return finalState;
}
function clearRefinements ( { helper , whiteList , blackList = [ ] , clearsQuery = false , } ) { const attributesToClear = getAttributesToClear ( { helper , whiteList , blackList , } ) ; let finalState = helper . state ; attributesToClear . forEach ( attribute => { if ( attribute === '_tags' ) { finalState = finalState . clearTags ( ) ; } else { finalState = finalState . clearRefinements ( attribute ) ; } } ) ; if ( clearsQuery ) { finalState = finalState . setQuery ( '' ) ; } return finalState ; }
Clears the refinements of a SearchParameters object based on rules provided.
Clears the refinements of a SearchParameters object based on rules provided .