@empathyco/x-components
Version:
Empathy X Components
34 lines (31 loc) • 1.38 kB
JavaScript
import { DefaultResultsEnrichmentService } from '../../../../services/results-enrichment.service.js';
import { createFetchAndSaveActions } from '../../../../store/utils/fetch-and-save-action.utils.js';
const { fetchAndSave, cancelPrevious } = createFetchAndSaveActions({
async fetch(_, partialResults) {
const results = partialResults.flatMap(partialResult => partialResult.results ?? []);
const resultSet = new Set();
const uniqueResults = results.filter(result => resultSet.has(result.id) ? false : resultSet.add(result.id));
return uniqueResults.length > 0
? DefaultResultsEnrichmentService.instance.fetchResults(uniqueResults)
: [];
},
onSuccess({ commit }, enrichmentResults) {
commit('updatePartialResultsFromEnrichment', enrichmentResults);
},
});
/**
* Default implementation for {@link SearchActions.fetchAndSavePartialResultsEnrichment}
* action.
*
* @public
*/
const fetchAndSavePartialResultsEnrichment = fetchAndSave;
/**
* Default implementation for {@link SearchActions.cancelFetchAndSavePartialResultsEnrichment}
* action.
*
* @public
*/
const cancelFetchAndSavePartialResultsEnrichment = cancelPrevious;
export { cancelFetchAndSavePartialResultsEnrichment, fetchAndSavePartialResultsEnrichment };
//# sourceMappingURL=fetch-and-save-partial-results-enrichment.action.js.map