UNPKG

@empathyco/x-components

Version:
41 lines (38 loc) 1.35 kB
import { defineComponent, computed } from 'vue'; import { useState } from '../../../composables/use-state.js'; import { useXBus } from '../../../composables/use-x-bus.js'; import { extraParamsXModule } from '../x-module.js'; /** * It emits a {@link ExtraParamsXEvents.UserChangedExtraParams} when the `updateValue` * is called. * * @public */ var _sfc_main = defineComponent({ name: 'RenderlessExtraParam', xModule: extraParamsXModule.name, props: { name: { type: String, required: true, }, }, setup(props, { slots }) { const xBus = useXBus(); /** A dictionary with the extra params in the store state. */ const stateParams = useState('extraParams').params; /** It returns the value of the extra param from the store. */ const extraParam = computed(() => stateParams.value[props.name]); /** * It sets the new value to the store. * * @param newValue - The new value of the extra param. */ function updateValue(newValue) { xBus.emit('UserChangedExtraParams', { [props.name]: newValue }); } return () => slots.default?.({ value: extraParam.value, updateValue })[0] ?? ''; }, }); export { _sfc_main as default }; //# sourceMappingURL=renderless-extra-param.vue.js.map