11import type Vue from 'vue'
22import { VueConstructor } from 'vue'
3+ import { Directive } from '../component/directives'
34import { getVueConstructor } from '../runtimeContext'
45import { warn } from '../utils'
56
@@ -9,7 +10,8 @@ export interface App<T = any> {
910 use : VueConstructor [ 'use' ]
1011 mixin : VueConstructor [ 'mixin' ]
1112 component : VueConstructor [ 'component' ]
12- directive : VueConstructor [ 'directive' ]
13+ directive ( name : string ) : Directive | undefined
14+ directive ( name : string , directive : Directive ) : this
1315 mount : Vue [ '$mount' ]
1416 unmount : Vue [ '$destroy' ]
1517}
@@ -19,12 +21,19 @@ export function createApp(rootComponent: any, rootProps: any = undefined): App {
1921
2022 let mountedVM : Vue | undefined = undefined
2123
22- return {
24+ const app : App = {
2325 config : V . config ,
2426 use : V . use . bind ( V ) ,
2527 mixin : V . mixin . bind ( V ) ,
2628 component : V . component . bind ( V ) ,
27- directive : V . directive . bind ( V ) ,
29+ directive ( name : string , dir ?: Directive | undefined ) : any {
30+ if ( dir ) {
31+ V . directive ( name , dir as any )
32+ return app
33+ } else {
34+ return V . directive ( name )
35+ }
36+ } ,
2837 mount : ( el , hydrating ) => {
2938 if ( ! mountedVM ) {
3039 mountedVM = new V ( { propsData : rootProps , ...rootComponent } )
@@ -51,4 +60,5 @@ export function createApp(rootComponent: any, rootProps: any = undefined): App {
5160 }
5261 } ,
5362 }
63+ return app
5464}
0 commit comments