@empathyco/x-components
Version:
Empathy X Components
132 lines (129 loc) • 3.93 kB
JavaScript
import { namespacedWireCommit, namespacedWireDispatchWithoutPayload, namespacedWireDispatch } from '../../wiring/namespaced-wires.factory.js';
import { namespacedDebounce } from '../../wiring/namespaced-wires.operators.js';
import { createWiring } from '../../wiring/wiring.utils.js';
/**
* `querySuggestions` {@link XModuleName | XModule name}.
*
* @internal
*/
const moduleName = 'querySuggestions';
/**
* WireCommit for {@link QuerySuggestionsXModule}.
*
* @internal
*/
const wireCommit = namespacedWireCommit(moduleName);
/**
* WireDispatchWithoutPayload for {@link QuerySuggestionsXModule}.
*
* @internal
*/
const wireDispatchWithoutPayload = namespacedWireDispatchWithoutPayload(moduleName);
/**
* WireDispatch for {@link QuerySuggestionsXModule}.
*
* @internal
*/
const wireDispatch = namespacedWireDispatch(moduleName);
/**
* Sets the query-suggestions module query.
*
* @public
*/
const setQuerySuggestionsQuery = wireCommit('setQuery');
/**
* Sets the query-suggestions module query from a selectedQueryPreview's query.
*
* @public
*/
const setQuerySuggestionsQueryFromPreview = wireCommit('setQuery', ({ eventPayload: { query } }) => query);
/**
* Sets the query-suggestions module params from a selectedQueryPreview's extraParams.
*
* @public
*/
const setQuerySuggestionsExtraParamsFromPreview = wireCommit('setParams', ({ eventPayload: { extraParams } }) => extraParams);
/**
* Sets the query suggestions state `params`.
*
* @public
*/
const setQuerySuggestionsExtraParams = wireCommit('setParams');
/**
* Sets the query suggestions state `searchedQueries` with the list of history queries.
*
* @public
*/
const setSearchedQueriesInSuggestions = wireCommit('setSearchedQueries');
/**
* Clears the query-suggestions module query.
*
* @public
*/
const clearQuerySuggestionsQuery = wireCommit('setQuery', '');
/**
* Sets the query-suggestions state `query` from url.
*
* @public
*/
const setUrlParams = wireDispatch('setUrlParams');
/**
* Requests and stores a new set of query suggestions for the query.
*
* @public
*/
const fetchAndSaveSuggestionsWire = wireDispatch('fetchAndSaveSuggestions');
/**
* Cancels the {@link QuerySuggestionsActions.fetchAndSaveSuggestions} request promise.
*
* @public
*/
const cancelFetchAndSaveSuggestionsWire = wireDispatchWithoutPayload('cancelFetchAndSaveSuggestions');
/**
* Debounce function for the module.
*/
const moduleDebounce = namespacedDebounce(moduleName);
/**
* QuerySuggestions wiring.
*
* @internal
*/
const querySuggestionsWiring = createWiring({
ParamsLoadedFromUrl: {
setUrlParams,
},
UserIsTypingAQuery: {
setQuerySuggestionsQueryDebounce: moduleDebounce(setQuerySuggestionsQuery, ({ state }) => state.config.debounceInMs, { cancelOn: 'UserAcceptedAQuery' }),
},
UserAcceptedAQuery: {
setQuerySuggestionsQuery,
},
UserClearedQuery: {
clearQuerySuggestionsQuery,
cancelFetchAndSaveSuggestionsWire,
},
QuerySuggestionsRequestUpdated: {
fetchAndSaveSuggestionsWire,
},
ExtraParamsChanged: {
setQuerySuggestionsExtraParams,
},
UserClickedCloseX: {
clearQuerySuggestionsQuery,
},
UserClickedOutOfMainModal: {
clearQuerySuggestionsQuery,
},
UserAcceptedAQueryPreview: {
setQuerySuggestionsQueryFromPreview,
setQuerySuggestionsExtraParamsFromPreview,
},
QueryPreviewUnselected: {
setQuerySuggestionsExtraParams,
},
SessionHistoryQueriesChanged: {
setSearchedQueriesInSuggestions,
},
});
export { cancelFetchAndSaveSuggestionsWire, clearQuerySuggestionsQuery, fetchAndSaveSuggestionsWire, querySuggestionsWiring, setQuerySuggestionsExtraParams, setQuerySuggestionsExtraParamsFromPreview, setQuerySuggestionsQuery, setQuerySuggestionsQueryFromPreview, setSearchedQueriesInSuggestions };
//# sourceMappingURL=wiring.js.map