1
- import { setDevtoolsHook , ComponentPublicInstance , devtools } from 'vue'
1
+ import { setDevtoolsHook , devtools } from 'vue'
2
2
3
3
const enum DevtoolsHooks {
4
4
COMPONENT_EMIT = 'component:emit'
5
5
}
6
6
7
- export const attachEmitListener = ( vm : ComponentPublicInstance ) => {
8
- const events : Record < string , unknown [ ] > = { }
9
- ; ( vm as any ) . __emitted = events
7
+ let events : Record < string , unknown [ ] >
8
+
9
+ export function emitted < T = unknown > (
10
+ eventName ?: string
11
+ ) : T [ ] | Record < string , T [ ] > {
12
+ if ( eventName ) {
13
+ const emitted = ( events as Record < string , T [ ] > ) [ eventName ]
14
+ return emitted
15
+ }
16
+
17
+ return events as Record < string , T [ ] >
18
+ }
19
+
20
+ export const attachEmitListener = ( ) => {
21
+ events = { }
10
22
// use devtools to capture this "emit"
11
23
setDevtoolsHook ( createDevTools ( events ) )
12
24
}
@@ -29,9 +41,6 @@ function createDevTools(events): any {
29
41
30
42
function recordEvent ( events , event , args ) {
31
43
// Record the event message sent by the emit
32
- // Stored by a vm
33
- // emitted by a subsequent wrapper.emitted
34
- // An event object and a vm.__emitted is a reference
35
44
events [ event ]
36
45
? ( events [ event ] = [ ...events [ event ] , [ ...args ] ] )
37
46
: ( events [ event ] = [ [ ...args ] ] )
0 commit comments