factory.js 659 B

123456789101112131415161718192021
  1. import Attribute from './attributes/base';
  2. // 所有的 attribute map
  3. var ATTRIBUTE_MAP = {};
  4. /**
  5. * 通过类型获得 Attribute 类
  6. * @param type
  7. */
  8. var getAttribute = function (type) {
  9. return ATTRIBUTE_MAP[type.toLowerCase()];
  10. };
  11. var registerAttribute = function (type, ctor) {
  12. // 注册的时候,需要校验 type 重名,不区分大小写
  13. if (getAttribute(type)) {
  14. throw new Error("Attribute type '".concat(type, "' existed."));
  15. }
  16. // 存储到 map 中
  17. ATTRIBUTE_MAP[type.toLowerCase()] = ctor;
  18. };
  19. export { getAttribute, registerAttribute, Attribute };
  20. export * from './interface';
  21. //# sourceMappingURL=factory.js.map