vue3-event-bus-plugin 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,89 @@
1
+ // Type definitions for vue3-event-bus-plugin
2
+ // Project: https://github.com/fyh-mengxiang/vue3-plugins
3
+ // Definitions by: fyh-mengxiang <fuyunhouazsj@aliyun.com>
4
+
5
+ import { App } from 'vue';
6
+
7
+ interface EventBusOptions {
8
+ enableCache?: boolean;
9
+ maxCacheSize?: number;
10
+ clearCacheAfterSubscribe?: boolean;
11
+ }
12
+
13
+ interface EventBus {
14
+ /**
15
+ * Subscribe to an event
16
+ * @param eventName Event name
17
+ * @param callback Callback function
18
+ * @param options Optional configuration
19
+ * @returns Unsubscribe function
20
+ */
21
+ on(eventName: string, callback: (...args: any[]) => void, options?: { once?: boolean }): () => void;
22
+
23
+ /**
24
+ * Subscribe to an event once
25
+ * @param eventName Event name
26
+ * @param callback Callback function
27
+ * @returns Unsubscribe function
28
+ */
29
+ once(eventName: string, callback: (...args: any[]) => void): () => void;
30
+
31
+ /**
32
+ * Unsubscribe from an event
33
+ * @param eventName Event name
34
+ * @param callback Optional callback function to unsubscribe
35
+ */
36
+ off(eventName: string, callback?: (...args: any[]) => void): void;
37
+
38
+ /**
39
+ * Emit an event
40
+ * @param eventName Event name
41
+ * @param args Arguments to pass to listeners
42
+ */
43
+ emit(eventName: string, ...args: any[]): void;
44
+
45
+ /**
46
+ * Get the number of listeners for an event
47
+ * @param eventName Event name
48
+ * @returns Number of listeners
49
+ */
50
+ listenerCount(eventName: string): number;
51
+
52
+ /**
53
+ * Get all event names
54
+ * @returns Array of event names
55
+ */
56
+ getEvents(): string[];
57
+
58
+ /**
59
+ * Clear all event listeners
60
+ */
61
+ clear(): void;
62
+ }
63
+
64
+ interface EventBusPluginOptions {
65
+ debug?: boolean;
66
+ eventBusOptions?: EventBusOptions;
67
+ }
68
+
69
+ interface EventBusPlugin {
70
+ install: (app: App, options?: EventBusPluginOptions) => void;
71
+ }
72
+
73
+ declare const eventBus: EventBus;
74
+
75
+ declare class EventBusClass implements EventBus {
76
+ constructor(options?: EventBusOptions);
77
+ on(eventName: string, callback: (...args: any[]) => void, options?: { once?: boolean }): () => void;
78
+ once(eventName: string, callback: (...args: any[]) => void): () => void;
79
+ off(eventName: string, callback?: (...args: any[]) => void): void;
80
+ emit(eventName: string, ...args: any[]): void;
81
+ listenerCount(eventName: string): number;
82
+ getEvents(): string[];
83
+ clear(): void;
84
+ }
85
+
86
+ declare const _default: EventBusPlugin;
87
+
88
+ export default _default;
89
+ export { eventBus, EventBusClass as EventBus };
package/index.d.ts ADDED
@@ -0,0 +1,89 @@
1
+ // Type definitions for vue3-event-bus-plugin
2
+ // Project: https://github.com/fyh-mengxiang/vue3-plugins
3
+ // Definitions by: fyh-mengxiang <fuyunhouazsj@aliyun.com>
4
+
5
+ import { App } from 'vue';
6
+
7
+ interface EventBusOptions {
8
+ enableCache?: boolean;
9
+ maxCacheSize?: number;
10
+ clearCacheAfterSubscribe?: boolean;
11
+ }
12
+
13
+ interface EventBus {
14
+ /**
15
+ * Subscribe to an event
16
+ * @param eventName Event name
17
+ * @param callback Callback function
18
+ * @param options Optional configuration
19
+ * @returns Unsubscribe function
20
+ */
21
+ on(eventName: string, callback: (...args: any[]) => void, options?: { once?: boolean }): () => void;
22
+
23
+ /**
24
+ * Subscribe to an event once
25
+ * @param eventName Event name
26
+ * @param callback Callback function
27
+ * @returns Unsubscribe function
28
+ */
29
+ once(eventName: string, callback: (...args: any[]) => void): () => void;
30
+
31
+ /**
32
+ * Unsubscribe from an event
33
+ * @param eventName Event name
34
+ * @param callback Optional callback function to unsubscribe
35
+ */
36
+ off(eventName: string, callback?: (...args: any[]) => void): void;
37
+
38
+ /**
39
+ * Emit an event
40
+ * @param eventName Event name
41
+ * @param args Arguments to pass to listeners
42
+ */
43
+ emit(eventName: string, ...args: any[]): void;
44
+
45
+ /**
46
+ * Get the number of listeners for an event
47
+ * @param eventName Event name
48
+ * @returns Number of listeners
49
+ */
50
+ listenerCount(eventName: string): number;
51
+
52
+ /**
53
+ * Get all event names
54
+ * @returns Array of event names
55
+ */
56
+ getEvents(): string[];
57
+
58
+ /**
59
+ * Clear all event listeners
60
+ */
61
+ clear(): void;
62
+ }
63
+
64
+ interface EventBusPluginOptions {
65
+ debug?: boolean;
66
+ eventBusOptions?: EventBusOptions;
67
+ }
68
+
69
+ interface EventBusPlugin {
70
+ install: (app: App, options?: EventBusPluginOptions) => void;
71
+ }
72
+
73
+ declare const eventBus: EventBus;
74
+
75
+ declare class EventBusClass implements EventBus {
76
+ constructor(options?: EventBusOptions);
77
+ on(eventName: string, callback: (...args: any[]) => void, options?: { once?: boolean }): () => void;
78
+ once(eventName: string, callback: (...args: any[]) => void): () => void;
79
+ off(eventName: string, callback?: (...args: any[]) => void): void;
80
+ emit(eventName: string, ...args: any[]): void;
81
+ listenerCount(eventName: string): number;
82
+ getEvents(): string[];
83
+ clear(): void;
84
+ }
85
+
86
+ declare const _default: EventBusPlugin;
87
+
88
+ export default _default;
89
+ export { eventBus, EventBusClass as EventBus };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vue3-event-bus-plugin",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
4
4
  "description": "A simple and lightweight EventBus for Vue 3, supporting both Composition API and Option API",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -12,7 +12,8 @@
12
12
  "module": "dist/vue3-event-bus-plugin.es.js",
13
13
  "types": "dist/index.d.ts",
14
14
  "files": [
15
- "dist"
15
+ "dist",
16
+ "index.d.ts"
16
17
  ],
17
18
  "keywords": [
18
19
  "vue3-event-bus-plugin",
@@ -28,10 +29,13 @@
28
29
  "vue": "^3.0.0"
29
30
  },
30
31
  "devDependencies": {
32
+ "@types/node": "^25.0.3",
31
33
  "@vitejs/plugin-vue": "^6.0.3",
32
34
  "rollup-plugin-terser": "^7.0.2",
35
+ "typescript": "^5.9.3",
33
36
  "vite": "^7.3.0",
34
- "vue": "^3.0.0"
37
+ "vue": "^3.0.0",
38
+ "vue-tsc": "^3.2.1"
35
39
  },
36
40
  "repository": {
37
41
  "type": "git",