-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
33 additions
and
23 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,12 @@ | ||
/* | ||
* @Author: limit | ||
* @Date: 2023-06-18 17:40:29 | ||
* @LastEditTime: 2023-08-01 16:32:19 | ||
* @LastEditTime: 2024-03-18 16:15:19 | ||
* @LastEditors: limit | ||
* @FilePath: /vue-turn-clock/packages/index.ts | ||
* @Description: 由limit创建! | ||
*/ | ||
import { withInstall } from './utils/install'; | ||
import { withInstall, type WithInstallType } from './utils/install'; | ||
import CountClock from './count-clock/countClock'; | ||
|
||
export default withInstall(CountClock); | ||
export default withInstall(CountClock) as WithInstallType<typeof CountClock>; |
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,19 +1,29 @@ | ||
import type { Plugin } from 'vue'; | ||
/* | ||
* @Author: limit | ||
* @Date: 2023-06-18 17:40:29 | ||
* @LastEditTime: 2024-03-18 15:51:51 | ||
* @LastEditors: limit | ||
* @FilePath: /vue-turn-clock/packages/utils/install.ts | ||
* @Description: 由limit创建! | ||
*/ | ||
import type { Plugin, App } from 'vue'; | ||
|
||
export type WithInstallType<T> = T & Plugin; | ||
|
||
export const withInstall = <T, E extends Record<string, any>>( | ||
main: T, | ||
extra?: E | ||
main: T, | ||
extra?: E | ||
) => { | ||
(main as T & Plugin).install = (app): void => { | ||
for (const comp of [main, ...Object.values(extra ?? {})]) { | ||
app.component(comp.name, comp); | ||
} | ||
}; | ||
(main as WithInstallType<T>).install = (app: 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; | ||
} | ||
if (extra) { | ||
for (const [key, comp] of Object.entries(extra)) { | ||
(main as any)[key] = comp; | ||
} | ||
return main as T & Plugin & E; | ||
} | ||
return main as WithInstallType<T> & E; | ||
}; |
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