@@ -3,6 +3,7 @@ import { VueConstructor } from 'vue'
3
3
import { Directive } from '../component/directives'
4
4
import { getVueConstructor } from '../runtimeContext'
5
5
import { warn } from '../utils'
6
+ import { InjectionKey } from './inject'
6
7
7
8
// Has a generic to match Vue 3 API and be type compatible
8
9
export interface App < T = any > {
@@ -12,6 +13,7 @@ export interface App<T = any> {
12
13
component : VueConstructor [ 'component' ]
13
14
directive ( name : string ) : Directive | undefined
14
15
directive ( name : string , directive : Directive ) : this
16
+ provide < T > ( key : InjectionKey < T > | symbol | string , value : T ) : this
15
17
mount : Vue [ '$mount' ]
16
18
unmount : Vue [ '$destroy' ]
17
19
}
@@ -21,11 +23,17 @@ export function createApp(rootComponent: any, rootProps: any = undefined): App {
21
23
22
24
let mountedVM : Vue | undefined = undefined
23
25
26
+ let provide : Record < any , any > = { }
27
+
24
28
const app : App = {
25
29
config : V . config ,
26
30
use : V . use . bind ( V ) ,
27
31
mixin : V . mixin . bind ( V ) ,
28
32
component : V . component . bind ( V ) ,
33
+ provide < T > ( key : InjectionKey < T > | symbol | string , value : T ) {
34
+ provide [ key as any ] = value
35
+ return this
36
+ } ,
29
37
directive ( name : string , dir ?: Directive | undefined ) : any {
30
38
if ( dir ) {
31
39
V . directive ( name , dir as any )
@@ -36,7 +44,11 @@ export function createApp(rootComponent: any, rootProps: any = undefined): App {
36
44
} ,
37
45
mount : ( el , hydrating ) => {
38
46
if ( ! mountedVM ) {
39
- mountedVM = new V ( { propsData : rootProps , ...rootComponent } )
47
+ mountedVM = new V ( {
48
+ propsData : rootProps ,
49
+ ...rootComponent ,
50
+ provide : { ...provide , ...rootComponent . provide } ,
51
+ } )
40
52
mountedVM . $mount ( el , hydrating )
41
53
return mountedVM
42
54
} else {
0 commit comments