chore: complete update
This commit is contained in:
23
resources/js/core/useEvent.js
Normal file
23
resources/js/core/useEvent.js
Normal file
@@ -0,0 +1,23 @@
|
||||
// modules/core/useEvent.js
|
||||
import { EventManager } from './EventManager.js';
|
||||
|
||||
/**
|
||||
* Vereinfachte Kurzform zur Registrierung eines EventListeners
|
||||
*
|
||||
* @param {EventTarget} target - Das Element, auf das der Event gehört
|
||||
* @param {string} type - Der Eventtyp (z.B. 'click')
|
||||
* @param {Function} handler - Die Callback-Funktion
|
||||
* @param {object} meta - Optionen oder automatisch aus `import.meta` (optional)
|
||||
* @param {Object|boolean} options - EventListener-Optionen
|
||||
*/
|
||||
export function useEvent(target, type, handler, meta = import.meta, options = false) {
|
||||
const module = typeof meta === 'string'
|
||||
? meta
|
||||
: (meta.url?.split('/').slice(-2, -1)[0] || 'unknown');
|
||||
|
||||
EventManager.add(target, type, handler, { module, options });
|
||||
|
||||
return () => {
|
||||
EventManager.removeModule(module);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user