mirror of
https://github.com/element-plus/element-plus.git
synced 2025-08-26 04:27:26 +08:00
refactor(utils): migrate utils (#5949)
* refactor(utils-v2): migrate utils * refactor(utils-v2): migrate utils * refactor(utils-v2): migrate utils * refactor(utils): remove * refactor(utils): rename * refactor(utils): move EVENT_CODE to constants * refactor: remove generic
This commit is contained in:
34
packages/utils/vue/install.ts
Normal file
34
packages/utils/vue/install.ts
Normal file
@ -0,0 +1,34 @@
|
||||
import { NOOP } from '@vue/shared'
|
||||
import type { SFCWithInstall } from './typescript'
|
||||
|
||||
export const withInstall = <T, E extends Record<string, any>>(
|
||||
main: T,
|
||||
extra?: E
|
||||
) => {
|
||||
;(main as SFCWithInstall<T>).install = (app): void => {
|
||||
for (const comp of [main, ...Object.values(extra ?? {})]) {
|
||||
app.component(comp.name, comp)
|
||||
}
|
||||
}
|
||||
|
||||
if (extra) {
|
||||
for (const [key, comp] of Object.entries(extra)) {
|
||||
;(main as any)[key] = comp
|
||||
}
|
||||
}
|
||||
return main as SFCWithInstall<T> & E
|
||||
}
|
||||
|
||||
export const withInstallFunction = <T>(fn: T, name: string) => {
|
||||
;(fn as SFCWithInstall<T>).install = (app) => {
|
||||
app.config.globalProperties[name] = fn
|
||||
}
|
||||
|
||||
return fn as SFCWithInstall<T>
|
||||
}
|
||||
|
||||
export const withNoopInstall = <T>(component: T) => {
|
||||
;(component as SFCWithInstall<T>).install = NOOP
|
||||
|
||||
return component as SFCWithInstall<T>
|
||||
}
|
Reference in New Issue
Block a user