fix(runtime-core): pass options to plugins (#561)
This commit is contained in:
parent
6a14542f78
commit
4d20981eb0
@ -242,13 +242,13 @@ describe('api: createApp', () => {
|
|||||||
test('use', () => {
|
test('use', () => {
|
||||||
const PluginA: Plugin = app => app.provide('foo', 1)
|
const PluginA: Plugin = app => app.provide('foo', 1)
|
||||||
const PluginB: Plugin = {
|
const PluginB: Plugin = {
|
||||||
install: app => app.provide('bar', 2)
|
install: (app, arg1, arg2) => app.provide('bar', arg1 + arg2)
|
||||||
}
|
}
|
||||||
const PluginC: any = undefined
|
const PluginC: any = undefined
|
||||||
|
|
||||||
const app = createApp()
|
const app = createApp()
|
||||||
app.use(PluginA)
|
app.use(PluginA)
|
||||||
app.use(PluginB)
|
app.use(PluginB, 1, 1)
|
||||||
|
|
||||||
const Root = {
|
const Root = {
|
||||||
setup() {
|
setup() {
|
||||||
|
@ -10,7 +10,7 @@ import { createVNode, cloneVNode } from './vnode'
|
|||||||
|
|
||||||
export interface App<HostElement = any> {
|
export interface App<HostElement = any> {
|
||||||
config: AppConfig
|
config: AppConfig
|
||||||
use(plugin: Plugin, options?: any): this
|
use(plugin: Plugin, ...options: any[]): this
|
||||||
mixin(mixin: ComponentOptions): this
|
mixin(mixin: ComponentOptions): this
|
||||||
component(name: string): Component | undefined
|
component(name: string): Component | undefined
|
||||||
component(name: string, component: Component): this
|
component(name: string, component: Component): this
|
||||||
@ -50,7 +50,7 @@ export interface AppContext {
|
|||||||
reload?: () => void // HMR only
|
reload?: () => void // HMR only
|
||||||
}
|
}
|
||||||
|
|
||||||
type PluginInstallFunction = (app: App) => any
|
type PluginInstallFunction = (app: App, ...options: any[]) => any
|
||||||
|
|
||||||
export type Plugin =
|
export type Plugin =
|
||||||
| PluginInstallFunction
|
| PluginInstallFunction
|
||||||
@ -97,15 +97,15 @@ export function createAppAPI<HostNode, HostElement>(
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
use(plugin: Plugin) {
|
use(plugin: Plugin, ...options: any[]) {
|
||||||
if (installedPlugins.has(plugin)) {
|
if (installedPlugins.has(plugin)) {
|
||||||
__DEV__ && warn(`Plugin has already been applied to target app.`)
|
__DEV__ && warn(`Plugin has already been applied to target app.`)
|
||||||
} else if (isFunction(plugin)) {
|
} else if (isFunction(plugin)) {
|
||||||
installedPlugins.add(plugin)
|
installedPlugins.add(plugin)
|
||||||
plugin(app)
|
plugin(app, ...options)
|
||||||
} else if (plugin && isFunction(plugin.install)) {
|
} else if (plugin && isFunction(plugin.install)) {
|
||||||
installedPlugins.add(plugin)
|
installedPlugins.add(plugin)
|
||||||
plugin.install(app)
|
plugin.install(app, ...options)
|
||||||
} else if (__DEV__) {
|
} else if (__DEV__) {
|
||||||
warn(
|
warn(
|
||||||
`A plugin must either be a function or an object with an "install" ` +
|
`A plugin must either be a function or an object with an "install" ` +
|
||||||
|
Loading…
Reference in New Issue
Block a user