-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
72 additions
and
66 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,6 @@ | ||
import type { Plugin } from 'vue' | ||
import { useGlobalConfig } from 'vue-global-config' | ||
import Component from './Component' | ||
import type { Mode } from './Component' | ||
|
||
type SFCWithInstall<T> = T & Plugin | ||
|
||
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 | ||
} | ||
|
||
const globalProps: Record<string, any> = {} | ||
const globalAttrs: Record<string, any> = {} | ||
const globalListeners: Record<string, any> = {} | ||
const globalHooks: Record<string, any> = {} | ||
|
||
const ComponentWithInstall = withInstall(Component) | ||
|
||
ComponentWithInstall.install = (app: any, options = {}) => { | ||
const { props, attrs, listeners, hooks } = useGlobalConfig(options, Component.props) | ||
Object.assign(globalProps, props) | ||
Object.assign(globalAttrs, attrs) | ||
Object.assign(globalListeners, listeners) | ||
Object.assign(globalHooks, hooks) | ||
app.component(ComponentWithInstall.name, ComponentWithInstall) | ||
} | ||
import ComponentWithInstall from './install' | ||
import type { Mode } from './install' | ||
|
||
export default ComponentWithInstall | ||
export { | ||
globalProps, globalAttrs, globalListeners, globalHooks, | ||
Mode, | ||
} | ||
export { Mode } | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import type { Plugin } from 'vue' | ||
import { useGlobalConfig } from 'vue-global-config' | ||
import Component from './Component' | ||
import type { Mode } from './Component' | ||
|
||
type SFCWithInstall<T> = T & Plugin | ||
|
||
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 | ||
} | ||
|
||
const globalProps: Record<string, any> = {} | ||
const globalAttrs: Record<string, any> = {} | ||
const globalListeners: Record<string, any> = {} | ||
const globalHooks: Record<string, any> = {} | ||
|
||
const ComponentWithInstall = withInstall(Component) | ||
|
||
ComponentWithInstall.install = (app: any, options = {}) => { | ||
const { props, attrs, listeners, hooks } = useGlobalConfig(options, Component.props) | ||
Object.assign(globalProps, props) | ||
Object.assign(globalAttrs, attrs) | ||
Object.assign(globalListeners, listeners) | ||
Object.assign(globalHooks, hooks) | ||
app.component(ComponentWithInstall.name, ComponentWithInstall) | ||
} | ||
|
||
export default ComponentWithInstall | ||
export { | ||
globalProps, globalAttrs, globalListeners, globalHooks, | ||
Mode, | ||
} |