@@ -3,6 +3,7 @@ import { VueConstructor } from 'vue'
33import { Directive } from '../component/directives'
44import { getVueConstructor } from '../runtimeContext'
55import { warn } from '../utils'
6+ import { InjectionKey } from './inject'
67
78// Has a generic to match Vue 3 API and be type compatible
89export interface App < T = any > {
@@ -12,6 +13,7 @@ export interface App<T = any> {
1213 component : VueConstructor [ 'component' ]
1314 directive ( name : string ) : Directive | undefined
1415 directive ( name : string , directive : Directive ) : this
16+ provide < T > ( key : InjectionKey < T > | symbol | string , value : T ) : this
1517 mount : Vue [ '$mount' ]
1618 unmount : Vue [ '$destroy' ]
1719}
@@ -21,11 +23,17 @@ export function createApp(rootComponent: any, rootProps: any = undefined): App {
2123
2224 let mountedVM : Vue | undefined = undefined
2325
26+ let provide : Record < any , any > = { }
27+
2428 const app : App = {
2529 config : V . config ,
2630 use : V . use . bind ( V ) ,
2731 mixin : V . mixin . bind ( V ) ,
2832 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+ } ,
2937 directive ( name : string , dir ?: Directive | undefined ) : any {
3038 if ( dir ) {
3139 V . directive ( name , dir as any )
@@ -36,7 +44,11 @@ export function createApp(rootComponent: any, rootProps: any = undefined): App {
3644 } ,
3745 mount : ( el , hydrating ) => {
3846 if ( ! mountedVM ) {
39- mountedVM = new V ( { propsData : rootProps , ...rootComponent } )
47+ mountedVM = new V ( {
48+ propsData : rootProps ,
49+ ...rootComponent ,
50+ provide : { ...provide , ...rootComponent . provide } ,
51+ } )
4052 mountedVM . $mount ( el , hydrating )
4153 return mountedVM
4254 } else {
0 commit comments