@cocojs/mvc 0.1.0-beta.11 → 0.1.0-beta.13

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
@@ -327,6 +327,8 @@ var DiagnoseCode;
327
327
  DiagnoseCode["CO10025"] = "CO10025";
328
328
  DiagnoseCode["CO10026"] = "CO10026";
329
329
  DiagnoseCode["CO10027"] = "CO10027";
330
+ DiagnoseCode["CO10028"] = "CO10028";
331
+ DiagnoseCode["CO10029"] = "CO10029";
330
332
  })(DiagnoseCode || (DiagnoseCode = {}));
331
333
  const DiagnoseCodeMsg = {
332
334
  [DiagnoseCode.CO10001]: '每个类最多只能添加一个component装饰器,但 %s 添加了:%s',
@@ -355,7 +357,9 @@ const DiagnoseCodeMsg = {
355
357
  [DiagnoseCode.CO10024]: `元数据类 %s 存在多个组件装饰器 %s,一个元数据类最多只能有一个组件装饰器。`,
356
358
  [DiagnoseCode.CO10025]: `findClassKindMetadataRecursively的第二个参数 %s 必须是元数据类。`,
357
359
  [DiagnoseCode.CO10026]: '在一个字段上不能添加多次同一个装饰器,但 %s 上 %s 字段存在重复装饰器: %s',
358
- [DiagnoseCode.CO10027]: '在一个方法上不能添加多次同一个装饰器,但 %s 上 %s 字段存在重复装饰器: %s'
360
+ [DiagnoseCode.CO10027]: '在一个方法上不能添加多次同一个装饰器,但 %s 上 %s 字段存在重复装饰器: %s',
361
+ [DiagnoseCode.CO10028]: '%s 类 %s 字段上memoized装饰器,但 %s 的值必须是函数,不能是 %s',
362
+ [DiagnoseCode.CO10029]: '更新 %s 组件的 %s 字段需要通过视图组件的属性更新,不能独立使用store更新或多次更新'
359
363
  };
360
364
  function createDiagnose(code, ...args) {
361
365
  return {
@@ -839,22 +843,22 @@ let _initClass$u;
839
843
  /**
840
844
  * @public
841
845
  */
842
- let _ConstructorParam;
846
+ let _ConstructorInject;
843
847
  new class extends _identity {
844
- static [class ConstructorParam extends Metadata {
848
+ static [class ConstructorInject extends Metadata {
845
849
  static {
846
- [_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;
847
851
  }
848
852
  value;
849
853
  }];
850
- $$id = "ConstructorParam";
854
+ $$id = "ConstructorInject";
851
855
  constructor() {
852
- super(_ConstructorParam), _initClass$u();
856
+ super(_ConstructorInject), _initClass$u();
853
857
  }
854
858
  }();
855
- var ConstructorParam = _ConstructorParam;
859
+ var ConstructorInject = _ConstructorInject;
856
860
 
857
- var constructorParam = createDecoratorExp(ConstructorParam);
861
+ var constructorInject = createDecoratorExp(ConstructorInject);
858
862
 
859
863
  let _initClass$t;
860
864
  /**
@@ -928,12 +932,15 @@ new class extends _identity {
928
932
  var Value = _Value;
929
933
 
930
934
  var value = createDecoratorExp(Value, {
931
- componentPostConstruct: function (metadata, application, field) {
935
+ componentPostConstruct: function (metadata, application, target) {
932
936
  const path = metadata.value;
933
937
  if (typeof path !== 'string' || !path.trim()) {
934
938
  return;
935
939
  }
936
- this[field] = application.propertiesConfig.getValue(path);
940
+ const {
941
+ name
942
+ } = target;
943
+ this[name] = application.propertiesConfig.getValue(path);
937
944
  }
938
945
  });
939
946
 
@@ -1441,7 +1448,7 @@ class ComponentMetadataClass {
1441
1448
  * 2. 不能和其他component复合装饰器同时使用
1442
1449
  */
1443
1450
  /**
1444
- * constructor-param
1451
+ * constructor-inject
1445
1452
  * 1. 只能用在class上,且只能装饰一次
1446
1453
  */
1447
1454
  /**
@@ -2089,7 +2096,10 @@ class IocComponentFactory {
2089
2096
  for (const meta of metaList) {
2090
2097
  const option = getCreateDecoratorOption(meta.constructor);
2091
2098
  if (option) {
2092
- option.componentPostConstruct.call(component, meta, application, field);
2099
+ option.componentPostConstruct.call(component, meta, application, {
2100
+ name: field,
2101
+ kind: KindField
2102
+ });
2093
2103
  }
2094
2104
  }
2095
2105
  }
@@ -2097,7 +2107,10 @@ class IocComponentFactory {
2097
2107
  for (const meta of metaList) {
2098
2108
  const option = getCreateDecoratorOption(meta.constructor);
2099
2109
  if (option) {
2100
- option.componentPostConstruct.call(component, meta, application, method);
2110
+ option.componentPostConstruct.call(component, meta, application, {
2111
+ name: method,
2112
+ kind: KindMethod
2113
+ });
2101
2114
  }
2102
2115
  }
2103
2116
  }
@@ -2150,11 +2163,11 @@ class IocComponentFactory {
2150
2163
  }
2151
2164
  instantiatingStage.add(targetDefinition.cls);
2152
2165
  const constructorArgs = [];
2153
- const constructorParams = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorParam);
2154
- if (constructorParams.length > 0) {
2166
+ const constructorInject = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorInject);
2167
+ if (constructorInject.length > 0) {
2155
2168
  // 因为元数据不能重复,所以只有一个
2156
- const constructorParamsParams = constructorParams[0].value;
2157
- for (const dependency of constructorParamsParams) {
2169
+ const constructorInjectParams = constructorInject[0].value;
2170
+ for (const dependency of constructorInjectParams) {
2158
2171
  if (dependency === undefined) {
2159
2172
  constructorArgs.push(undefined);
2160
2173
  } else {
@@ -2481,8 +2494,11 @@ new class extends _identity {
2481
2494
  var Bind = _Bind;
2482
2495
 
2483
2496
  var bind = createDecoratorExp(Bind, {
2484
- componentPostConstruct: function (metadata, application, field) {
2485
- this[field] = this[field].bind(this);
2497
+ componentPostConstruct: function (metadata, application, target) {
2498
+ const {
2499
+ name
2500
+ } = target;
2501
+ this[name] = this[name].bind(this);
2486
2502
  }
2487
2503
  });
2488
2504
 
@@ -2843,7 +2859,7 @@ let _Memoized;
2843
2859
  new class extends _identity {
2844
2860
  static [class Memoized extends Metadata {
2845
2861
  static {
2846
- [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method])], [], 0, void 0, Metadata).c;
2862
+ [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method, Target.Type.Field])], [], 0, void 0, Metadata).c;
2847
2863
  }
2848
2864
  }];
2849
2865
  $$id = "Memoized";
@@ -2897,11 +2913,31 @@ class Subscriber {
2897
2913
  }
2898
2914
  }
2899
2915
 
2916
+ function isArrowFunction(v) {
2917
+ return !v.hasOwnProperty('prototype');
2918
+ }
2900
2919
  var memoized = createDecoratorExp(Memoized, {
2901
- componentPostConstruct: function (metadata, application, field) {
2902
- const fn = this[field];
2903
- const subscriber = new Subscriber(fn.bind(this));
2904
- this[field] = subscriber.memoizedFn;
2920
+ componentPostConstruct: function (metadata, application, target) {
2921
+ const {
2922
+ name,
2923
+ kind
2924
+ } = target;
2925
+ if (kind === KindMethod) {
2926
+ const fn = this[name];
2927
+ const subscriber = new Subscriber(fn.bind(this));
2928
+ this[name] = subscriber.memoizedFn;
2929
+ } else if (kind === KindField) {
2930
+ const func = this[name];
2931
+ const type = typeof func;
2932
+ if (type === 'function') {
2933
+ const bindThisFunc = isArrowFunction(func) ? func : func.bind(this);
2934
+ const subscriber = new Subscriber(bindThisFunc);
2935
+ this[name] = subscriber.memoizedFn;
2936
+ } else {
2937
+ const diagnose = createDiagnose(DiagnoseCode.CO10028, this.constructor.name, name, name, type);
2938
+ console.error(stringifyDiagnose(diagnose));
2939
+ }
2940
+ } else ;
2905
2941
  }
2906
2942
  });
2907
2943
 
@@ -2998,7 +3034,10 @@ function definePublisher(object, field, getter, setter) {
2998
3034
  }
2999
3035
 
3000
3036
  var reactive = createDecoratorExp(Reactive, {
3001
- componentPostConstruct(metadata, application, name) {
3037
+ componentPostConstruct(metadata, application, target) {
3038
+ const {
3039
+ name
3040
+ } = target;
3002
3041
  // TODO: 限制只能在store或view组件内部
3003
3042
  let value = this[name];
3004
3043
  definePublisher(this, name, function getter() {
@@ -3036,8 +3075,11 @@ new class extends _identity {
3036
3075
  var Ref$1 = _Ref;
3037
3076
 
3038
3077
  var ref = createDecoratorExp(Ref$1, {
3039
- componentPostConstruct: function (metadata, application, field) {
3040
- this[field] = {
3078
+ componentPostConstruct: function (metadata, application, target) {
3079
+ const {
3080
+ name
3081
+ } = target;
3082
+ this[name] = {
3041
3083
  current: null
3042
3084
  };
3043
3085
  }
@@ -3062,8 +3104,8 @@ new class extends _identity {
3062
3104
  var Refs = _Refs;
3063
3105
 
3064
3106
  var refs = createDecoratorExp(Refs, {
3065
- componentPostConstruct: function (metadata, application, field) {
3066
- this[field] = {};
3107
+ componentPostConstruct: function (metadata, application, target) {
3108
+ this[target.name] = {};
3067
3109
  }
3068
3110
  });
3069
3111
 
@@ -6299,7 +6341,7 @@ const storeComponentUpdater = {
6299
6341
  // 使用后立刻清空标记
6300
6342
  inst[bindViewInst] = null;
6301
6343
  if (viewInstance === null || viewInstance === undefined) {
6302
- console.error("store只能通过视图组件的属性更新状态。");
6344
+ console.error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10029, inst.constructor.name, field)));
6303
6345
  return;
6304
6346
  }
6305
6347
  const update = createUpdate(field);
@@ -6319,18 +6361,21 @@ function reactiveStoreField(ctor, viewComponent) {
6319
6361
  // 找到所有的注入
6320
6362
  const Autowired = application.getMetaClassById('Autowired');
6321
6363
  const autowiredFields = application.listFieldByMetadataCls(ctor, Autowired);
6364
+ const Store = application.getMetaClassById('Store');
6322
6365
  autowiredFields.forEach((field) => {
6323
- const storeInst = viewComponent[field];
6324
- Object.defineProperty(viewComponent, field, {
6325
- get() {
6326
- // 每次访问前设置标记
6327
- storeInst[bindViewInst] = viewComponent;
6328
- return storeInst;
6329
- },
6330
- set() {
6331
- console.error('store实例在初始化之后不允许修改');
6332
- }
6333
- });
6366
+ const component = viewComponent[field];
6367
+ if (application.findClassKindMetadataRecursively(component.constructor, Store, 0)) {
6368
+ Object.defineProperty(viewComponent, field, {
6369
+ get() {
6370
+ // 每次访问前设置标记
6371
+ component[bindViewInst] = viewComponent;
6372
+ return component;
6373
+ },
6374
+ set() {
6375
+ console.error('store实例在初始化之后不允许修改');
6376
+ }
6377
+ });
6378
+ }
6334
6379
  });
6335
6380
  }
6336
6381
  /**
@@ -6389,6 +6434,7 @@ function processUpdateQueueForStore(ctor, instance) {
6389
6434
  });
6390
6435
  }
6391
6436
  }
6437
+ // TODO 放在store组件实例化的地方
6392
6438
  function initFiber(storeInstance) {
6393
6439
  if (storeInstance[fiberField]) {
6394
6440
  return;
@@ -7877,7 +7923,7 @@ let _HistoryRouter;
7877
7923
  new class extends _identity {
7878
7924
  static [class HistoryRouter extends Router {
7879
7925
  static {
7880
- [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorParam([Render])], [], 0, void 0, Router).c;
7926
+ [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorInject([Render])], [], 0, void 0, Router).c;
7881
7927
  }
7882
7928
  constructor(render) {
7883
7929
  super();
@@ -8029,7 +8075,7 @@ exports.Bind = Bind;
8029
8075
  exports.Children = Children;
8030
8076
  exports.Component = Component;
8031
8077
  exports.Configuration = Configuration;
8032
- exports.ConstructorParam = ConstructorParam;
8078
+ exports.ConstructorInject = ConstructorInject;
8033
8079
  exports.Cookie = Cookie;
8034
8080
  exports.Flow = Flow;
8035
8081
  exports.GlobalData = GlobalData;
@@ -8070,7 +8116,7 @@ exports.autowired = autowired;
8070
8116
  exports.bind = bind;
8071
8117
  exports.component = component;
8072
8118
  exports.configuration = configuration;
8073
- exports.constructorParam = constructorParam;
8119
+ exports.constructorInject = constructorInject;
8074
8120
  exports.cookie = cookie;
8075
8121
  exports.createDecoratorExp = createDecoratorExp;
8076
8122
  exports.createPlaceholderDecoratorExp = createPlaceholderDecoratorExp;
package/dist/index.d.ts CHANGED
@@ -217,9 +217,12 @@ declare type ComponentClassPostConstructFn = (metadata: Metadata, application: A
217
217
  * @public
218
218
  * @param metadata - 元数据实例对象
219
219
  * @param application - 全局的application对象
220
- * @param field - 被装饰的字段名
220
+ * @param target - 被装饰字段或方法
221
221
  */
222
- declare type ComponentFieldPostConstructFn = (metadata: Metadata, application: Application, field: Field) => void;
222
+ declare type ComponentFieldPostConstructFn = (metadata: Metadata, application: Application, target: {
223
+ name: Field;
224
+ kind: Kind;
225
+ }) => void;
223
226
 
224
227
  declare class ComponentMetadataClass {
225
228
  isComponent: Map<Class<Metadata>, boolean>;
@@ -278,7 +281,10 @@ declare class ComponentMetadataClass_3 {
278
281
  /**
279
282
  * @public
280
283
  */
281
- declare type ComponentMethodPostConstructFn = (metadata: Metadata, application: Application, field: Field) => void;
284
+ declare type ComponentMethodPostConstructFn = (metadata: Metadata, application: Application, target: {
285
+ name: Field;
286
+ kind: Kind;
287
+ }) => void;
282
288
 
283
289
  declare type ComponentPostConstruct = ComponentClassPostConstructFn | ComponentMethodPostConstructFn | ComponentFieldPostConstructFn;
284
290
 
@@ -308,11 +314,11 @@ declare type ConstructOption_3 = {
308
314
  /**
309
315
  * @public
310
316
  */
311
- export declare class ConstructorParam extends Metadata {
317
+ export declare class ConstructorInject extends Metadata {
312
318
  value: Class<any>[];
313
319
  }
314
320
 
315
- export declare const constructorParam: () => Decorator<ClassDecoratorContext>;
321
+ export declare const constructorInject: () => Decorator<ClassDecoratorContext>;
316
322
 
317
323
  /**
318
324
  * @public
@@ -417,6 +423,8 @@ declare enum DiagnoseCode {
417
423
  'CO10025' = 'CO10025', // findClassKindMetadataRecursively参数错误,入参不是元数据类
418
424
  'CO10026' = 'CO10026', // 不能添加多个相同的 field 装饰器
419
425
  'CO10027' = 'CO10027', // 不能添加多个相同的 method 装饰器
426
+ 'CO10028' = 'CO10028', // memoized装饰了field类型,但值不是箭头函数
427
+ 'CO10029' = 'CO10029', // store组件的更新方法不正确
420
428
  }
421
429
 
422
430
  declare enum DiagnoseCode_2 {
@@ -447,6 +455,8 @@ declare enum DiagnoseCode_2 {
447
455
  'CO10025' = 'CO10025', // findClassKindMetadataRecursively参数错误,入参不是元数据类
448
456
  'CO10026' = 'CO10026', // 不能添加多个相同的 field 装饰器
449
457
  'CO10027' = 'CO10027', // 不能添加多个相同的 method 装饰器
458
+ 'CO10028' = 'CO10028', // memoized装饰了field类型,但值不是箭头函数
459
+ 'CO10029' = 'CO10029', // store组件的更新方法不正确
450
460
  }
451
461
 
452
462
  declare enum DiagnoseCode_3 {
@@ -477,6 +487,8 @@ declare enum DiagnoseCode_3 {
477
487
  'CO10025' = 'CO10025', // findClassKindMetadataRecursively参数错误,入参不是元数据类
478
488
  'CO10026' = 'CO10026', // 不能添加多个相同的 field 装饰器
479
489
  'CO10027' = 'CO10027', // 不能添加多个相同的 method 装饰器
490
+ 'CO10028' = 'CO10028', // memoized装饰了field类型,但值不是箭头函数
491
+ 'CO10029' = 'CO10029', // store组件的更新方法不正确
480
492
  }
481
493
 
482
494
  declare class DynamicRoute {
package/dist/index.esm.js CHANGED
@@ -325,6 +325,8 @@ var DiagnoseCode;
325
325
  DiagnoseCode["CO10025"] = "CO10025";
326
326
  DiagnoseCode["CO10026"] = "CO10026";
327
327
  DiagnoseCode["CO10027"] = "CO10027";
328
+ DiagnoseCode["CO10028"] = "CO10028";
329
+ DiagnoseCode["CO10029"] = "CO10029";
328
330
  })(DiagnoseCode || (DiagnoseCode = {}));
329
331
  const DiagnoseCodeMsg = {
330
332
  [DiagnoseCode.CO10001]: '每个类最多只能添加一个component装饰器,但 %s 添加了:%s',
@@ -353,7 +355,9 @@ const DiagnoseCodeMsg = {
353
355
  [DiagnoseCode.CO10024]: `元数据类 %s 存在多个组件装饰器 %s,一个元数据类最多只能有一个组件装饰器。`,
354
356
  [DiagnoseCode.CO10025]: `findClassKindMetadataRecursively的第二个参数 %s 必须是元数据类。`,
355
357
  [DiagnoseCode.CO10026]: '在一个字段上不能添加多次同一个装饰器,但 %s 上 %s 字段存在重复装饰器: %s',
356
- [DiagnoseCode.CO10027]: '在一个方法上不能添加多次同一个装饰器,但 %s 上 %s 字段存在重复装饰器: %s'
358
+ [DiagnoseCode.CO10027]: '在一个方法上不能添加多次同一个装饰器,但 %s 上 %s 字段存在重复装饰器: %s',
359
+ [DiagnoseCode.CO10028]: '%s 类 %s 字段上memoized装饰器,但 %s 的值必须是函数,不能是 %s',
360
+ [DiagnoseCode.CO10029]: '更新 %s 组件的 %s 字段需要通过视图组件的属性更新,不能独立使用store更新或多次更新'
357
361
  };
358
362
  function createDiagnose(code, ...args) {
359
363
  return {
@@ -837,22 +841,22 @@ let _initClass$u;
837
841
  /**
838
842
  * @public
839
843
  */
840
- let _ConstructorParam;
844
+ let _ConstructorInject;
841
845
  new class extends _identity {
842
- static [class ConstructorParam extends Metadata {
846
+ static [class ConstructorInject extends Metadata {
843
847
  static {
844
- [_ConstructorParam, _initClass$u] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
848
+ [_ConstructorInject, _initClass$u] = _applyDecs2311(this, [target([Target.Type.Class])], [], 0, void 0, Metadata).c;
845
849
  }
846
850
  value;
847
851
  }];
848
- $$id = "ConstructorParam";
852
+ $$id = "ConstructorInject";
849
853
  constructor() {
850
- super(_ConstructorParam), _initClass$u();
854
+ super(_ConstructorInject), _initClass$u();
851
855
  }
852
856
  }();
853
- var ConstructorParam = _ConstructorParam;
857
+ var ConstructorInject = _ConstructorInject;
854
858
 
855
- var constructorParam = createDecoratorExp(ConstructorParam);
859
+ var constructorInject = createDecoratorExp(ConstructorInject);
856
860
 
857
861
  let _initClass$t;
858
862
  /**
@@ -926,12 +930,15 @@ new class extends _identity {
926
930
  var Value = _Value;
927
931
 
928
932
  var value = createDecoratorExp(Value, {
929
- componentPostConstruct: function (metadata, application, field) {
933
+ componentPostConstruct: function (metadata, application, target) {
930
934
  const path = metadata.value;
931
935
  if (typeof path !== 'string' || !path.trim()) {
932
936
  return;
933
937
  }
934
- this[field] = application.propertiesConfig.getValue(path);
938
+ const {
939
+ name
940
+ } = target;
941
+ this[name] = application.propertiesConfig.getValue(path);
935
942
  }
936
943
  });
937
944
 
@@ -1439,7 +1446,7 @@ class ComponentMetadataClass {
1439
1446
  * 2. 不能和其他component复合装饰器同时使用
1440
1447
  */
1441
1448
  /**
1442
- * constructor-param
1449
+ * constructor-inject
1443
1450
  * 1. 只能用在class上,且只能装饰一次
1444
1451
  */
1445
1452
  /**
@@ -2087,7 +2094,10 @@ class IocComponentFactory {
2087
2094
  for (const meta of metaList) {
2088
2095
  const option = getCreateDecoratorOption(meta.constructor);
2089
2096
  if (option) {
2090
- option.componentPostConstruct.call(component, meta, application, field);
2097
+ option.componentPostConstruct.call(component, meta, application, {
2098
+ name: field,
2099
+ kind: KindField
2100
+ });
2091
2101
  }
2092
2102
  }
2093
2103
  }
@@ -2095,7 +2105,10 @@ class IocComponentFactory {
2095
2105
  for (const meta of metaList) {
2096
2106
  const option = getCreateDecoratorOption(meta.constructor);
2097
2107
  if (option) {
2098
- option.componentPostConstruct.call(component, meta, application, method);
2108
+ option.componentPostConstruct.call(component, meta, application, {
2109
+ name: method,
2110
+ kind: KindMethod
2111
+ });
2099
2112
  }
2100
2113
  }
2101
2114
  }
@@ -2148,11 +2161,11 @@ class IocComponentFactory {
2148
2161
  }
2149
2162
  instantiatingStage.add(targetDefinition.cls);
2150
2163
  const constructorArgs = [];
2151
- const constructorParams = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorParam);
2152
- if (constructorParams.length > 0) {
2164
+ const constructorInject = application.metadataRepository.listClassKindMetadata(instantiateDefinition.cls, ConstructorInject);
2165
+ if (constructorInject.length > 0) {
2153
2166
  // 因为元数据不能重复,所以只有一个
2154
- const constructorParamsParams = constructorParams[0].value;
2155
- for (const dependency of constructorParamsParams) {
2167
+ const constructorInjectParams = constructorInject[0].value;
2168
+ for (const dependency of constructorInjectParams) {
2156
2169
  if (dependency === undefined) {
2157
2170
  constructorArgs.push(undefined);
2158
2171
  } else {
@@ -2479,8 +2492,11 @@ new class extends _identity {
2479
2492
  var Bind = _Bind;
2480
2493
 
2481
2494
  var bind = createDecoratorExp(Bind, {
2482
- componentPostConstruct: function (metadata, application, field) {
2483
- this[field] = this[field].bind(this);
2495
+ componentPostConstruct: function (metadata, application, target) {
2496
+ const {
2497
+ name
2498
+ } = target;
2499
+ this[name] = this[name].bind(this);
2484
2500
  }
2485
2501
  });
2486
2502
 
@@ -2841,7 +2857,7 @@ let _Memoized;
2841
2857
  new class extends _identity {
2842
2858
  static [class Memoized extends Metadata {
2843
2859
  static {
2844
- [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method])], [], 0, void 0, Metadata).c;
2860
+ [_Memoized, _initClass$k] = _applyDecs2311(this, [target([Target.Type.Method, Target.Type.Field])], [], 0, void 0, Metadata).c;
2845
2861
  }
2846
2862
  }];
2847
2863
  $$id = "Memoized";
@@ -2895,11 +2911,31 @@ class Subscriber {
2895
2911
  }
2896
2912
  }
2897
2913
 
2914
+ function isArrowFunction(v) {
2915
+ return !v.hasOwnProperty('prototype');
2916
+ }
2898
2917
  var memoized = createDecoratorExp(Memoized, {
2899
- componentPostConstruct: function (metadata, application, field) {
2900
- const fn = this[field];
2901
- const subscriber = new Subscriber(fn.bind(this));
2902
- this[field] = subscriber.memoizedFn;
2918
+ componentPostConstruct: function (metadata, application, target) {
2919
+ const {
2920
+ name,
2921
+ kind
2922
+ } = target;
2923
+ if (kind === KindMethod) {
2924
+ const fn = this[name];
2925
+ const subscriber = new Subscriber(fn.bind(this));
2926
+ this[name] = subscriber.memoizedFn;
2927
+ } else if (kind === KindField) {
2928
+ const func = this[name];
2929
+ const type = typeof func;
2930
+ if (type === 'function') {
2931
+ const bindThisFunc = isArrowFunction(func) ? func : func.bind(this);
2932
+ const subscriber = new Subscriber(bindThisFunc);
2933
+ this[name] = subscriber.memoizedFn;
2934
+ } else {
2935
+ const diagnose = createDiagnose(DiagnoseCode.CO10028, this.constructor.name, name, name, type);
2936
+ console.error(stringifyDiagnose(diagnose));
2937
+ }
2938
+ } else ;
2903
2939
  }
2904
2940
  });
2905
2941
 
@@ -2996,7 +3032,10 @@ function definePublisher(object, field, getter, setter) {
2996
3032
  }
2997
3033
 
2998
3034
  var reactive = createDecoratorExp(Reactive, {
2999
- componentPostConstruct(metadata, application, name) {
3035
+ componentPostConstruct(metadata, application, target) {
3036
+ const {
3037
+ name
3038
+ } = target;
3000
3039
  // TODO: 限制只能在store或view组件内部
3001
3040
  let value = this[name];
3002
3041
  definePublisher(this, name, function getter() {
@@ -3034,8 +3073,11 @@ new class extends _identity {
3034
3073
  var Ref$1 = _Ref;
3035
3074
 
3036
3075
  var ref = createDecoratorExp(Ref$1, {
3037
- componentPostConstruct: function (metadata, application, field) {
3038
- this[field] = {
3076
+ componentPostConstruct: function (metadata, application, target) {
3077
+ const {
3078
+ name
3079
+ } = target;
3080
+ this[name] = {
3039
3081
  current: null
3040
3082
  };
3041
3083
  }
@@ -3060,8 +3102,8 @@ new class extends _identity {
3060
3102
  var Refs = _Refs;
3061
3103
 
3062
3104
  var refs = createDecoratorExp(Refs, {
3063
- componentPostConstruct: function (metadata, application, field) {
3064
- this[field] = {};
3105
+ componentPostConstruct: function (metadata, application, target) {
3106
+ this[target.name] = {};
3065
3107
  }
3066
3108
  });
3067
3109
 
@@ -6297,7 +6339,7 @@ const storeComponentUpdater = {
6297
6339
  // 使用后立刻清空标记
6298
6340
  inst[bindViewInst] = null;
6299
6341
  if (viewInstance === null || viewInstance === undefined) {
6300
- console.error("store只能通过视图组件的属性更新状态。");
6342
+ console.error(stringifyDiagnose(createDiagnose(DiagnoseCode.CO10029, inst.constructor.name, field)));
6301
6343
  return;
6302
6344
  }
6303
6345
  const update = createUpdate(field);
@@ -6317,18 +6359,21 @@ function reactiveStoreField(ctor, viewComponent) {
6317
6359
  // 找到所有的注入
6318
6360
  const Autowired = application.getMetaClassById('Autowired');
6319
6361
  const autowiredFields = application.listFieldByMetadataCls(ctor, Autowired);
6362
+ const Store = application.getMetaClassById('Store');
6320
6363
  autowiredFields.forEach((field) => {
6321
- const storeInst = viewComponent[field];
6322
- Object.defineProperty(viewComponent, field, {
6323
- get() {
6324
- // 每次访问前设置标记
6325
- storeInst[bindViewInst] = viewComponent;
6326
- return storeInst;
6327
- },
6328
- set() {
6329
- console.error('store实例在初始化之后不允许修改');
6330
- }
6331
- });
6364
+ const component = viewComponent[field];
6365
+ if (application.findClassKindMetadataRecursively(component.constructor, Store, 0)) {
6366
+ Object.defineProperty(viewComponent, field, {
6367
+ get() {
6368
+ // 每次访问前设置标记
6369
+ component[bindViewInst] = viewComponent;
6370
+ return component;
6371
+ },
6372
+ set() {
6373
+ console.error('store实例在初始化之后不允许修改');
6374
+ }
6375
+ });
6376
+ }
6332
6377
  });
6333
6378
  }
6334
6379
  /**
@@ -6387,6 +6432,7 @@ function processUpdateQueueForStore(ctor, instance) {
6387
6432
  });
6388
6433
  }
6389
6434
  }
6435
+ // TODO 放在store组件实例化的地方
6390
6436
  function initFiber(storeInstance) {
6391
6437
  if (storeInstance[fiberField]) {
6392
6438
  return;
@@ -7875,7 +7921,7 @@ let _HistoryRouter;
7875
7921
  new class extends _identity {
7876
7922
  static [class HistoryRouter extends Router {
7877
7923
  static {
7878
- [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorParam([Render])], [], 0, void 0, Router).c;
7924
+ [_HistoryRouter, _initClass$5] = _applyDecs2311(this, [router(), constructorInject([Render])], [], 0, void 0, Router).c;
7879
7925
  }
7880
7926
  constructor(render) {
7881
7927
  super();
@@ -8020,4 +8066,4 @@ var WebApplication = _WebApplication;
8020
8066
 
8021
8067
  var webApplication = createDecoratorExp(WebApplication);
8022
8068
 
8023
- 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 };
8069
+ 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.11",
3
+ "version": "0.1.0-beta.13",
4
4
  "description": "由装饰器驱动,快速构建可扩展的 Web 应用。",
5
5
  "main": "dist/index.cjs.js",
6
6
  "module": "dist/index.esm.js",