mirror of
https://github.com/nasa/openmct.git
synced 2024-12-21 06:03:08 +00:00
feat: add useEventListener
composable
This commit is contained in:
parent
715a44864e
commit
f5d57374fb
18
src/ui/composables/event.js
Normal file
18
src/ui/composables/event.js
Normal file
@ -0,0 +1,18 @@
|
||||
import { onBeforeMount, onBeforeUnmount } from 'vue';
|
||||
|
||||
/**
|
||||
* @param {*} api the specific openmct API to use i.e. openmct.editor
|
||||
* @param {string} eventName
|
||||
* @param {() => void} handler
|
||||
*/
|
||||
export function useEventListener(api, eventName, handler) {
|
||||
onBeforeMount(() => {
|
||||
// Add the event listener before the component is mounted
|
||||
api.on(eventName, handler);
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
// Remove the event listener before the component is unmounted
|
||||
api.off(eventName, handler);
|
||||
});
|
||||
}
|
Loading…
Reference in New Issue
Block a user