1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
| import type { ComponentType } from '../types';
| import { tryOnUnmounted } from '@vueuse/core';
| import { add, del } from '../componentMap';
| import type { Component } from 'vue';
| import { isPascalCase } from '@/utils/is';
|
| export function useComponentRegister<T extends string, R extends Component>(
| compName: ComponentType | T,
| comp: R,
| ) {
| if (!isPascalCase(compName)) {
| throw new Error('compName must be in PascalCase');
| }
|
| add(compName, comp);
| tryOnUnmounted(() => {
| del(compName);
| });
| }
|
|