@@ -7,12 +7,17 @@ export default function install(app) {
7
7
app . config . globalProperties . $emitExtendable = emitExtendable ;
8
8
}
9
9
10
- export function createEmitExtendable ( ) {
10
+ export function createEmitExtendable ( { emit} ) {
11
+ if ( ! emit && ! getCurrentInstance ( ) ) {
12
+ throw new TypeError ( 'Emit function is not present.' ) ;
13
+ }
14
+ if ( emit ) {
15
+ return emitExtendable . bind ( { emit} ) ;
16
+ }
11
17
return emitExtendable . bind ( getCurrentInstance ( ) ) ;
12
18
}
13
19
14
- // Pass in the emit function from setup when using a Vue 3 composition api component
15
- export async function emitExtendable ( name , event = { } , emit ) {
20
+ export async function emitExtendable ( name , event = { } ) {
16
21
if ( ! ( event && typeof event === 'object' ) ) {
17
22
throw new TypeError ( '"event" must be an object.' ) ;
18
23
}
@@ -35,7 +40,7 @@ export async function emitExtendable(name, event = {}, emit) {
35
40
}
36
41
response = p ;
37
42
}
38
- } , emit ) ;
43
+ } ) ;
39
44
40
45
// await any lifetime extensions
41
46
await Promise . all ( promises ) ;
@@ -50,13 +55,7 @@ function _emit(...args) {
50
55
}
51
56
if ( this ?. emit ) {
52
57
return this . emit ( ...args ) ;
53
- }
54
- if ( getCurrentInstance ( ) ) {
55
- const { emit} = getCurrentInstance ( ) ;
56
- return emit ( ...args ) ;
57
- }
58
- if ( typeof args [ 2 ] === 'function' ) {
59
- const emit = args [ 2 ] ;
60
- return emit ( ...args . slice ( 0 , 2 ) ) ;
61
58
}
59
+ const { emit} = getCurrentInstance ( ) ;
60
+ return emit ( ...args ) ;
62
61
}
0 commit comments