UNPKG

@empathyco/x-components

Version:
48 lines (45 loc) 2.1 kB
import { debounce, throttle } from './wires.operators.js'; import { getStateAndGettersFromModule } from './wiring.utils.js'; /** * Type safe debounce operator which creates a function which can only access the Module of * the {@link https://vuex.vuejs.org/ | Vuex} Store passed as parameter. * * @param moduleName - The {@link XModuleName} to create the operator wire. * @returns A function which creates a wire that uses the {@link debounce} wire operator to * execute the `wire` after the time has passed without invoking it. This debounce time * is given by the execution of the `timeRetrieving` function. * * @public */ function namespacedDebounce(moduleName) { return createNamespacedTimeWireOperator(moduleName, debounce); } /** * Type safe throttle operator which creates a function which can only access the Module of * the {@link https://vuex.vuejs.org/ | Vuex} Store passed as parameter. * * @param moduleName - The {@link XModuleName} to create the operator wire. * @returns A function which creates a wire that uses the {@link throttle} wire operator to * execute the `wire` once every couple of milliseconds. This throttle time is given by * the execution of the `timeRetrieving` function. * * @public */ function namespacedThrottle(moduleName) { return createNamespacedTimeWireOperator(moduleName, throttle); } /** * Creates a function which creates a namespaced wire that uses the {@link debounce} or * {@link throttle} time wire operator. * * @param moduleName - The {@link XModuleName} to create the operator wire. * @param timingOperator - The time wire operator {@link debounce} or {@link throttle}. * @returns A function which creates a namespaced time wire operator. * * @internal */ function createNamespacedTimeWireOperator(moduleName, timingOperator) { return (wire, timeSelector, options) => timingOperator(wire, ({ state, getters }) => timeSelector(getStateAndGettersFromModule(state, getters, moduleName)), options); } export { namespacedDebounce, namespacedThrottle }; //# sourceMappingURL=namespaced-wires.operators.js.map