refactor(utils): refactor with-install (#3355)

This commit is contained in:
三咲智子 2021-09-12 19:18:14 +08:00 committed by GitHub
parent d819ef14b8
commit 5be1f0d878
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

View File

@ -1,5 +1,5 @@
import CheckTag from './src/index.vue' import CheckTag from './src/index.vue'
import withInstall from '@element-plus/utils/with-install' import { withInstall } from '@element-plus/utils/with-install'
export const ElCheckTag = withInstall(CheckTag) export const ElCheckTag = withInstall(CheckTag)
export default ElCheckTag export default ElCheckTag

View File

@ -1,8 +1,5 @@
import withInstall from '@element-plus/utils/with-install' import { withInstall } from '@element-plus/utils/with-install'
import { ConfigProvider } from './config-provider' import { ConfigProvider } from './config-provider'
const ElConfigProvider = withInstall(ConfigProvider) export const ElConfigProvider = withInstall(ConfigProvider)
export default ElConfigProvider export default ElConfigProvider
export { ElConfigProvider }

View File

@ -1,10 +1,20 @@
import type { App, DefineComponent } from 'vue' import type { App } from 'vue'
import type { SFCWithInstall } from './types' import type { SFCWithInstall } from './types'
/* istanbul ignore next */ export const withInstall = <T, E extends Record<string, any>>(
export default <T extends DefineComponent<any, any, any>>(component: T) => { main: T,
;(component as any).install = (app: App): void => { extra?: E
app.component(component.name, component) ) => {
;(main as SFCWithInstall<T>).install = (app: App): void => {
for (const comp of [main, ...Object.values(extra ?? {})]) {
app.component(comp.name, comp)
}
} }
return component as SFCWithInstall<T>
if (extra) {
for (const [key, comp] of Object.entries(extra)) {
;(main as any)[key] = comp
}
}
return main as SFCWithInstall<T> & E
} }