@empathyco/x-components
Version:
Empathy X Components
137 lines (134 loc) • 3.86 kB
JavaScript
import { namespacedWireCommit, namespacedWireCommitWithoutPayload, namespacedWireDispatch } from '../../wiring/namespaced-wires.factory.js';
import { createWiring } from '../../wiring/wiring.utils.js';
/**
* `nextQueries` {@link XModuleName | XModule name}.
*
* @internal
*/
const moduleName = 'nextQueries';
/**
* WireCommit for {@link NextQueriesXModule}.
*
* @internal
*/
const wireCommit = namespacedWireCommit(moduleName);
/**
* WireCommitWithoutPayload for {@link NextQueriesXModule}.
*/
const wireCommitWithoutPayload = namespacedWireCommitWithoutPayload(moduleName);
/**
* WireDispatch for {@link NextQueriesXModule}.
*
* @internal
*/
const wireDispatch = namespacedWireDispatch(moduleName);
/**
* Sets the next queries state `query`.
*
* @public
*/
const setNextQueriesQuery = wireCommit('setQuery');
/**
* Sets the next queries state `relatedTags`.
*
* @public
*/
const setNextQueriesRelatedTags = wireCommit('setRelatedTags');
/**
* Sets the next queries state `query` with a selectedQueryPreview's query.
*
* @public
*/
const setNextQueriesQueryFromPreview = wireCommit('setParams', ({ eventPayload: { query } }) => query);
/**
* Sets the next queries state `query` from url.
*
* @public
*/
const setUrlParams = wireDispatch('setUrlParams');
/**
* Sets the next queries state `params`.
*
* @public
*/
const setNextQueriesExtraParams = wireCommit('setParams');
/**
* Sets the next queries state `params` with a selectedQueryPreview's extraParams.
*
* @public
*/
const setNextQueriesExtraParamsFromPreview = wireCommit('setParams', ({ eventPayload: { extraParams } }) => extraParams);
/**
* Requests and stores the next queries.
*
* @public
*/
const fetchAndSaveNextQueriesWire = wireDispatch('fetchAndSaveNextQueries');
/**
* Sets the next queries state `query` with the last query in history queries.
*
* @public
*/
const setQueryFromLastHistoryQueryWire = wireDispatch('setQueryFromLastHistoryQuery');
/**
* Requests and store the next query preview results.
*
* @public
*/
const fetchAndSaveNextQueryPreviewWire = wireDispatch('fetchAndSaveNextQueryPreview', ({ eventPayload: query, metadata: { location } }) => {
return {
query,
location,
};
});
/**
* Resets the next query preview results.
*
* @public
*/
const resetResultsPreviewWire = wireCommitWithoutPayload('resetResultsPreview');
/**
* Sets the next queries state `searchedQueries` with the list of history queries.
*
* @public
*/
const setSearchedQueries = wireCommit('setSearchedQueries');
/**
* Wiring configuration for the {@link NextQueriesXModule | next queries module}.
*
* @internal
*/
const nextQueriesWiring = createWiring({
ParamsLoadedFromUrl: {
setUrlParams,
},
NextQueriesChanged: {
resetResultsPreviewWire,
},
UserAcceptedAQuery: {
setNextQueriesQuery,
},
SelectedRelatedTagsChanged: {
setNextQueriesRelatedTags,
},
SessionHistoryQueriesChanged: {
setSearchedQueries,
// TODO setQueryFromLastHistoryQuery it has to be called only one time
setQueryFromLastHistoryQueryWire,
},
NextQueriesRequestUpdated: {
fetchAndSaveNextQueriesWire,
},
ExtraParamsChanged: {
setNextQueriesExtraParams,
},
NextQueryPreviewMountedHook: {
fetchAndSaveNextQueryPreviewWire,
},
UserAcceptedAQueryPreview: {
setNextQueriesQueryFromPreview,
setNextQueriesExtraParamsFromPreview,
},
});
export { fetchAndSaveNextQueriesWire, fetchAndSaveNextQueryPreviewWire, nextQueriesWiring, resetResultsPreviewWire, setNextQueriesExtraParams, setNextQueriesExtraParamsFromPreview, setNextQueriesQuery, setNextQueriesQueryFromPreview, setNextQueriesRelatedTags, setQueryFromLastHistoryQueryWire, setSearchedQueries };
//# sourceMappingURL=wiring.js.map