1
1
import { ComponentPublicInstance } from 'vue'
2
2
import { GlobalMountOptions } from './types'
3
3
import { VueWrapper } from './vueWrapper'
4
+ import { DOMWrapper } from './domWrapper'
4
5
5
6
interface GlobalConfigOptions {
6
7
global : GlobalMountOptions
7
8
plugins : {
8
- VueWrapper : Pluggable
9
- DOMWrapper : Pluggable
9
+ VueWrapper : Pluggable < VueWrapper < ComponentPublicInstance > >
10
+ DOMWrapper : Pluggable < DOMWrapper < Element > >
10
11
}
11
12
renderStubDefaultSlot : boolean
12
13
}
13
14
14
- interface Plugin {
15
- handler : (
16
- instance : VueWrapper < ComponentPublicInstance >
17
- ) => Record < string , any >
15
+ interface Plugin < Instance > {
16
+ handler : ( instance : Instance ) => Record < string , any >
18
17
options : Record < string , any >
19
18
}
20
19
21
- class Pluggable {
22
- installedPlugins : Plugin [ ] = [ ]
20
+ class Pluggable < Instance = DOMWrapper < Element > > {
21
+ installedPlugins : Plugin < Instance > [ ] = [ ]
23
22
24
23
install (
25
- handler : (
26
- instance : VueWrapper < ComponentPublicInstance >
27
- ) => Record < string , any > ,
24
+ handler : ( instance : Instance ) => Record < string , any > ,
28
25
options : Record < string , any > = { }
29
26
) {
30
27
if ( typeof handler !== 'function' ) {
@@ -34,8 +31,8 @@ class Pluggable {
34
31
this . installedPlugins . push ( { handler, options } )
35
32
}
36
33
37
- extend ( instance : VueWrapper < ComponentPublicInstance > ) {
38
- const invokeSetup = ( plugin : Plugin ) => plugin . handler ( instance ) // invoke the setup method passed to install
34
+ extend ( instance : Instance ) {
35
+ const invokeSetup = ( plugin : Plugin < Instance > ) => plugin . handler ( instance ) // invoke the setup method passed to install
39
36
const bindProperty = ( [ property , value ] : [ string , any ] ) => {
40
37
; ( instance as any ) [ property ] =
41
38
typeof value === 'function' ? value . bind ( instance ) : value
0 commit comments