@cocojs/mvc 0.1.0-beta.10 → 0.1.0-beta.12
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 +85 -32
- package/dist/index.d.ts +15 -3
- package/dist/index.esm.js +85 -32
- package/package.json +1 -1
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 {
|
|
@@ -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,
|
|
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
|
-
|
|
940
|
+
const {
|
|
941
|
+
name
|
|
942
|
+
} = target;
|
|
943
|
+
this[name] = application.propertiesConfig.getValue(path);
|
|
937
944
|
}
|
|
938
945
|
});
|
|
939
946
|
|
|
@@ -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,
|
|
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,
|
|
2110
|
+
option.componentPostConstruct.call(component, meta, application, {
|
|
2111
|
+
name: method,
|
|
2112
|
+
kind: KindMethod
|
|
2113
|
+
});
|
|
2101
2114
|
}
|
|
2102
2115
|
}
|
|
2103
2116
|
}
|
|
@@ -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,
|
|
2485
|
-
|
|
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,
|
|
2902
|
-
const
|
|
2903
|
-
|
|
2904
|
-
|
|
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,
|
|
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,
|
|
3040
|
-
|
|
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,
|
|
3066
|
-
this[
|
|
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(
|
|
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
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
6330
|
-
|
|
6331
|
-
|
|
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
|
/**
|
|
@@ -6354,12 +6399,19 @@ function getAutowiredStores(ctor, instance) {
|
|
|
6354
6399
|
});
|
|
6355
6400
|
return uniqueStores;
|
|
6356
6401
|
}
|
|
6357
|
-
function createFiber() {
|
|
6402
|
+
function createFiber(storeInstance) {
|
|
6403
|
+
const ctor = storeInstance.constructor;
|
|
6404
|
+
const { application } = getCommonApi();
|
|
6405
|
+
const Autowired = application.getMetaClassById('Autowired');
|
|
6406
|
+
const autowiredFields = application.listFieldByMetadataCls(ctor, Autowired);
|
|
6358
6407
|
return {
|
|
6359
6408
|
alternate: null,
|
|
6360
6409
|
stateNode: null,
|
|
6361
6410
|
updateQueue: null,
|
|
6362
|
-
memoizedState:
|
|
6411
|
+
memoizedState: autowiredFields.reduce((prev, field) => {
|
|
6412
|
+
prev[field] = storeInstance[field];
|
|
6413
|
+
return prev;
|
|
6414
|
+
}, {}),
|
|
6363
6415
|
};
|
|
6364
6416
|
}
|
|
6365
6417
|
/**
|
|
@@ -6382,11 +6434,12 @@ function processUpdateQueueForStore(ctor, instance) {
|
|
|
6382
6434
|
});
|
|
6383
6435
|
}
|
|
6384
6436
|
}
|
|
6437
|
+
// TODO 放在store组件实例化的地方
|
|
6385
6438
|
function initFiber(storeInstance) {
|
|
6386
6439
|
if (storeInstance[fiberField]) {
|
|
6387
6440
|
return;
|
|
6388
6441
|
}
|
|
6389
|
-
storeInstance[fiberField] = createFiber();
|
|
6442
|
+
storeInstance[fiberField] = createFiber(storeInstance);
|
|
6390
6443
|
storeInstance[updaterField] = storeComponentUpdater;
|
|
6391
6444
|
initializeUpdateQueue(storeInstance[fiberField]);
|
|
6392
6445
|
}
|
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
|
|
220
|
+
* @param target - 被装饰字段或方法
|
|
221
221
|
*/
|
|
222
|
-
declare type ComponentFieldPostConstructFn = (metadata: Metadata, application: Application,
|
|
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,
|
|
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
|
|
|
@@ -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 {
|
|
@@ -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,
|
|
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
|
-
|
|
938
|
+
const {
|
|
939
|
+
name
|
|
940
|
+
} = target;
|
|
941
|
+
this[name] = application.propertiesConfig.getValue(path);
|
|
935
942
|
}
|
|
936
943
|
});
|
|
937
944
|
|
|
@@ -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,
|
|
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,
|
|
2108
|
+
option.componentPostConstruct.call(component, meta, application, {
|
|
2109
|
+
name: method,
|
|
2110
|
+
kind: KindMethod
|
|
2111
|
+
});
|
|
2099
2112
|
}
|
|
2100
2113
|
}
|
|
2101
2114
|
}
|
|
@@ -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,
|
|
2483
|
-
|
|
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,
|
|
2900
|
-
const
|
|
2901
|
-
|
|
2902
|
-
|
|
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,
|
|
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,
|
|
3038
|
-
|
|
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,
|
|
3064
|
-
this[
|
|
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(
|
|
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
|
|
6322
|
-
|
|
6323
|
-
|
|
6324
|
-
|
|
6325
|
-
|
|
6326
|
-
|
|
6327
|
-
|
|
6328
|
-
|
|
6329
|
-
|
|
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
|
/**
|
|
@@ -6352,12 +6397,19 @@ function getAutowiredStores(ctor, instance) {
|
|
|
6352
6397
|
});
|
|
6353
6398
|
return uniqueStores;
|
|
6354
6399
|
}
|
|
6355
|
-
function createFiber() {
|
|
6400
|
+
function createFiber(storeInstance) {
|
|
6401
|
+
const ctor = storeInstance.constructor;
|
|
6402
|
+
const { application } = getCommonApi();
|
|
6403
|
+
const Autowired = application.getMetaClassById('Autowired');
|
|
6404
|
+
const autowiredFields = application.listFieldByMetadataCls(ctor, Autowired);
|
|
6356
6405
|
return {
|
|
6357
6406
|
alternate: null,
|
|
6358
6407
|
stateNode: null,
|
|
6359
6408
|
updateQueue: null,
|
|
6360
|
-
memoizedState:
|
|
6409
|
+
memoizedState: autowiredFields.reduce((prev, field) => {
|
|
6410
|
+
prev[field] = storeInstance[field];
|
|
6411
|
+
return prev;
|
|
6412
|
+
}, {}),
|
|
6361
6413
|
};
|
|
6362
6414
|
}
|
|
6363
6415
|
/**
|
|
@@ -6380,11 +6432,12 @@ function processUpdateQueueForStore(ctor, instance) {
|
|
|
6380
6432
|
});
|
|
6381
6433
|
}
|
|
6382
6434
|
}
|
|
6435
|
+
// TODO 放在store组件实例化的地方
|
|
6383
6436
|
function initFiber(storeInstance) {
|
|
6384
6437
|
if (storeInstance[fiberField]) {
|
|
6385
6438
|
return;
|
|
6386
6439
|
}
|
|
6387
|
-
storeInstance[fiberField] = createFiber();
|
|
6440
|
+
storeInstance[fiberField] = createFiber(storeInstance);
|
|
6388
6441
|
storeInstance[updaterField] = storeComponentUpdater;
|
|
6389
6442
|
initializeUpdateQueue(storeInstance[fiberField]);
|
|
6390
6443
|
}
|