@@ -14,25 +14,24 @@ import {
14
14
import { ComponentPropsOptions , resolveProps } from './componentProps'
15
15
import { Slots , resolveSlots } from './componentSlots'
16
16
import { warn } from './warning'
17
- import {
18
- ErrorCodes ,
19
- callWithErrorHandling ,
20
- callWithAsyncErrorHandling
21
- } from './errorHandling'
17
+ import { ErrorCodes , callWithErrorHandling } from './errorHandling'
22
18
import { AppContext , createAppContext , AppConfig } from './apiCreateApp'
23
19
import { Directive , validateDirectiveName } from './directives'
24
- import { applyOptions , ComponentOptions , EmitsOptions } from './apiOptions'
20
+ import { applyOptions , ComponentOptions } from './componentOptions'
21
+ import {
22
+ EmitsOptions ,
23
+ ObjectEmitsOptions ,
24
+ EmitFn ,
25
+ emit
26
+ } from './componentEmits'
25
27
import {
26
28
EMPTY_OBJ ,
27
29
isFunction ,
28
- capitalize ,
29
30
NOOP ,
30
31
isObject ,
31
32
NO ,
32
33
makeMap ,
33
34
isPromise ,
34
- isArray ,
35
- hyphenate ,
36
35
ShapeFlags
37
36
} from '@vue/shared'
38
37
import { SuspenseBoundary } from './components/Suspense'
@@ -96,29 +95,10 @@ export const enum LifecycleHooks {
96
95
ERROR_CAPTURED = 'ec'
97
96
}
98
97
99
- type UnionToIntersection < U > = ( U extends any
100
- ? ( k : U ) => void
101
- : never ) extends ( ( k : infer I ) => void )
102
- ? I
103
- : never
104
-
105
- export type Emit <
106
- Options = Record < string , any > ,
107
- Event extends keyof Options = keyof Options
108
- > = Options extends any [ ]
109
- ? ( event : Options [ 0 ] , ...args : any [ ] ) => unknown [ ]
110
- : UnionToIntersection <
111
- {
112
- [ key in Event ] : Options [ key ] extends ( ( ...args : infer Args ) => any )
113
- ? ( event : key , ...args : Args ) => unknown [ ]
114
- : ( event : key , ...args : any [ ] ) => unknown [ ]
115
- } [ Event ]
116
- >
117
-
118
- export interface SetupContext < E = Record < string , any > > {
98
+ export interface SetupContext < E = ObjectEmitsOptions > {
119
99
attrs : Data
120
100
slots : Slots
121
- emit : Emit < E >
101
+ emit : EmitFn < E >
122
102
}
123
103
124
104
export type RenderFunction = {
@@ -165,7 +145,7 @@ export interface ComponentInternalInstance {
165
145
propsProxy : Data | null
166
146
setupContext : SetupContext | null
167
147
refs : Data
168
- emit : Emit
148
+ emit : EmitFn
169
149
170
150
// suspense related
171
151
suspense : SuspenseBoundary | null
@@ -268,29 +248,10 @@ export function createComponentInstance(
268
248
rtg : null ,
269
249
rtc : null ,
270
250
ec : null ,
271
-
272
- emit : ( event : string , ...args : any [ ] ) : any [ ] => {
273
- const props = instance . vnode . props || EMPTY_OBJ
274
- let handler = props [ `on${ event } ` ] || props [ `on${ capitalize ( event ) } ` ]
275
- if ( ! handler && event . indexOf ( 'update:' ) === 0 ) {
276
- event = hyphenate ( event )
277
- handler = props [ `on${ event } ` ] || props [ `on${ capitalize ( event ) } ` ]
278
- }
279
- if ( handler ) {
280
- const res = callWithAsyncErrorHandling (
281
- handler ,
282
- instance ,
283
- ErrorCodes . COMPONENT_EVENT_HANDLER ,
284
- args
285
- )
286
- return isArray ( res ) ? res : [ res ]
287
- } else {
288
- return [ ]
289
- }
290
- }
251
+ emit : null as any // to be set immediately
291
252
}
292
-
293
253
instance . root = parent ? parent . root : instance
254
+ instance . emit = emit . bind ( null , instance )
294
255
return instance
295
256
}
296
257
0 commit comments