tethys.backend/resources/js/test.ts
Arno Kaimbacher cd66f318b6 - add EventEmmitter for directly binding Events to component
- add NotificationToast for messages
- add leaflet map component and zoom control component
- change focus:ring to focus:ring-2 inside BaseButton
-  `@tailwindcss/line-clamp` plugin is now included by default...remove it from tailwind.config.js
- npm updates
2023-03-31 14:54:15 +02:00

67 lines
2.2 KiB
TypeScript

import type { Directive, Plugin } from 'vue';
import type { EventEmitter } from '@/Components/Map/EventEmitter';
// https://vuejs.org/guide/reusability/custom-directives.html#directive-hooks
// https://learnvue.co/articles/vue-custom-directives
let emitter: EventEmitter<string>;
export const EmitterDirective: Directive<any> = {
mounted: (el, binding, vnode) => {
// el: the element the directive is bound to. This can be used to directly manipulate
binding.arg && el.setAttribute('event', binding.arg);
// const vm = binding.instance;
// let iwas = vm?.$data.onMapInitializedEvent;
// var handlers = (vnode.data && vnode.data.on) ||
// (vnode.componentOptions && vnode.componentOptions.listeners);
//vnode: the underlying VNode representing the bound element.
//binding.instance: The instance of the component where the directive is used.
// const instance = binding.instance;
// if (vnode && vnode.dirs) {
// const instance = vnode.dirs[0].instance;
// }
// binding.value
// arg: 'onMapInitialized'
// dir: {created: ƒ}
// instance: Proxy {__v_skip: true}
// modifiers: {}
// oldValue: undefined
// value: {mapId: 'test', name: 'test'}
const handler = binding.value;
// let instanceComp = binding.instance;
// @ts-ignore
if (vnode.ctx) {
// @ts-ignore
emitter = vnode.ctx.data[binding.arg];
emitter.subscribe(handler);
}
// for (const key in binding.value) {
// const k = key; //kebabCase(key);
// if (!el.hasAttribute(k)) {
// el.setAttribute(k, binding.value[key]);
// }
// }
},
unmounted() {
emitter.unsubscribe();
},
// getSSRProps(binding) {
// /* c8 ignore next */
// if (!binding.value) return {};
// return Object.fromEntries(Object.entries(binding.value).map(([key, value]) => [kebabCase(key), value]));
// },
};
export const EmitterPlugin: Plugin = {
install(app) {
app.directive('bind-event', EmitterDirective);
},
};