@@ -4,11 +4,7 @@ import {
4
4
VNode ,
5
5
defineComponent ,
6
6
VNodeNormalizedChildren ,
7
- ComponentOptions ,
8
7
transformVNodeArgs ,
9
- Plugin ,
10
- Directive ,
11
- Component ,
12
8
reactive ,
13
9
ComponentPublicInstance ,
14
10
ComponentOptionsWithObjectProps ,
@@ -17,6 +13,9 @@ import {
17
13
ExtractPropTypes
18
14
} from 'vue'
19
15
16
+ import { config } from './config'
17
+ import { GlobalMountOptions } from './types'
18
+ import { mergeGlobalProperties } from './utils'
20
19
import { createWrapper , VueWrapper } from './vue-wrapper'
21
20
import { attachEmitListener } from './emitMixin'
22
21
import { createDataMixin } from './dataMixin'
@@ -36,17 +35,7 @@ interface MountingOptions<Props> {
36
35
default ?: Slot
37
36
[ key : string ] : Slot
38
37
}
39
- global ?: {
40
- plugins ?: Plugin [ ]
41
- mixins ?: ComponentOptions [ ]
42
- mocks ?: Record < string , any >
43
- stubs ?: Record < any , any >
44
- provide ?: Record < any , any >
45
- // TODO how to type `defineComponent`? Using `any` for now.
46
- components ?: Record < string , Component | object >
47
- directives ?: Record < string , Directive >
48
- }
49
- stubs ?: Record < string , any >
38
+ global ?: GlobalMountOptions
50
39
}
51
40
52
41
// Component declared with defineComponent
@@ -139,11 +128,13 @@ export function mount(
139
128
// create the app
140
129
const app = createApp ( Parent )
141
130
131
+ const global = mergeGlobalProperties ( config . global , options ?. global )
132
+
142
133
// global mocks mixin
143
- if ( options ?. global ?. mocks ) {
134
+ if ( global ?. mocks ) {
144
135
const mixin = {
145
136
beforeCreate ( ) {
146
- for ( const [ k , v ] of Object . entries ( options . global ? .mocks ) ) {
137
+ for ( const [ k , v ] of Object . entries ( global . mocks ) ) {
147
138
this [ k ] = v
148
139
}
149
140
}
@@ -153,30 +144,30 @@ export function mount(
153
144
}
154
145
155
146
// use and plugins from mounting options
156
- if ( options ?. global ?. plugins ) {
157
- for ( const use of options ?. global ? .plugins ) app . use ( use )
147
+ if ( global ?. plugins ) {
148
+ for ( const use of global . plugins ) app . use ( use )
158
149
}
159
150
160
151
// use any mixins from mounting options
161
- if ( options ?. global ?. mixins ) {
162
- for ( const mixin of options ?. global ? .mixins ) app . mixin ( mixin )
152
+ if ( global ?. mixins ) {
153
+ for ( const mixin of global . mixins ) app . mixin ( mixin )
163
154
}
164
155
165
- if ( options ?. global ?. components ) {
166
- for ( const key of Object . keys ( options ?. global ? .components ) )
167
- app . component ( key , options . global . components [ key ] )
156
+ if ( global ?. components ) {
157
+ for ( const key of Object . keys ( global . components ) )
158
+ app . component ( key , global . components [ key ] )
168
159
}
169
160
170
- if ( options ?. global ?. directives ) {
171
- for ( const key of Object . keys ( options ?. global ? .directives ) )
172
- app . directive ( key , options . global . directives [ key ] )
161
+ if ( global ?. directives ) {
162
+ for ( const key of Object . keys ( global . directives ) )
163
+ app . directive ( key , global . directives [ key ] )
173
164
}
174
165
175
166
// provide any values passed via provides mounting option
176
- if ( options ?. global ?. provide ) {
177
- for ( const key of Reflect . ownKeys ( options . global . provide ) ) {
167
+ if ( global ?. provide ) {
168
+ for ( const key of Reflect . ownKeys ( global . provide ) ) {
178
169
// @ts -ignore: https://github.com/microsoft/TypeScript/issues/1863
179
- app . provide ( key , options . global . provide [ key ] )
170
+ app . provide ( key , global . provide [ key ] )
180
171
}
181
172
}
182
173
0 commit comments