Skip to content

Commit c836ed0

Browse files
authored
Merge pull request #216 from HerringtonDarkholme/master
[fix] apply DOMWrapper plugins in constructor
2 parents c6fdcba + c7a10fd commit c836ed0

File tree

2 files changed

+13
-13
lines changed

2 files changed

+13
-13
lines changed

src/config.ts

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,27 @@
11
import { ComponentPublicInstance } from 'vue'
22
import { GlobalMountOptions } from './types'
33
import { VueWrapper } from './vueWrapper'
4+
import { DOMWrapper } from './domWrapper'
45

56
interface GlobalConfigOptions {
67
global: GlobalMountOptions
78
plugins: {
8-
VueWrapper: Pluggable
9-
DOMWrapper: Pluggable
9+
VueWrapper: Pluggable<VueWrapper<ComponentPublicInstance>>
10+
DOMWrapper: Pluggable<DOMWrapper<Element>>
1011
}
1112
renderStubDefaultSlot: boolean
1213
}
1314

14-
interface Plugin {
15-
handler: (
16-
instance: VueWrapper<ComponentPublicInstance>
17-
) => Record<string, any>
15+
interface Plugin<Instance> {
16+
handler: (instance: Instance) => Record<string, any>
1817
options: Record<string, any>
1918
}
2019

21-
class Pluggable {
22-
installedPlugins: Plugin[] = []
20+
class Pluggable<Instance = DOMWrapper<Element>> {
21+
installedPlugins: Plugin<Instance>[] = []
2322

2423
install(
25-
handler: (
26-
instance: VueWrapper<ComponentPublicInstance>
27-
) => Record<string, any>,
24+
handler: (instance: Instance) => Record<string, any>,
2825
options: Record<string, any> = {}
2926
) {
3027
if (typeof handler !== 'function') {
@@ -34,8 +31,8 @@ class Pluggable {
3431
this.installedPlugins.push({ handler, options })
3532
}
3633

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
3936
const bindProperty = ([property, value]: [string, any]) => {
4037
;(instance as any)[property] =
4138
typeof value === 'function' ? value.bind(instance) : value

src/domWrapper.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,16 @@ import { nextTick } from 'vue'
22

33
import { createWrapperError } from './errorWrapper'
44
import { TriggerOptions, createDOMEvent } from './createDomEvent'
5+
import { config } from './config'
56
import { isElementVisible } from './utils/isElementVisible'
67

78
export class DOMWrapper<ElementType extends Element> {
89
element: ElementType
910

1011
constructor(element: ElementType) {
1112
this.element = element
13+
// plugins hook
14+
config.plugins.DOMWrapper.extend(this)
1215
}
1316

1417
classes(): string[]

0 commit comments

Comments
 (0)