fix(runtime-core): allow classes to be passed as plugins (#588)

This commit is contained in:
Kael
2020-01-09 04:40:24 +11:00
committed by Evan You
parent 453e6889da
commit 8f616a89c5
2 changed files with 13 additions and 6 deletions

View 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" ` +