@cocojs/mvc 0.1.0-beta.12 → 0.1.0-beta.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs.js CHANGED
@@ -621,8 +621,8 @@ function createDecoratorExpFactory(fn) {
621
621
  }
622
622
  case KindMethod:
623
623
  case KindField:
624
- break;
625
624
  case KindGetter:
625
+ break;
626
626
  case KindSetter:
627
627
  case KindAccessor:
628
628
  default:
@@ -632,6 +632,7 @@ function createDecoratorExpFactory(fn) {
632
632
  switch (context.kind) {
633
633
  case KindField:
634
634
  case KindMethod:
635
+ case KindGetter:
635
636
  fn(isPlaceholderExp, this.constructor, {
636
637
  metadataKind: context.kind,
637
638
  metadataClass: MetaClsOrPlaceholderMetaCls,
@@ -717,6 +718,7 @@ var Type;
717
718
  Type[Type["Class"] = KindClass] = "Class";
718
719
  Type[Type["Field"] = KindField] = "Field";
719
720
  Type[Type["Method"] = KindMethod] = "Method";
721
+ Type[Type["Getter"] = KindGetter] = "Getter";
720
722
  })(Type || (Type = {}));
721
723
  /**
722
724
  * @public
@@ -843,22 +845,22 @@ let _initClass$u;
843
845
  /**
844
846
  * @public
845
847
  */
846
- let _ConstructorParam;
848
+ let _ConstructorInject;
847
849
  new class extends _identity {
848
- static [class ConstructorParam extends Metadata {
850
+ static [class ConstructorInject extends Metadata {
849
851
  static {
850
- [_ConstructorParam, _initClass$u] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
852
+ [_ConstructorInject, _initClass$u] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
851
853
  }
852
854
  value;
853
855
  }];
854
- $$id = "ConstructorParam";
856
+ $$id = "ConstructorInject";
855
857
  constructor() {
856
- super(_ConstructorParam), _initClass$u();
858
+ super(_ConstructorInject), _initClass$u();
857
859
  }
858
860
  }();
859
- var ConstructorParam = _ConstructorParam;
861
+ var ConstructorInject = _ConstructorInject;
860
862
 
861
- var constructorParam = createDecoratorExp(ConstructorParam);
863
+ var constructorInject = createDecoratorExp(ConstructorInject);
862
864
 
863
865
  let _initClass$t;
864
866
  /**
@@ -971,6 +973,9 @@ class MetadataRepository {
971
973
  case KindMethod:
972
974
  this.addMethodKindMetadata(beDecoratedCls, field, metadataClass, metadataParam);
973
975
  break;
976
+ case KindGetter:
977
+ this.addGetterKindMetadata(beDecoratedCls, field, metadataClass, metadataParam);
978
+ break;
974
979
  }
975
980
  }
976
981
  }
@@ -994,7 +999,8 @@ class MetadataRepository {
994
999
  config = {
995
1000
  classMetadata: [],
996
1001
  fieldMetadata: new Map(),
997
- methodMetadata: new Map()
1002
+ methodMetadata: new Map(),
1003
+ getterMetadata: new Map()
998
1004
  };
999
1005
  map.set(cls, config);
1000
1006
  }
@@ -1044,6 +1050,22 @@ class MetadataRepository {
1044
1050
  const metadata = instantiateMetadata(MetadataCls, args);
1045
1051
  methodMetas.push(metadata);
1046
1052
  }
1053
+ addGetterKindMetadata(Cls, fieldName, MetadataCls, args) {
1054
+ let config = this.getMetadataByClass(Cls);
1055
+ if (!config) {
1056
+ config = this.addToMap(Cls);
1057
+ }
1058
+ const {
1059
+ getterMetadata
1060
+ } = config;
1061
+ let methodMetas = getterMetadata.get(fieldName);
1062
+ if (!methodMetas) {
1063
+ methodMetas = [];
1064
+ getterMetadata.set(fieldName, methodMetas);
1065
+ }
1066
+ const metadata = instantiateMetadata(MetadataCls, args);
1067
+ methodMetas.push(metadata);
1068
+ }
1047
1069
  /**
1048
1070
  * 获取指定类的类类型的元数据
1049
1071
  * @param beDecoratedCls 指定类
@@ -1448,7 +1470,7 @@ class ComponentMetadataClass {
1448
1470
  * 2. 不能和其他component复合装饰器同时使用
1449
1471
  */
1450
1472
  /**
1451
- * constructor-param
1473
+ * constructor-inject
1452
1474
  * 1. 只能用在class上,且只能装饰一次
1453
1475
  */
1454
1476
  /**
@@ -2084,7 +2106,8 @@ class IocComponentFactory {
2084
2106
  const {
2085
2107
  classMetadata,
2086
2108
  methodMetadata,
2087
- fieldMetadata
2109
+ fieldMetadata,
2110
+ getterMetadata
2088
2111
  } = metadatas;
2089
2112
  for (const meta of classMetadata) {
2090
2113
  const option = getCreateDecoratorOption(meta.constructor);
@@ -2114,6 +2137,17 @@ class IocComponentFactory {
2114
2137
  }
2115
2138
  }
2116
2139
  }
2140
+ for (const [getter, metaList] of getterMetadata.entries()) {
2141
+ for (const meta of metaList) {
2142
+ const option = getCreateDecoratorOption(meta.constructor);
2143
+ if (option) {
2144
+ option.componentPostConstruct.call(component, meta, application, {
2145
+ name: getter,
2146
+ kind: KindGetter
2147
+ });
2148
+ }
2149
+ }
2150
+ }
2117
2151
  }
2118
2152
  return component;
2119
2153
  }
@@ -2163,11 +2197,11 @@ class IocComponentFactory {
2163
2197
  }
2164
2198
  instantiatingStage.add(targetDefinition.cls);
2165
2199
  const constructorArgs = [];
2166
- const constructorParams = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorParam);
2167
- if (constructorParams.length > 0) {
2200
+ const constructorInject = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorInject);
2201
+ if (constructorInject.length > 0) {
2168
2202
  // 因为元数据不能重复,所以只有一个
2169
- const constructorParamsParams = constructorParams[0].value;
2170
- for (const dependency of constructorParamsParams) {
2203
+ const constructorInjectParams = constructorInject[0].value;
2204
+ for (const dependency of constructorInjectParams) {
2171
2205
  if (dependency === undefined) {
2172
2206
  constructorArgs.push(undefined);
2173
2207
  } else {
@@ -2859,7 +2893,7 @@ let _Memoized;
2859
2893
  new class extends _identity {
2860
2894
  static [class Memoized extends Metadata {
2861
2895
  static {
2862
- [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method, Target.Type.Field])], [], 0, void 0, Metadata).c;
2896
+ [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method, Target.Type.Field, Target.Type.Getter])], [], 0, void 0, Metadata).c;
2863
2897
  }
2864
2898
  }];
2865
2899
  $$id = "Memoized";
@@ -2937,6 +2971,19 @@ var memoized = createDecoratorExp(Memoized, {
2937
2971
  const diagnose = createDiagnose(DiagnoseCode.CO10028, this.constructor.name, name, name, type);
2938
2972
  console.error(stringifyDiagnose(diagnose));
2939
2973
  }
2974
+ } else if (kind === KindGetter) {
2975
+ const descriptor = Object.getOwnPropertyDescriptor(this.constructor.prototype, name);
2976
+ const getter = descriptor?.get;
2977
+ if (typeof getter !== 'function') {
2978
+ console.error("不应该拿不到getter函数");
2979
+ return;
2980
+ }
2981
+ const subscriber = new Subscriber(getter.bind(this));
2982
+ const memoizedGetter = subscriber.memoizedFn;
2983
+ Object.defineProperty(this, name, {
2984
+ ...descriptor,
2985
+ get: memoizedGetter
2986
+ });
2940
2987
  } else ;
2941
2988
  }
2942
2989
  });
@@ -7901,7 +7948,7 @@ let _Route;
7901
7948
  new class extends _identity {
7902
7949
  static [class Route {
7903
7950
  static {
7904
- [_Route, _initClass$6] = _applyDecs2311(this, [store()], []).c;
7951
+ [_Route, _initClass$6] = _applyDecs2311(this, [component()], []).c;
7905
7952
  }
7906
7953
  // window.location.pathname
7907
7954
  pathname;
@@ -7923,7 +7970,7 @@ let _HistoryRouter;
7923
7970
  new class extends _identity {
7924
7971
  static [class HistoryRouter extends Router {
7925
7972
  static {
7926
- [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorParam([Render])], [], 0, void 0, Router).c;
7973
+ [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorInject([Render])], [], 0, void 0, Router).c;
7927
7974
  }
7928
7975
  constructor(render) {
7929
7976
  super();
@@ -8075,7 +8122,7 @@ exports.Bind = Bind;
8075
8122
  exports.Children = Children;
8076
8123
  exports.Component = Component;
8077
8124
  exports.Configuration = Configuration;
8078
- exports.ConstructorParam = ConstructorParam;
8125
+ exports.ConstructorInject = ConstructorInject;
8079
8126
  exports.Cookie = Cookie;
8080
8127
  exports.Flow = Flow;
8081
8128
  exports.GlobalData = GlobalData;
@@ -8116,7 +8163,7 @@ exports.autowired = autowired;
8116
8163
  exports.bind = bind;
8117
8164
  exports.component = component;
8118
8165
  exports.configuration = configuration;
8119
- exports.constructorParam = constructorParam;
8166
+ exports.constructorInject = constructorInject;
8120
8167
  exports.cookie = cookie;
8121
8168
  exports.createDecoratorExp = createDecoratorExp;
8122
8169
  exports.createPlaceholderDecoratorExp = createPlaceholderDecoratorExp;
package/dist/index.d.ts CHANGED
@@ -167,18 +167,21 @@ declare interface BizMetadata {
167
167
  classMetadata: Metadata[];
168
168
  fieldMetadata: Map<Field, Metadata[]>;
169
169
  methodMetadata: Map<Field, Metadata[]>;
170
+ getterMetadata: Map<Field, Metadata[]>;
170
171
  }
171
172
 
172
173
  declare interface BizMetadata_2 {
173
174
  classMetadata: Metadata_2[];
174
175
  fieldMetadata: Map<Field_2, Metadata_2[]>;
175
176
  methodMetadata: Map<Field_2, Metadata_2[]>;
177
+ getterMetadata: Map<Field_2, Metadata_2[]>;
176
178
  }
177
179
 
178
180
  declare interface BizMetadata_3 {
179
181
  classMetadata: Metadata_4[];
180
182
  fieldMetadata: Map<Field_3, Metadata_4[]>;
181
183
  methodMetadata: Map<Field_3, Metadata_4[]>;
184
+ getterMetadata: Map<Field_3, Metadata_4[]>;
182
185
  }
183
186
 
184
187
  /**
@@ -221,7 +224,12 @@ declare type ComponentClassPostConstructFn = (metadata: Metadata, application: A
221
224
  */
222
225
  declare type ComponentFieldPostConstructFn = (metadata: Metadata, application: Application, target: {
223
226
  name: Field;
224
- kind: Kind;
227
+ kind: typeof KindField;
228
+ }) => void;
229
+
230
+ declare type ComponentGetterPostConstructFn = (metadata: Metadata, application: Application, target: {
231
+ name: Field;
232
+ kind: typeof KindGetter;
225
233
  }) => void;
226
234
 
227
235
  declare class ComponentMetadataClass {
@@ -283,10 +291,10 @@ declare class ComponentMetadataClass_3 {
283
291
  */
284
292
  declare type ComponentMethodPostConstructFn = (metadata: Metadata, application: Application, target: {
285
293
  name: Field;
286
- kind: Kind;
294
+ kind: typeof KindMethod;
287
295
  }) => void;
288
296
 
289
- declare type ComponentPostConstruct = ComponentClassPostConstructFn | ComponentMethodPostConstructFn | ComponentFieldPostConstructFn;
297
+ declare type ComponentPostConstruct = ComponentClassPostConstructFn | ComponentMethodPostConstructFn | ComponentFieldPostConstructFn | ComponentGetterPostConstructFn;
290
298
 
291
299
  /**
292
300
  * @public
@@ -314,11 +322,11 @@ declare type ConstructOption_3 = {
314
322
  /**
315
323
  * @public
316
324
  */
317
- export declare class ConstructorParam extends Metadata {
325
+ export declare class ConstructorInject extends Metadata {
318
326
  value: Class<any>[];
319
327
  }
320
328
 
321
- export declare const constructorParam: () => Decorator<ClassDecoratorContext>;
329
+ export declare const constructorInject: () => Decorator<ClassDecoratorContext>;
322
330
 
323
331
  /**
324
332
  * @public
@@ -760,11 +768,11 @@ declare function jsx(component: any, config: any, maybeKey?: any): {
760
768
  export { jsx }
761
769
  export { jsx as jsxs }
762
770
 
763
- declare type Kind = typeof KindClass | typeof KindField | typeof KindMethod;
771
+ declare type Kind = typeof KindClass | typeof KindField | typeof KindMethod | typeof KindGetter;
764
772
 
765
- declare type Kind_2 = typeof KindClass_2 | typeof KindField_2 | typeof KindMethod_2;
773
+ declare type Kind_2 = typeof KindClass_2 | typeof KindField_2 | typeof KindMethod_2 | typeof KindGetter_2;
766
774
 
767
- declare type Kind_3 = typeof KindClass_3 | typeof KindField_3 | typeof KindMethod_3;
775
+ declare type Kind_3 = typeof KindClass_3 | typeof KindField_3 | typeof KindMethod_3 | typeof KindGetter_3;
768
776
 
769
777
  export declare const KindClass = "class";
770
778
 
@@ -778,6 +786,12 @@ declare const KindField_2 = "field";
778
786
 
779
787
  declare const KindField_3 = "field";
780
788
 
789
+ declare const KindGetter = "getter";
790
+
791
+ declare const KindGetter_2 = "getter";
792
+
793
+ declare const KindGetter_3 = "getter";
794
+
781
795
  export declare const KindMethod = "method";
782
796
 
783
797
  declare const KindMethod_2 = "method";
@@ -854,11 +868,13 @@ declare class MetadataRepository {
854
868
  classMetadata: Metadata[];
855
869
  fieldMetadata?: Map<Field, Metadata[]>;
856
870
  methodMetadata?: Map<Field, Metadata[]>;
871
+ getterMetadata?: Map<Field, Metadata[]>;
857
872
  };
858
873
  private addToMap;
859
874
  addClassKindMetadata(cls: Class<any>, MetadataCls?: Class<Metadata>, args?: any): void;
860
875
  addFieldKindMetadata(Cls: Class<any>, fieldName: Field, MetadataCls: Class<Metadata>, args?: any): void;
861
876
  addMethodKindMetadata(Cls: Class<any>, fieldName: Field, MetadataCls: Class<Metadata>, args?: any): void;
877
+ addGetterKindMetadata(Cls: Class<any>, fieldName: Field, MetadataCls: Class<Metadata>, args?: any): void;
862
878
  /**
863
879
  * 获取指定类的类类型的元数据
864
880
  * @param beDecoratedCls 指定类
@@ -911,11 +927,13 @@ declare class MetadataRepository_2 {
911
927
  classMetadata: Metadata_2[];
912
928
  fieldMetadata?: Map<Field_2, Metadata_2[]>;
913
929
  methodMetadata?: Map<Field_2, Metadata_2[]>;
930
+ getterMetadata?: Map<Field_2, Metadata_2[]>;
914
931
  };
915
932
  private addToMap;
916
933
  addClassKindMetadata(cls: Class<any>, MetadataCls?: Class<Metadata_2>, args?: any): void;
917
934
  addFieldKindMetadata(Cls: Class<any>, fieldName: Field_2, MetadataCls: Class<Metadata_2>, args?: any): void;
918
935
  addMethodKindMetadata(Cls: Class<any>, fieldName: Field_2, MetadataCls: Class<Metadata_2>, args?: any): void;
936
+ addGetterKindMetadata(Cls: Class<any>, fieldName: Field_2, MetadataCls: Class<Metadata_2>, args?: any): void;
919
937
  /**
920
938
  * 获取指定类的类类型的元数据
921
939
  * @param beDecoratedCls 指定类
@@ -968,11 +986,13 @@ declare class MetadataRepository_3 {
968
986
  classMetadata: Metadata_4[];
969
987
  fieldMetadata?: Map<Field_3, Metadata_4[]>;
970
988
  methodMetadata?: Map<Field_3, Metadata_4[]>;
989
+ getterMetadata?: Map<Field_3, Metadata_4[]>;
971
990
  };
972
991
  private addToMap;
973
992
  addClassKindMetadata(cls: Class<any>, MetadataCls?: Class<Metadata_4>, args?: any): void;
974
993
  addFieldKindMetadata(Cls: Class<any>, fieldName: Field_3, MetadataCls: Class<Metadata_4>, args?: any): void;
975
994
  addMethodKindMetadata(Cls: Class<any>, fieldName: Field_3, MetadataCls: Class<Metadata_4>, args?: any): void;
995
+ addGetterKindMetadata(Cls: Class<any>, fieldName: Field_3, MetadataCls: Class<Metadata_4>, args?: any): void;
976
996
  /**
977
997
  * 获取指定类的类类型的元数据
978
998
  * @param beDecoratedCls 指定类
@@ -1019,18 +1039,21 @@ declare interface MetaMetadata {
1019
1039
  classMetadata: Metadata[];
1020
1040
  fieldMetadata: Map<Field, Metadata[]>;
1021
1041
  methodMetadata: Map<Field, Metadata[]>;
1042
+ getterMetadata: Map<Field, Metadata[]>;
1022
1043
  }
1023
1044
 
1024
1045
  declare interface MetaMetadata_2 {
1025
1046
  classMetadata: Metadata_2[];
1026
1047
  fieldMetadata: Map<Field_2, Metadata_2[]>;
1027
1048
  methodMetadata: Map<Field_2, Metadata_2[]>;
1049
+ getterMetadata: Map<Field_2, Metadata_2[]>;
1028
1050
  }
1029
1051
 
1030
1052
  declare interface MetaMetadata_3 {
1031
1053
  classMetadata: Metadata_4[];
1032
1054
  fieldMetadata: Map<Field_3, Metadata_4[]>;
1033
1055
  methodMetadata: Map<Field_3, Metadata_4[]>;
1056
+ getterMetadata: Map<Field_3, Metadata_4[]>;
1034
1057
  }
1035
1058
 
1036
1059
  /**
@@ -1267,7 +1290,8 @@ export declare const target: DecoratorExpWithDecoratorSelf<Type[]>;
1267
1290
  export declare enum Type {
1268
1291
  Class = "class",
1269
1292
  Field = "field",
1270
- Method = "method"
1293
+ Method = "method",
1294
+ Getter = "getter"
1271
1295
  }
1272
1296
 
1273
1297
  /**
package/dist/index.esm.js CHANGED
@@ -619,8 +619,8 @@ function createDecoratorExpFactory(fn) {
619
619
  }
620
620
  case KindMethod:
621
621
  case KindField:
622
- break;
623
622
  case KindGetter:
623
+ break;
624
624
  case KindSetter:
625
625
  case KindAccessor:
626
626
  default:
@@ -630,6 +630,7 @@ function createDecoratorExpFactory(fn) {
630
630
  switch (context.kind) {
631
631
  case KindField:
632
632
  case KindMethod:
633
+ case KindGetter:
633
634
  fn(isPlaceholderExp, this.constructor, {
634
635
  metadataKind: context.kind,
635
636
  metadataClass: MetaClsOrPlaceholderMetaCls,
@@ -715,6 +716,7 @@ var Type;
715
716
  Type[Type["Class"] = KindClass] = "Class";
716
717
  Type[Type["Field"] = KindField] = "Field";
717
718
  Type[Type["Method"] = KindMethod] = "Method";
719
+ Type[Type["Getter"] = KindGetter] = "Getter";
718
720
  })(Type || (Type = {}));
719
721
  /**
720
722
  * @public
@@ -841,22 +843,22 @@ let _initClass$u;
841
843
  /**
842
844
  * @public
843
845
  */
844
- let _ConstructorParam;
846
+ let _ConstructorInject;
845
847
  new class extends _identity {
846
- static [class ConstructorParam extends Metadata {
848
+ static [class ConstructorInject extends Metadata {
847
849
  static {
848
- [_ConstructorParam, _initClass$u] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
850
+ [_ConstructorInject, _initClass$u] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
849
851
  }
850
852
  value;
851
853
  }];
852
- $$id = "ConstructorParam";
854
+ $$id = "ConstructorInject";
853
855
  constructor() {
854
- super(_ConstructorParam), _initClass$u();
856
+ super(_ConstructorInject), _initClass$u();
855
857
  }
856
858
  }();
857
- var ConstructorParam = _ConstructorParam;
859
+ var ConstructorInject = _ConstructorInject;
858
860
 
859
- var constructorParam = createDecoratorExp(ConstructorParam);
861
+ var constructorInject = createDecoratorExp(ConstructorInject);
860
862
 
861
863
  let _initClass$t;
862
864
  /**
@@ -969,6 +971,9 @@ class MetadataRepository {
969
971
  case KindMethod:
970
972
  this.addMethodKindMetadata(beDecoratedCls, field, metadataClass, metadataParam);
971
973
  break;
974
+ case KindGetter:
975
+ this.addGetterKindMetadata(beDecoratedCls, field, metadataClass, metadataParam);
976
+ break;
972
977
  }
973
978
  }
974
979
  }
@@ -992,7 +997,8 @@ class MetadataRepository {
992
997
  config = {
993
998
  classMetadata: [],
994
999
  fieldMetadata: new Map(),
995
- methodMetadata: new Map()
1000
+ methodMetadata: new Map(),
1001
+ getterMetadata: new Map()
996
1002
  };
997
1003
  map.set(cls, config);
998
1004
  }
@@ -1042,6 +1048,22 @@ class MetadataRepository {
1042
1048
  const metadata = instantiateMetadata(MetadataCls, args);
1043
1049
  methodMetas.push(metadata);
1044
1050
  }
1051
+ addGetterKindMetadata(Cls, fieldName, MetadataCls, args) {
1052
+ let config = this.getMetadataByClass(Cls);
1053
+ if (!config) {
1054
+ config = this.addToMap(Cls);
1055
+ }
1056
+ const {
1057
+ getterMetadata
1058
+ } = config;
1059
+ let methodMetas = getterMetadata.get(fieldName);
1060
+ if (!methodMetas) {
1061
+ methodMetas = [];
1062
+ getterMetadata.set(fieldName, methodMetas);
1063
+ }
1064
+ const metadata = instantiateMetadata(MetadataCls, args);
1065
+ methodMetas.push(metadata);
1066
+ }
1045
1067
  /**
1046
1068
  * 获取指定类的类类型的元数据
1047
1069
  * @param beDecoratedCls 指定类
@@ -1446,7 +1468,7 @@ class ComponentMetadataClass {
1446
1468
  * 2. 不能和其他component复合装饰器同时使用
1447
1469
  */
1448
1470
  /**
1449
- * constructor-param
1471
+ * constructor-inject
1450
1472
  * 1. 只能用在class上,且只能装饰一次
1451
1473
  */
1452
1474
  /**
@@ -2082,7 +2104,8 @@ class IocComponentFactory {
2082
2104
  const {
2083
2105
  classMetadata,
2084
2106
  methodMetadata,
2085
- fieldMetadata
2107
+ fieldMetadata,
2108
+ getterMetadata
2086
2109
  } = metadatas;
2087
2110
  for (const meta of classMetadata) {
2088
2111
  const option = getCreateDecoratorOption(meta.constructor);
@@ -2112,6 +2135,17 @@ class IocComponentFactory {
2112
2135
  }
2113
2136
  }
2114
2137
  }
2138
+ for (const [getter, metaList] of getterMetadata.entries()) {
2139
+ for (const meta of metaList) {
2140
+ const option = getCreateDecoratorOption(meta.constructor);
2141
+ if (option) {
2142
+ option.componentPostConstruct.call(component, meta, application, {
2143
+ name: getter,
2144
+ kind: KindGetter
2145
+ });
2146
+ }
2147
+ }
2148
+ }
2115
2149
  }
2116
2150
  return component;
2117
2151
  }
@@ -2161,11 +2195,11 @@ class IocComponentFactory {
2161
2195
  }
2162
2196
  instantiatingStage.add(targetDefinition.cls);
2163
2197
  const constructorArgs = [];
2164
- const constructorParams = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorParam);
2165
- if (constructorParams.length > 0) {
2198
+ const constructorInject = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorInject);
2199
+ if (constructorInject.length > 0) {
2166
2200
  // 因为元数据不能重复,所以只有一个
2167
- const constructorParamsParams = constructorParams[0].value;
2168
- for (const dependency of constructorParamsParams) {
2201
+ const constructorInjectParams = constructorInject[0].value;
2202
+ for (const dependency of constructorInjectParams) {
2169
2203
  if (dependency === undefined) {
2170
2204
  constructorArgs.push(undefined);
2171
2205
  } else {
@@ -2857,7 +2891,7 @@ let _Memoized;
2857
2891
  new class extends _identity {
2858
2892
  static [class Memoized extends Metadata {
2859
2893
  static {
2860
- [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method, Target.Type.Field])], [], 0, void 0, Metadata).c;
2894
+ [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method, Target.Type.Field, Target.Type.Getter])], [], 0, void 0, Metadata).c;
2861
2895
  }
2862
2896
  }];
2863
2897
  $$id = "Memoized";
@@ -2935,6 +2969,19 @@ var memoized = createDecoratorExp(Memoized, {
2935
2969
  const diagnose = createDiagnose(DiagnoseCode.CO10028, this.constructor.name, name, name, type);
2936
2970
  console.error(stringifyDiagnose(diagnose));
2937
2971
  }
2972
+ } else if (kind === KindGetter) {
2973
+ const descriptor = Object.getOwnPropertyDescriptor(this.constructor.prototype, name);
2974
+ const getter = descriptor?.get;
2975
+ if (typeof getter !== 'function') {
2976
+ console.error("不应该拿不到getter函数");
2977
+ return;
2978
+ }
2979
+ const subscriber = new Subscriber(getter.bind(this));
2980
+ const memoizedGetter = subscriber.memoizedFn;
2981
+ Object.defineProperty(this, name, {
2982
+ ...descriptor,
2983
+ get: memoizedGetter
2984
+ });
2938
2985
  } else ;
2939
2986
  }
2940
2987
  });
@@ -7899,7 +7946,7 @@ let _Route;
7899
7946
  new class extends _identity {
7900
7947
  static [class Route {
7901
7948
  static {
7902
- [_Route, _initClass$6] = _applyDecs2311(this, [store()], []).c;
7949
+ [_Route, _initClass$6] = _applyDecs2311(this, [component()], []).c;
7903
7950
  }
7904
7951
  // window.location.pathname
7905
7952
  pathname;
@@ -7921,7 +7968,7 @@ let _HistoryRouter;
7921
7968
  new class extends _identity {
7922
7969
  static [class HistoryRouter extends Router {
7923
7970
  static {
7924
- [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorParam([Render])], [], 0, void 0, Router).c;
7971
+ [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorInject([Render])], [], 0, void 0, Router).c;
7925
7972
  }
7926
7973
  constructor(render) {
7927
7974
  super();
@@ -8066,4 +8113,4 @@ var WebApplication = _WebApplication;
8066
8113
 
8067
8114
  var webApplication = createDecoratorExp(WebApplication);
8068
8115
 
8069
- export { Api, Application, Autowired, Bind, Children, Component, Configuration, ConstructorParam, Cookie, Flow, GlobalData, _HistoryRouter_default as HistoryRouter, Id, KindClass, KindField, KindMethod, Layout, _LocalStorage_default as LocalStorage, LocalStorage as LocalStorageMeta, Memoized, Metadata, Page, PropertiesConfig, Qualifier, ReactNoopUpdateQueue, Reactive, Ref$1 as Ref, Refs, Render, Route, RouteMeta, Router, Router$1 as RouterMeta, SCOPE, Scope, _SessionStorage_default as SessionStorage, SessionStorage as SessionStorageMeta, Store, Target, Util, Value, View, WebApplication, _WebRender_default as WebRender, api, autowired, bind, component, configuration, constructorParam, cookie, createDecoratorExp, createPlaceholderDecoratorExp, definePublisher, flow, globalData, id, jsx, jsx as jsxs, layout, localStorageDecorator as localStorage, memoized, page, qualifier, reactive, ref, refs, route, scope, sessionStorageDecorator as sessionStorage, store, target, util, value, view, webApplication };
8116
+ export { Api, Application, Autowired, Bind, Children, Component, Configuration, ConstructorInject, Cookie, Flow, GlobalData, _HistoryRouter_default as HistoryRouter, Id, KindClass, KindField, KindMethod, Layout, _LocalStorage_default as LocalStorage, LocalStorage as LocalStorageMeta, Memoized, Metadata, Page, PropertiesConfig, Qualifier, ReactNoopUpdateQueue, Reactive, Ref$1 as Ref, Refs, Render, Route, RouteMeta, Router, Router$1 as RouterMeta, SCOPE, Scope, _SessionStorage_default as SessionStorage, SessionStorage as SessionStorageMeta, Store, Target, Util, Value, View, WebApplication, _WebRender_default as WebRender, api, autowired, bind, component, configuration, constructorInject, cookie, createDecoratorExp, createPlaceholderDecoratorExp, definePublisher, flow, globalData, id, jsx, jsx as jsxs, layout, localStorageDecorator as localStorage, memoized, page, qualifier, reactive, ref, refs, route, scope, sessionStorageDecorator as sessionStorage, store, target, util, value, view, webApplication };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cocojs/mvc",
3
- "version": "0.1.0-beta.12",
3
+ "version": "0.1.0-beta.14",
4
4
  "description": "由装饰器驱动,快速构建可扩展的 Web 应用。",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",