You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
tailchat/shared/manager/buildRegMap.ts

21 lines
417 B
TypeScript

/**
* Mapping
*
*/
export function buildRegMap<T>(): [
Record<string, T>,
(name: string, item: T) => void
] {
const mapping: Record<string, T> = {};
const reg = (name: string, item: T) => {
if (mapping[name]) {
console.warn('[buildRegMap] 重复注册:', name);
}
mapping[name] = item;
};
return [mapping, reg];
}