1 | import Attribute, { AttributeConstructor } from './attributes/base';
|
2 |
|
3 | interface AttributeMapType {
|
4 | [key: string]: any;
|
5 | }
|
6 |
|
7 |
|
8 | const ATTRIBUTE_MAP: AttributeMapType = {};
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 | const getAttribute = (type: string) => {
|
15 | return ATTRIBUTE_MAP[type.toLowerCase()];
|
16 | };
|
17 |
|
18 | const registerAttribute = (type: string, ctor: AttributeConstructor) => {
|
19 |
|
20 | if (getAttribute(type)) {
|
21 | throw new Error(`Attribute type '${type}' existed.`);
|
22 | }
|
23 |
|
24 | ATTRIBUTE_MAP[type.toLowerCase()] = ctor;
|
25 | };
|
26 |
|
27 | export { getAttribute, registerAttribute, Attribute };
|
28 | export * from './interface';
|