UNPKG

@empathyco/x-components

Version:
34 lines (31 loc) 1.38 kB
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