]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): allow classes to be passed as plugins (#588)
authorKael <kaelwd@gmail.com>
Wed, 8 Jan 2020 17:40:24 +0000 (04:40 +1100)
committerEvan You <yyx990803@gmail.com>
Wed, 8 Jan 2020 17:40:24 +0000 (12:40 -0500)
packages/runtime-core/__tests__/apiApp.spec.ts
packages/runtime-core/src/apiCreateApp.ts

index 2a70350cf2aeeb5c3cc5654ab8ac937edd64703e..31096954e6d1329a038f5307cbc203114874e404 100644 (file)
@@ -244,11 +244,18 @@ describe('api: createApp', () => {
     const PluginB: Plugin = {
       install: (app, arg1, arg2) => app.provide('bar', arg1 + arg2)
     }
-    const PluginC: any = undefined
+    class PluginC {
+      someProperty = {}
+      static install() {
+        app.provide('baz', 2)
+      }
+    }
+    const PluginD: any = undefined
 
     const app = createApp()
     app.use(PluginA)
     app.use(PluginB, 1, 1)
+    app.use(PluginC)
 
     const Root = {
       setup() {
@@ -266,7 +273,7 @@ describe('api: createApp', () => {
       `Plugin has already been applied to target app`
     ).toHaveBeenWarnedTimes(1)
 
-    app.use(PluginC)
+    app.use(PluginD)
     expect(
       `A plugin must either be a function or an object with an "install" ` +
         `function.`
index fa50f0e8e319023d1b8d2d7e1c103c12c0d54425..a07b14ca0d4ed6bc9cddb85465ec834a56b62cdc 100644 (file)
@@ -56,7 +56,7 @@ export interface AppContext {
 type PluginInstallFunction = (app: App, ...options: any[]) => any
 
 export type Plugin =
-  | PluginInstallFunction
+  | PluginInstallFunction & { install?: PluginInstallFunction }
   | {
       install: PluginInstallFunction
     }
@@ -103,12 +103,12 @@ export function createAppAPI<HostNode, HostElement>(
       use(plugin: Plugin, ...options: any[]) {
         if (installedPlugins.has(plugin)) {
           __DEV__ && warn(`Plugin has already been applied to target app.`)
-        } else if (isFunction(plugin)) {
-          installedPlugins.add(plugin)
-          plugin(app, ...options)
         } else if (plugin && isFunction(plugin.install)) {
           installedPlugins.add(plugin)
           plugin.install(app, ...options)
+        } else if (isFunction(plugin)) {
+          installedPlugins.add(plugin)
+          plugin(app, ...options)
         } else if (__DEV__) {
           warn(
             `A plugin must either be a function or an object with an "install" ` +