UNPKG

533 BPlain TextView Raw
1import Scale from './base';
2import { ScaleConfig } from './types';
3type ScaleConstructor<T extends Scale = Scale> = new (cfg: ScaleConfig) => T;
4
5interface ScaleMap {
6 [key: string]: ScaleConstructor;
7}
8
9const map: ScaleMap = {};
10
11function getClass(key: string): ScaleConstructor {
12 return map[key];
13}
14
15function registerClass(key: string, cls: ScaleConstructor) {
16 if (getClass(key)) {
17 throw new Error(`type '${key}' existed.`);
18 }
19 map[key] = cls;
20}
21
22export { Scale, getClass as getScale, registerClass as registerScale };