feat: warn duplicate plugin installations
This commit is contained in:
parent
2d5f9b58ac
commit
c61e5463fa
@ -259,6 +259,11 @@ describe('api: createApp', () => {
|
||||
const root = nodeOps.createElement('div')
|
||||
app.mount(Root, root)
|
||||
expect(serializeInner(root)).toBe(`1,2`)
|
||||
|
||||
app.use(PluginA)
|
||||
expect(
|
||||
`Plugin has already been applied to target app`
|
||||
).toHaveBeenWarnedTimes(1)
|
||||
})
|
||||
|
||||
test('config.errorHandler', () => {
|
||||
|
@ -79,6 +79,7 @@ export function createAppAPI<HostNode, HostElement>(
|
||||
): () => App<HostElement> {
|
||||
return function createApp(): App {
|
||||
const context = createAppContext()
|
||||
const installedPlugins = new Set()
|
||||
|
||||
let isMounted = false
|
||||
|
||||
@ -96,9 +97,13 @@ export function createAppAPI<HostNode, HostElement>(
|
||||
},
|
||||
|
||||
use(plugin: Plugin) {
|
||||
if (isFunction(plugin)) {
|
||||
if (installedPlugins.has(plugin)) {
|
||||
__DEV__ && warn(`Plugin has already been applied to target app.`)
|
||||
} else if (isFunction(plugin)) {
|
||||
installedPlugins.add(plugin)
|
||||
plugin(app)
|
||||
} else if (isFunction(plugin.install)) {
|
||||
installedPlugins.add(plugin)
|
||||
plugin.install(app)
|
||||
} else if (__DEV__) {
|
||||
warn(
|
||||
|
Loading…
Reference in New Issue
Block a user