-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
117 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import mitt, { Emitter } from 'mitt'; | ||
import { EventMap } from './types'; | ||
|
||
const emitter: Emitter<EventMap> = mitt<EventMap>(); | ||
export default emitter; | ||
|
||
/** | ||
* Emits an event with the given name and data. | ||
* @param eventName - The name of the event. | ||
* @param data - The data to emit with the event. | ||
*/ | ||
export function eventEmit<T extends keyof EventMap>( | ||
eventName: T, | ||
data?: EventMap[T] | ||
): void { | ||
emitter.emit(eventName, data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
import { EventType } from 'mitt'; | ||
|
||
export type EventMap = Record<EventType, unknown>; | ||
export type EventCallback = (...args: any[]) => void; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import emitter from './emitter'; | ||
import { ComponentOptions } from 'vue'; | ||
import { EventCallback } from './types'; | ||
|
||
/** | ||
* Provides Vue 2 mixins for registering event listeners. | ||
* @param event - The event name to listen for. | ||
* @param callback - The callback to invoke when the event is emitted. | ||
* @returns A Vue mixin with `created` and `beforeDestroy` hooks. | ||
*/ | ||
export function useEventListener( | ||
event: string, | ||
callback: EventCallback | ||
): ComponentOptions { | ||
return { | ||
created() { | ||
emitter.on(event, callback.bind(this)); | ||
}, | ||
beforeDestroy() { | ||
emitter.off(event, callback.bind(this)); | ||
}, | ||
}; | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import emitter from './emitter'; | ||
import { onMounted, onUnmounted } from 'vue'; | ||
import { EventCallback } from './types'; | ||
|
||
/** | ||
* Registers event listeners for Vue 3 using lifecycle hooks. | ||
* @param event - The event name to listen for. | ||
* @param callback - The callback to invoke when the event is emitted. | ||
*/ | ||
export function useEventListener(event: string, callback: EventCallback): void { | ||
onMounted(() => { | ||
emitter.on(event, callback); | ||
}); | ||
|
||
onUnmounted(() => { | ||
emitter.off(event, callback); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"lib": ["esnext", "dom"], | ||
"target": "es6", | ||
"module": "commonjs", | ||
"moduleResolution": "node", | ||
"outDir": "./dist", | ||
"strict": true, | ||
"esModuleInterop": true, | ||
"declaration": true, | ||
"sourceMap": true, | ||
"skipLibCheck": true, | ||
"resolveJsonModule": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"include": ["src/**/*"], | ||
"exclude": ["node_modules", "dist"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters