1
1
import { GlobalMountOptions } from './types'
2
+ import { VueWrapper } from './vue-wrapper'
3
+ import { ComponentPublicInstance } from 'vue'
2
4
3
5
interface GlobalConfigOptions {
4
6
global : GlobalMountOptions
@@ -9,27 +11,36 @@ interface GlobalConfigOptions {
9
11
renderStubDefaultSlot : boolean
10
12
}
11
13
14
+ interface Plugin {
15
+ handler : (
16
+ instance : VueWrapper < ComponentPublicInstance >
17
+ ) => Record < string , any >
18
+ options : Record < string , any >
19
+ }
20
+
12
21
class Pluggable {
13
- installedPlugins : any
14
- constructor ( ) {
15
- this . installedPlugins = [ ]
16
- }
22
+ installedPlugins = [ ] as Array < Plugin >
17
23
18
- install ( handler , options = { } ) {
24
+ install (
25
+ handler : (
26
+ instance : VueWrapper < ComponentPublicInstance >
27
+ ) => Record < string , any > ,
28
+ options : Record < string , any > = { }
29
+ ) {
19
30
if ( typeof handler !== 'function' ) {
20
31
console . error ( 'plugin.install must receive a function' )
21
32
handler = ( ) => ( { } )
22
33
}
23
34
this . installedPlugins . push ( { handler, options } )
24
35
}
25
36
26
- extend ( instance ) {
27
- const invokeSetup = ( plugin ) => plugin . handler ( instance ) // invoke the setup method passed to install
37
+ extend ( instance : VueWrapper < ComponentPublicInstance > ) {
38
+ const invokeSetup = ( plugin : Plugin ) => plugin . handler ( instance ) // invoke the setup method passed to install
28
39
const bindProperty = ( [ property , value ] : [ string , any ] ) => {
29
- instance [ property ] =
40
+ ; ( instance as any ) [ property ] =
30
41
typeof value === 'function' ? value . bind ( instance ) : value
31
42
}
32
- const addAllPropertiesFromSetup = ( setupResult ) => {
43
+ const addAllPropertiesFromSetup = ( setupResult : Record < string , any > ) => {
33
44
setupResult = typeof setupResult === 'object' ? setupResult : { }
34
45
Object . entries ( setupResult ) . forEach ( bindProperty )
35
46
}
0 commit comments