@empathyco/x-components
Version:
Empathy X Components
51 lines (48 loc) • 1.92 kB
JavaScript
import { normalizeString } from '../../../../utils/normalize.js';
/**
* Class implementation for the {@link HistoryQueriesGetters.historyQueries} getter.
*
* @public
*/
class HistoryQueriesGetter {
/**
* Default implementation for the {@link HistoryQueriesGetters.historyQueries} getter.
*
* @param state - Current {@link https://vuex.vuejs.org/guide/state.html | state} of the history
* queries module.
* @returns The filtered subset of queries, matching with the current query.
*/
historyQueries({ query, historyQueries, config }) {
return query
? historyQueries.filter(this.searchInHistoryQueries(normalizeString(query), config.hideIfEqualsQuery))
: historyQueries;
}
/**
* Creates a function for searching in the history queries array the items that match the current
* query.
*
* @param normalizedQuery - The normalized query for search into the array.
* @param hideIfEqualsQuery - If `true`, removes items that are exactly like the current query.
* @returns A filter function for searching into the array of history queries with the provided
* params.
* @internal
*/
searchInHistoryQueries(normalizedQuery, hideIfEqualsQuery) {
return (historyQuery) => {
const normalizedHistoryQuery = normalizeString(historyQuery.query);
const matchesQuery = normalizedHistoryQuery.includes(normalizedQuery);
return hideIfEqualsQuery
? matchesQuery && normalizedHistoryQuery !== normalizedQuery
: matchesQuery;
};
}
}
const historyQueriesGetter = new HistoryQueriesGetter();
/**
* History Queries getter.
*
* @public
*/
const historyQueries = historyQueriesGetter.historyQueries.bind(historyQueriesGetter);
export { HistoryQueriesGetter, historyQueries };
//# sourceMappingURL=history-queries.getter.js.map