1
- import { isFunction , isObject } from '@vue/shared'
1
+ import { NO , isFunction , isObject } from '@vue/shared'
2
2
import {
3
3
type Component ,
4
4
type ComponentInternalInstance ,
5
5
createComponentInstance ,
6
+ validateComponentName ,
6
7
} from './component'
7
8
import { warn } from './warning'
8
9
import { version } from '.'
@@ -60,6 +61,20 @@ export function createVaporApp(
60
61
return app
61
62
} ,
62
63
64
+ component ( name : string , component ?: Component ) : any {
65
+ if ( __DEV__ ) {
66
+ validateComponentName ( name , context . config )
67
+ }
68
+ if ( ! component ) {
69
+ return context . components [ name ]
70
+ }
71
+ if ( __DEV__ && context . components [ name ] ) {
72
+ warn ( `Component "${ name } " has already been registered in target app.` )
73
+ }
74
+ context . components [ name ] = component
75
+ return app
76
+ } ,
77
+
63
78
mount ( rootContainer ) : any {
64
79
if ( ! instance ) {
65
80
instance = createComponentInstance (
@@ -119,10 +134,12 @@ export function createAppContext(): AppContext {
119
134
return {
120
135
app : null as any ,
121
136
config : {
137
+ isNativeTag : NO ,
122
138
errorHandler : undefined ,
123
139
warnHandler : undefined ,
124
140
globalProperties : { } ,
125
141
} ,
142
+ components : { } ,
126
143
provides : Object . create ( null ) ,
127
144
}
128
145
}
@@ -151,6 +168,11 @@ export interface App {
151
168
) : this
152
169
use < Options > ( plugin : Plugin < Options > , options : Options ) : this
153
170
171
+ component ( name : string ) : Component | undefined
172
+ // TODO: DefineComponent
173
+ // component<T extends Component | DefineComponent>(
174
+ component < T extends Component > ( name : string , component : T ) : this
175
+
154
176
mount (
155
177
rootContainer : ParentNode | string ,
156
178
isHydrate ?: boolean ,
@@ -163,6 +185,9 @@ export interface App {
163
185
}
164
186
165
187
export interface AppConfig {
188
+ // @private
189
+ readonly isNativeTag : ( tag : string ) => boolean
190
+
166
191
errorHandler ?: (
167
192
err : unknown ,
168
193
instance : ComponentInternalInstance | null ,
@@ -179,6 +204,7 @@ export interface AppConfig {
179
204
export interface AppContext {
180
205
app : App // for devtools
181
206
config : AppConfig
207
+ components : Record < string , Component >
182
208
provides : Record < string | symbol , any >
183
209
}
184
210
0 commit comments