e0645bd86126bbdedaf0f51918ccb4fc1700b1c46aac59c5fbd0b755f0f30c32eba4d151f06c8ceae8e6ec85d93b84247e9f8681abe06a62f51ccbd4eff575 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import { ComponentFullType, ComponentTypeInfo, ComponentMainType, ComponentSubType } from './types.js';
  2. declare const IS_EXTENDED_CLASS: "___EC__EXTENDED_CLASS___";
  3. /**
  4. * Notice, parseClassType('') should returns {main: '', sub: ''}
  5. * @public
  6. */
  7. export declare function parseClassType(componentType: ComponentFullType): ComponentTypeInfo;
  8. export declare function isExtendedClass(clz: any): boolean;
  9. export interface ExtendableConstructor {
  10. new (...args: any): any;
  11. $constructor?: new (...args: any) => any;
  12. extend: (proto: {
  13. [name: string]: any;
  14. }) => ExtendableConstructor;
  15. superCall: (context: any, methodName: string, ...args: any) => any;
  16. superApply: (context: any, methodName: string, args: []) => any;
  17. superClass?: ExtendableConstructor;
  18. [IS_EXTENDED_CLASS]?: boolean;
  19. }
  20. /**
  21. * Implements `ExtendableConstructor` for `rootClz`.
  22. *
  23. * @usage
  24. * ```ts
  25. * class Xxx {}
  26. * type XxxConstructor = typeof Xxx & ExtendableConstructor
  27. * enableClassExtend(Xxx as XxxConstructor);
  28. * ```
  29. */
  30. export declare function enableClassExtend(rootClz: ExtendableConstructor, mandatoryMethods?: string[]): void;
  31. /**
  32. * A work around to both support ts extend and this extend mechanism.
  33. * on sub-class.
  34. * @usage
  35. * ```ts
  36. * class Component { ... }
  37. * classUtil.enableClassExtend(Component);
  38. * classUtil.enableClassManagement(Component, {registerWhenExtend: true});
  39. *
  40. * class Series extends Component { ... }
  41. * // Without calling `markExtend`, `registerWhenExtend` will not work.
  42. * Component.markExtend(Series);
  43. * ```
  44. */
  45. export declare function mountExtend(SubClz: any, SupperClz: any): void;
  46. export interface CheckableConstructor {
  47. new (...args: any): any;
  48. isInstance: (ins: any) => boolean;
  49. }
  50. /**
  51. * Implements `CheckableConstructor` for `target`.
  52. * Can not use instanceof, consider different scope by
  53. * cross domain or es module import in ec extensions.
  54. * Mount a method "isInstance()" to Clz.
  55. *
  56. * @usage
  57. * ```ts
  58. * class Xxx {}
  59. * type XxxConstructor = typeof Xxx & CheckableConstructor;
  60. * enableClassCheck(Xxx as XxxConstructor)
  61. * ```
  62. */
  63. export declare function enableClassCheck(target: CheckableConstructor): void;
  64. export declare type Constructor = new (...args: any) => any;
  65. export interface ClassManager {
  66. registerClass: (clz: Constructor) => Constructor;
  67. getClass: (componentMainType: ComponentMainType, subType?: ComponentSubType, throwWhenNotFound?: boolean) => Constructor;
  68. getClassesByMainType: (componentType: ComponentMainType) => Constructor[];
  69. hasClass: (componentType: ComponentFullType) => boolean;
  70. getAllClassMainTypes: () => ComponentMainType[];
  71. hasSubTypes: (componentType: ComponentFullType) => boolean;
  72. }
  73. /**
  74. * Implements `ClassManager` for `target`
  75. *
  76. * @usage
  77. * ```ts
  78. * class Xxx {}
  79. * type XxxConstructor = typeof Xxx & ClassManager
  80. * enableClassManagement(Xxx as XxxConstructor);
  81. * ```
  82. */
  83. export declare function enableClassManagement(target: ClassManager): void;
  84. export {};