Ben Lin
2024-10-22 78999ce1626d2a786f3a705281eeba79c2f1d6dd
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);
  });
}