annil 1.1.0 → 1.1.2
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/CHANGELOG.md +14 -0
- package/dist/api/DefineComponent/collectOptionsForComponent.d.ts +2 -2
- package/dist/api/DefineComponent/collectOptionsForComponent.js +55 -6
- package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -1
- package/dist/api/DefineComponent/index.d.ts +2 -2
- package/dist/api/RootComponent/Computed/ComputedOption.d.ts +2 -2
- package/dist/api/RootComponent/Computed/GetComputedDoc.d.ts +2 -2
- package/dist/api/RootComponent/Computed/test/normal.test.js +5 -12
- package/dist/api/RootComponent/Computed/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/CustomEvents/CustomEventsOption.d.ts +2 -2
- package/dist/api/RootComponent/Data/DataConstraint.d.ts +1 -1
- package/dist/api/RootComponent/Data/DataOption.d.ts +2 -2
- package/dist/api/RootComponent/Data/GetDataDoc.d.ts +1 -4
- package/dist/api/RootComponent/Data/test/GetDataDoc.test.d.ts +3 -2
- package/dist/api/RootComponent/Data/test/GetDataDoc.test.js +5 -5
- package/dist/api/RootComponent/Data/test/GetDataDoc.test.js.map +1 -1
- package/dist/api/RootComponent/Data/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Events/EventsConstraint.d.ts +6 -5
- package/dist/api/RootComponent/Events/EventsOption.d.ts +2 -3
- package/dist/api/RootComponent/Events/test/normal.test.js +1 -1
- package/dist/api/RootComponent/Events/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +5 -4
- package/dist/api/RootComponent/Lifetimes/test/error.test.js.map +1 -1
- package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +6 -7
- package/dist/api/RootComponent/PageLifetimes/test/error.test.js +3 -1
- package/dist/api/RootComponent/PageLifetimes/test/error.test.js.map +1 -1
- package/dist/api/RootComponent/PageLifetimes/test/normal.test.js +3 -1
- package/dist/api/RootComponent/PageLifetimes/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/RootComponentDoc.d.ts +17 -3
- package/dist/api/RootComponent/Store/GeTStoreDoc.d.ts +1 -1
- package/dist/api/RootComponent/Store/StoreOption.d.ts +2 -2
- package/dist/api/RootComponent/Store/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Watch/test/WatchProperties.test.js +0 -2
- package/dist/api/RootComponent/Watch/test/WatchProperties.test.js.map +1 -1
- package/dist/api/RootComponent/index.d.ts +5 -5
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/SubData/SubDataConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubData/test/normal.test.js +0 -15
- package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubEvents/SubEventsOptions.d.ts +2 -2
- package/dist/api/SubComponent/SubEvents/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubEvents/test/normal.test.js +20 -0
- package/dist/api/SubComponent/SubEvents/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +3 -2
- package/dist/api/SubComponent/SubInherit/SubInheritOption.d.ts +3 -0
- package/dist/api/SubComponent/SubInherit/SubInheritOption.js +2 -0
- package/dist/api/SubComponent/SubInherit/SubInheritOption.js.map +1 -0
- package/dist/api/SubComponent/SubInherit/test/error.test.js +1 -1
- package/dist/api/SubComponent/SubInherit/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubInherit/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubMethods/SubMethodsOption.d.ts +3 -2
- package/dist/api/SubComponent/SubMethods/test/error.test.js +6 -0
- package/dist/api/SubComponent/SubMethods/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubMethods/test/normarl.test.js +3 -3
- package/dist/api/SubComponent/SubMethods/test/normarl.test.js.map +1 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/error.test.d.ts +0 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/error.test.js +1 -11
- package/dist/api/SubComponent/SubPageLifetimes/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.d.ts +0 -1
- package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js +1 -25
- package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubStore/SubDataConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubStore/SubStoreOption.d.ts +1 -1
- package/dist/api/SubComponent/SubStore/test/error.test.js +2 -0
- package/dist/api/SubComponent/SubStore/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/SubStore/test/normal.test.js +1 -0
- package/dist/api/SubComponent/SubStore/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubWatch/SubWatchOption.d.ts +2 -1
- package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.d.ts +1 -0
- package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.js +44 -1
- package/dist/api/SubComponent/SubWatch/test/WatchComputed.test.js.map +1 -1
- package/dist/api/SubComponent/SubWatch/test/error.test.js +10 -2
- package/dist/api/SubComponent/SubWatch/test/error.test.js.map +1 -1
- package/dist/api/SubComponent/index.d.ts +3 -4
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/computedUpdater.js +1 -3
- package/dist/behaviors/BComputedAndWatch/computedUpdater.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/initComputed.js +1 -3
- package/dist/behaviors/BComputedAndWatch/initComputed.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/types.d.ts +1 -0
- package/dist/behaviors/BStore.js.map +1 -1
- package/dist/behaviors/BbeforeCreated.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js.map +1 -1
- package/dist/types/OfficialTypeAlias.d.ts +1 -1
- package/dist/types/RemoveInnerData.d.ts +1 -0
- package/dist/types/RemoveInnerData.js +2 -0
- package/dist/types/RemoveInnerData.js.map +1 -0
- package/package.json +4 -2
- package/src/api/DefineComponent/collectOptionsForComponent.ts +99 -16
- package/src/api/DefineComponent/index.ts +2 -2
- package/src/api/RootComponent/Computed/ComputedOption.ts +23 -3
- package/src/api/RootComponent/Computed/GetComputedDoc.ts +1 -3
- package/src/api/RootComponent/Computed/test/normal.test.ts +9 -19
- package/src/api/RootComponent/CustomEvents/CustomEventsOption.ts +26 -22
- package/src/api/RootComponent/CustomEvents/test/error.test.ts +5 -5
- package/src/api/RootComponent/CustomEvents/test/normal.test.ts +1 -1
- package/src/api/RootComponent/Data/DataConstraint.ts +1 -1
- package/src/api/RootComponent/Data/DataOption.ts +6 -4
- package/src/api/RootComponent/Data/GetDataDoc.ts +1 -18
- package/src/api/RootComponent/Data/test/GetDataDoc.test.ts +14 -25
- package/src/api/RootComponent/Data/test/error.test.ts +2 -2
- package/src/api/RootComponent/Data/test/normal.test.ts +5 -8
- package/src/api/RootComponent/Events/EventsConstraint.ts +24 -19
- package/src/api/RootComponent/Events/EventsOption.ts +54 -6
- package/src/api/RootComponent/Events/test/normal.test.ts +16 -16
- package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +1 -1
- package/src/api/RootComponent/IsPage/IsPageOption.ts +1 -1
- package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +11 -8
- package/src/api/RootComponent/Lifetimes/LifetimesOption.ts +26 -0
- package/src/api/RootComponent/Lifetimes/test/error.test.ts +3 -13
- package/src/api/RootComponent/Lifetimes/test/normal.test.ts +1 -1
- package/src/api/RootComponent/Methods/MethodsOption.ts +3 -0
- package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +21 -10
- package/src/api/RootComponent/PageLifetimes/test/error.test.ts +7 -5
- package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +9 -10
- package/src/api/RootComponent/Properties/PropertiesOption.ts +19 -32
- package/src/api/RootComponent/RootComponentDoc.ts +19 -3
- package/src/api/RootComponent/Store/GeTStoreDoc.ts +1 -1
- package/src/api/RootComponent/Store/StoreOption.ts +14 -2
- package/src/api/RootComponent/Store/test/error.test.ts +5 -5
- package/src/api/RootComponent/Store/test/normal.test.ts +1 -0
- package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +1 -12
- package/src/api/RootComponent/index.ts +13 -15
- package/src/api/SubComponent/SubComputed/SubComputedOption.ts +0 -1
- package/src/api/SubComponent/SubData/SubDataConstraint.ts +2 -3
- package/src/api/SubComponent/SubData/SubDataOption.ts +4 -0
- package/src/api/SubComponent/SubData/test/error.test.ts +1 -1
- package/src/api/SubComponent/SubData/test/normal.test.ts +6 -37
- package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +7 -2
- package/src/api/SubComponent/SubEvents/SubEventsOptions.ts +7 -2
- package/src/api/SubComponent/SubEvents/test/error.test.ts +5 -4
- package/src/api/SubComponent/SubEvents/test/normal.test.ts +31 -4
- package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +6 -3
- package/src/api/SubComponent/SubInherit/SubInheritOption.ts +8 -0
- package/src/api/SubComponent/SubInherit/test/error.test.ts +9 -7
- package/src/api/SubComponent/SubInherit/test/normal.test.ts +5 -4
- package/src/api/SubComponent/SubMethods/SubMethodsOption.ts +7 -3
- package/src/api/SubComponent/SubMethods/test/error.test.ts +13 -5
- package/src/api/SubComponent/SubMethods/test/normarl.test.ts +6 -12
- package/src/api/SubComponent/SubPageLifetimes/test/error.test.ts +1 -32
- package/src/api/SubComponent/SubPageLifetimes/test/normal.test.ts +1 -74
- package/src/api/SubComponent/SubStore/SubDataConstraint.ts +2 -2
- package/src/api/SubComponent/SubStore/SubStoreOption.ts +15 -1
- package/src/api/SubComponent/SubStore/test/error.test.ts +4 -0
- package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -0
- package/src/api/SubComponent/SubWatch/SubWatchOption.ts +2 -1
- package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +75 -43
- package/src/api/SubComponent/SubWatch/test/error.test.ts +12 -3
- package/src/api/SubComponent/index.ts +9 -5
- package/src/behaviors/BComputedAndWatch/computedUpdater.ts +1 -0
- package/src/behaviors/BComputedAndWatch/index.ts +2 -2
- package/src/behaviors/BComputedAndWatch/initComputed.ts +1 -0
- package/src/behaviors/BComputedAndWatch/types.ts +1 -0
- package/src/behaviors/BStore.ts +2 -2
- package/src/behaviors/BbeforeCreated.ts +2 -2
- package/src/index.ts +9 -1
- package/src/types/OfficialTypeAlias.ts +7 -11
- package/src/types/RemoveInnerData.ts +5 -0
|
@@ -16,7 +16,7 @@ import type {
|
|
|
16
16
|
import type { EventsConstraint } from "../RootComponent/Events/EventsConstraint";
|
|
17
17
|
import type { PageInstance } from "../RootComponent/Instance/RootComponentInstance";
|
|
18
18
|
import type { SubComponentTrueOptions } from "../SubComponent";
|
|
19
|
-
import type {
|
|
19
|
+
import type { FinalOptionsOfComponent, FuncOptions } from ".";
|
|
20
20
|
/**
|
|
21
21
|
* 针对通过 navigateTo传过来的数据解析
|
|
22
22
|
* @param option - option中的url是拼接了encodeURIComponent转码的data对象的,key为INNERMARKER.url
|
|
@@ -49,7 +49,7 @@ function onLoadReceivedDataHandle(
|
|
|
49
49
|
*/
|
|
50
50
|
/* istanbul ignore next */
|
|
51
51
|
function onLoadHijack(
|
|
52
|
-
options:
|
|
52
|
+
options: FinalOptionsOfComponent,
|
|
53
53
|
before: Func[],
|
|
54
54
|
after: Func[] = [],
|
|
55
55
|
) {
|
|
@@ -70,18 +70,47 @@ function onLoadHijack(
|
|
|
70
70
|
});
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* attached生命周期劫持函数
|
|
75
|
+
*/
|
|
76
|
+
/* istanbul ignore next */
|
|
77
|
+
function attachedHijack(
|
|
78
|
+
options: FinalOptionsOfComponent,
|
|
79
|
+
before: Func[],
|
|
80
|
+
after: Func[] = [],
|
|
81
|
+
) {
|
|
82
|
+
/* istanbul ignore next */
|
|
83
|
+
options.lifetimes ||= {};
|
|
84
|
+
|
|
85
|
+
const originalAttached: Func | undefined = options.lifetimes.attached;
|
|
86
|
+
|
|
87
|
+
options.lifetimes.attached = function() {
|
|
88
|
+
before.forEach((func) => {
|
|
89
|
+
func.call(this, options);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
originalAttached?.call(this);
|
|
93
|
+
|
|
94
|
+
/* istanbul ignore next */
|
|
95
|
+
after.forEach((func) => {
|
|
96
|
+
func.call(this, options);
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
}
|
|
73
100
|
/**
|
|
74
101
|
* 内部保护字段 即不允许配置的字段名(所有方法下)
|
|
75
102
|
*/
|
|
76
|
-
const INNERFIELDS = ["disposer"];
|
|
103
|
+
// const INNERFIELDS = ["disposer"];
|
|
77
104
|
|
|
78
105
|
/**
|
|
79
106
|
* 报错的形式避免输入字段和内部字段冲突
|
|
107
|
+
* 保护config下不被配置keys包含的内部预定字段
|
|
80
108
|
*/
|
|
81
109
|
/* istanbul ignore next */
|
|
82
|
-
function InternalFieldProtection(
|
|
83
|
-
|
|
84
|
-
|
|
110
|
+
function InternalFieldProtection(config: object | undefined, keys: string[]) {
|
|
111
|
+
if (!config) return;
|
|
112
|
+
const methodsConfigKeys = Object.keys(config);
|
|
113
|
+
for (const key of keys) {
|
|
85
114
|
if (methodsConfigKeys.includes(key)) {
|
|
86
115
|
throw Error(`${key}已被内部字段占用`);
|
|
87
116
|
}
|
|
@@ -99,7 +128,7 @@ function _funcConfigHandle(methodsConfig: object, configList: Record<string, Fun
|
|
|
99
128
|
}
|
|
100
129
|
|
|
101
130
|
function funcConfigHandle(
|
|
102
|
-
finalOptionsForComponent:
|
|
131
|
+
finalOptionsForComponent: FinalOptionsOfComponent,
|
|
103
132
|
isPage: boolean | undefined,
|
|
104
133
|
funcOptions: FuncOptions,
|
|
105
134
|
) {
|
|
@@ -138,7 +167,7 @@ function funcFieldsCollect(
|
|
|
138
167
|
|
|
139
168
|
// 其他字段加入到componentOptions对应字段配置中
|
|
140
169
|
function otherFieldsHandle(
|
|
141
|
-
finalOptions:
|
|
170
|
+
finalOptions: FinalOptionsOfComponent,
|
|
142
171
|
rootComponentOptions: RootComponentTrueOptions,
|
|
143
172
|
) {
|
|
144
173
|
for (const key in rootComponentOptions) {
|
|
@@ -155,14 +184,14 @@ function otherFieldsHandle(
|
|
|
155
184
|
/**
|
|
156
185
|
* 把events字段配置变成函数放入到componentOptions.methods中
|
|
157
186
|
*/
|
|
158
|
-
function eventsHandle(componentOptions:
|
|
187
|
+
function eventsHandle(componentOptions: FinalOptionsOfComponent, eventsConfig: EventsConstraint) {
|
|
159
188
|
/* istanbul ignore next */
|
|
160
189
|
componentOptions.methods ||= {};
|
|
161
190
|
|
|
162
191
|
Object.assign(componentOptions.methods, eventsConfig);
|
|
163
192
|
}
|
|
164
193
|
function subComponentsHandle(
|
|
165
|
-
componentOptions:
|
|
194
|
+
componentOptions: FinalOptionsOfComponent,
|
|
166
195
|
subComponents: SubComponentTrueOptions[],
|
|
167
196
|
funcOptions: FuncOptions,
|
|
168
197
|
) {
|
|
@@ -186,7 +215,7 @@ function IsFullCustomEvents(
|
|
|
186
215
|
* 把customEvents字段配置变成函数放入到componentOptions.methods中
|
|
187
216
|
*/
|
|
188
217
|
function customEventsHandle(
|
|
189
|
-
componentOptions:
|
|
218
|
+
componentOptions: FinalOptionsOfComponent,
|
|
190
219
|
customEventsConfig: CustomEventConstraint,
|
|
191
220
|
) {
|
|
192
221
|
/* istanbul ignore next */
|
|
@@ -206,7 +235,49 @@ function customEventsHandle(
|
|
|
206
235
|
}
|
|
207
236
|
}
|
|
208
237
|
}
|
|
238
|
+
/**
|
|
239
|
+
* 触发各个组件的页面load事件
|
|
240
|
+
*/
|
|
241
|
+
/* istanbul ignore next */
|
|
242
|
+
function triggerCompLoad(this: Instance, props: object) {
|
|
243
|
+
if (!this.__compLoadList__) return;
|
|
244
|
+
this.__compLoadList__.forEach((loadFunc) => {
|
|
245
|
+
loadFunc(props);
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
/* istanbul ignore next */
|
|
249
|
+
function getPageInstance(pageId: string): Instance {
|
|
250
|
+
const pagestack = getCurrentPages() as unknown as Instance[];
|
|
251
|
+
let pageInstance: Instance;
|
|
252
|
+
pagestack.some((instance) => {
|
|
253
|
+
if (instance.getPageId() === pageId) {
|
|
254
|
+
pageInstance = instance;
|
|
255
|
+
|
|
256
|
+
return true;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
return false;
|
|
260
|
+
});
|
|
261
|
+
|
|
262
|
+
// @ts-ignore pagestack中一定赋值了
|
|
263
|
+
return pageInstance;
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* 收集组件pageLifetimes下的load周期函数到页面实例的__loadFunList__
|
|
267
|
+
*/
|
|
268
|
+
/* istanbul ignore next */
|
|
269
|
+
function collectLoadLifetimesOfComponent(this: Instance, finalOptionsForComponent: FinalOptionsOfComponent) {
|
|
270
|
+
const loadFunc = finalOptionsForComponent.pageLifetimes?.load;
|
|
271
|
+
|
|
272
|
+
console.log(loadFunc, finalOptionsForComponent);
|
|
209
273
|
|
|
274
|
+
if (!loadFunc) return;
|
|
275
|
+
|
|
276
|
+
const pageInstance = getPageInstance(this.getPageId());
|
|
277
|
+
const __compLoadList__: Function[] = (pageInstance.__compLoadList__ ||= []);
|
|
278
|
+
|
|
279
|
+
__compLoadList__.push(loadFunc.bind(this));
|
|
280
|
+
}
|
|
210
281
|
/**
|
|
211
282
|
* 收集 rootComponentOptions 配置到 finalOptions 和 funcOptions 中
|
|
212
283
|
* @param finalOptions - 收集配置对象
|
|
@@ -214,10 +285,18 @@ function customEventsHandle(
|
|
|
214
285
|
* @param rootComponentOptions - 被收集的源配置对象
|
|
215
286
|
*/
|
|
216
287
|
function collectRootComponentOption(
|
|
217
|
-
finalOptions:
|
|
288
|
+
finalOptions: FinalOptionsOfComponent,
|
|
218
289
|
funcOptions: FuncOptions,
|
|
219
290
|
rootComponentOptions: RootComponentTrueOptions,
|
|
220
291
|
) {
|
|
292
|
+
console.log("-------------------------");
|
|
293
|
+
|
|
294
|
+
InternalFieldProtection(rootComponentOptions.customEvents, ["load"]);
|
|
295
|
+
|
|
296
|
+
InternalFieldProtection(rootComponentOptions.methods, ["load"]);
|
|
297
|
+
|
|
298
|
+
InternalFieldProtection(rootComponentOptions.events, ["load"]);
|
|
299
|
+
|
|
221
300
|
rootComponentOptions.customEvents && customEventsHandle(finalOptions, rootComponentOptions.customEvents);
|
|
222
301
|
|
|
223
302
|
delete rootComponentOptions.customEvents;
|
|
@@ -239,8 +318,8 @@ function collectRootComponentOption(
|
|
|
239
318
|
export function collectOptionsForComponent(
|
|
240
319
|
rootComponentOption: RootComponentTrueOptions | undefined,
|
|
241
320
|
subComponentsList: SubComponentTrueOptions[] | undefined,
|
|
242
|
-
):
|
|
243
|
-
const finalOptionsForComponent:
|
|
321
|
+
): FinalOptionsOfComponent {
|
|
322
|
+
const finalOptionsForComponent: FinalOptionsOfComponent = {
|
|
244
323
|
// default options
|
|
245
324
|
options: {
|
|
246
325
|
// addGlobalClass: true,
|
|
@@ -273,12 +352,16 @@ export function collectOptionsForComponent(
|
|
|
273
352
|
funcConfigHandle(finalOptionsForComponent, rootComponentOption?.isPage, funcOptions);
|
|
274
353
|
}
|
|
275
354
|
|
|
276
|
-
finalOptionsForComponent.methods && InternalFieldProtection(finalOptionsForComponent.methods);
|
|
355
|
+
finalOptionsForComponent.methods && InternalFieldProtection(finalOptionsForComponent.methods, ["disposer"]);
|
|
277
356
|
|
|
278
357
|
// BBeforeCreate在最后面
|
|
279
358
|
finalOptionsForComponent.behaviors!.push(BBeforeCreate);
|
|
280
359
|
|
|
281
|
-
|
|
360
|
+
console.log(finalOptionsForComponent, 999, funcOptions);
|
|
361
|
+
|
|
362
|
+
attachedHijack(finalOptionsForComponent, [collectLoadLifetimesOfComponent], []);
|
|
363
|
+
|
|
364
|
+
onLoadHijack(finalOptionsForComponent, [onLoadReceivedDataHandle, initComputed], [triggerCompLoad]);
|
|
282
365
|
|
|
283
366
|
// 框架无法测试页面
|
|
284
367
|
/* istanbul ignore next */
|
|
@@ -54,7 +54,7 @@ export type FuncOptions = Record<"pageLifetimes" | "lifetimes" | "watch", Record
|
|
|
54
54
|
/**
|
|
55
55
|
* 最终传入原生Component的配置项
|
|
56
56
|
*/
|
|
57
|
-
export type
|
|
57
|
+
export type FinalOptionsOfComponent = {
|
|
58
58
|
isPage?: boolean;
|
|
59
59
|
options?: WMComponent.Options;
|
|
60
60
|
properties?: Record<string, any>;
|
|
@@ -66,7 +66,7 @@ export type FinalOptionsForComponent = {
|
|
|
66
66
|
methods?: Record<string, Func> & { __storeConfig__?: Func };
|
|
67
67
|
watch?: Record<string, Func>;
|
|
68
68
|
lifetimes?: LifetimesConstraint;
|
|
69
|
-
pageLifetimes?: Partial<WMCompPageLifetimes & { load:
|
|
69
|
+
pageLifetimes?: Partial<WMCompPageLifetimes & { load: (prop: unknown) => void } & WMPageLifetimes>;
|
|
70
70
|
};
|
|
71
71
|
|
|
72
72
|
export const DefineComponent: DefineComponentConstructor = function(options): any {
|
|
@@ -2,11 +2,31 @@ import type { DuplicateFieldValidator } from "hry-types/src/Generic/DuplicateFie
|
|
|
2
2
|
|
|
3
3
|
import type { ComputedConstraint } from "./ComputedConstraint";
|
|
4
4
|
|
|
5
|
-
export type ComputedOption<TComputed extends ComputedConstraint,
|
|
5
|
+
export type ComputedOption<TComputed extends ComputedConstraint, CompareKeys extends PropertyKey> = {
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* computed字段, [类型约束ComputedConstraint](ComputedConstraint.ts)
|
|
8
|
+
* @remarks
|
|
9
|
+
*
|
|
10
|
+
* 函数体内,可通过this.data获取实例其他数据(依赖),setData发生时,若数据(依赖)发生变化则重新运行函数体并setData。
|
|
11
|
+
*
|
|
12
|
+
* 带重复字段检测(与properties、data、store字段比较)
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
*
|
|
16
|
+
* ```ts
|
|
17
|
+
* {
|
|
18
|
+
* data:{
|
|
19
|
+
* count:1
|
|
20
|
+
* },
|
|
21
|
+
* computed:{
|
|
22
|
+
* return this.data.count + 1
|
|
23
|
+
* }
|
|
24
|
+
|
|
25
|
+
* }
|
|
26
|
+
*
|
|
27
|
+
* ```
|
|
8
28
|
*/
|
|
9
29
|
computed?:
|
|
10
30
|
& TComputed
|
|
11
|
-
& DuplicateFieldValidator<TComputed,
|
|
31
|
+
& DuplicateFieldValidator<TComputed, CompareKeys>;
|
|
12
32
|
};
|
|
@@ -5,6 +5,4 @@ import type { ComputedConstraint } from "./ComputedConstraint";
|
|
|
5
5
|
* @param T - ComputedConstraint
|
|
6
6
|
* @returns object
|
|
7
7
|
*/
|
|
8
|
-
export type GetComputedDoc<TComputed extends ComputedConstraint> = TComputed
|
|
9
|
-
? { [k in keyof TComputed]: ReturnType<TComputed[k]> }
|
|
10
|
-
: never;
|
|
8
|
+
export type GetComputedDoc<TComputed extends ComputedConstraint> = { [k in keyof TComputed]: ReturnType<TComputed[k]> };
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
|
-
import type { DetailedType } from "../../../../types/DetailedType";
|
|
4
3
|
import { RootComponent } from "../..";
|
|
5
4
|
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
6
5
|
|
|
7
|
-
/**
|
|
8
|
-
* computed字段约束为 [ComputedConstraint](../ComputedConstraint.ts)
|
|
9
|
-
*/
|
|
10
6
|
const RootDoc = RootComponent()({
|
|
11
7
|
properties: {
|
|
12
8
|
firstName: String,
|
|
@@ -14,10 +10,13 @@ const RootDoc = RootComponent()({
|
|
|
14
10
|
data: {
|
|
15
11
|
lastName: "lastName",
|
|
16
12
|
},
|
|
13
|
+
store: {
|
|
14
|
+
prefix: () => "hry-", // 模拟而已
|
|
15
|
+
},
|
|
17
16
|
computed: {
|
|
18
17
|
fullName() {
|
|
19
|
-
// 1 计算属性字段可以通过this.data 引用properties、data
|
|
20
|
-
return this.data.firstName + this.data.lastName;
|
|
18
|
+
// 1 计算属性字段可以通过this.data 引用properties、data、store字段
|
|
19
|
+
return this.data.prefix + this.data.firstName + this.data.lastName;
|
|
21
20
|
},
|
|
22
21
|
user() {
|
|
23
22
|
return {} as Mock_User;
|
|
@@ -35,12 +34,16 @@ const RootDoc = RootComponent()({
|
|
|
35
34
|
lastName: string;
|
|
36
35
|
fullName: string;
|
|
37
36
|
user: Mock_User;
|
|
37
|
+
prefix: string;
|
|
38
38
|
id_fullName: string;
|
|
39
39
|
readOnly: "str";
|
|
40
40
|
}>,
|
|
41
41
|
Test.Pass
|
|
42
42
|
>;
|
|
43
43
|
|
|
44
|
+
// @ts-expect-error 深度只读 不可赋值
|
|
45
|
+
this.data.user.id = "xxx";
|
|
46
|
+
|
|
44
47
|
return "str";
|
|
45
48
|
},
|
|
46
49
|
},
|
|
@@ -84,16 +87,3 @@ const EmptyComputedFieldDoc = RootComponent()({
|
|
|
84
87
|
});
|
|
85
88
|
|
|
86
89
|
Checking<typeof EmptyComputedFieldDoc, { methods: { M1: () => void } }, Test.Pass>;
|
|
87
|
-
|
|
88
|
-
RootComponent()({
|
|
89
|
-
isPage: true,
|
|
90
|
-
properties: {
|
|
91
|
-
obj: Object as DetailedType<{ name: string; age: number }>,
|
|
92
|
-
},
|
|
93
|
-
computed: {
|
|
94
|
-
age() {
|
|
95
|
-
// 页面实例对象不添加Null,因为计算属性初始化在onLoad之后(即properties已传入时,且不会传入Null)
|
|
96
|
-
return this.data.obj.age;
|
|
97
|
-
},
|
|
98
|
-
},
|
|
99
|
-
});
|
|
@@ -1,37 +1,41 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
2
|
import type { CustomEventConstraint } from "./CustomEventConstraint";
|
|
3
3
|
|
|
4
|
-
/**
|
|
5
|
-
* customEvents字段泛型输入
|
|
6
|
-
*/
|
|
7
4
|
export type CustomEventsOption<
|
|
8
5
|
TCustomEvents extends CustomEventConstraint,
|
|
9
|
-
|
|
6
|
+
EventsKeys extends PropertyKey,
|
|
10
7
|
> = {
|
|
11
8
|
/**
|
|
12
|
-
*
|
|
13
|
-
* @remarks
|
|
9
|
+
* customEvents 定义组件的自定义事件 [类型约束](CustomEventConstraint.ts)
|
|
10
|
+
* @remarks 通过this.A(123)调用。与events字段重复检测
|
|
14
11
|
* @example
|
|
15
12
|
* ```ts
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
13
|
+
* {
|
|
14
|
+
* customEvents: {
|
|
15
|
+
* A: Number, // number
|
|
16
|
+
* B: [String as DetailedType<"male" | "femal">, Number], // "male" | "femal" | number
|
|
17
|
+
* C: {
|
|
18
|
+
* detail: String,
|
|
19
|
+
* options: {
|
|
20
|
+
* bubbles: true,
|
|
21
|
+
* composed: true,
|
|
22
|
+
* capturePhase: true,
|
|
23
|
+
* },
|
|
24
|
+
* },
|
|
25
|
+
* },
|
|
26
|
+
* methods: {
|
|
27
|
+
* M1() {
|
|
28
|
+
* // 调用自定义事件
|
|
29
|
+
* this.A(123);
|
|
30
|
+
* this.B("femal");
|
|
31
|
+
* this.C("string");
|
|
32
|
+
* },
|
|
33
|
+
* },
|
|
34
|
+
* },
|
|
31
35
|
* ```
|
|
32
36
|
*/
|
|
33
37
|
customEvents?:
|
|
34
38
|
& TCustomEvents
|
|
35
39
|
& V.IllegalFieldValidator<TCustomEvents, "bubbles" | "composed" | "capturePhase", 1, "options">
|
|
36
|
-
& V.DuplicateFieldValidator<TCustomEvents,
|
|
40
|
+
& V.DuplicateFieldValidator<TCustomEvents, EventsKeys, "与events字段重复">;
|
|
37
41
|
};
|
|
@@ -5,26 +5,26 @@ import { RootComponent } from "../..";
|
|
|
5
5
|
*/
|
|
6
6
|
RootComponent()({
|
|
7
7
|
customEvents: {
|
|
8
|
-
// @ts-expect-error options 没有options字段时无需写对象形式,应简写`error1:Boolean`。
|
|
8
|
+
// @ts-expect-error options 1.1 没有options字段时无需写对象形式,应简写`error1:Boolean`。
|
|
9
9
|
error1: {
|
|
10
10
|
detail: Boolean,
|
|
11
11
|
},
|
|
12
|
-
// @ts-expect-error options 不可以为空对象 无意义
|
|
12
|
+
// @ts-expect-error options 1.2 不可以为空对象 无意义
|
|
13
13
|
error2: {
|
|
14
14
|
detail: Boolean,
|
|
15
15
|
options: {},
|
|
16
16
|
},
|
|
17
|
-
// @ts-expect-error false字段不要写 默认就为false
|
|
17
|
+
// @ts-expect-error 1.3 false字段不要写 默认就为false
|
|
18
18
|
error3: {
|
|
19
19
|
detail: Boolean,
|
|
20
20
|
options: { bubbles: false },
|
|
21
21
|
},
|
|
22
|
-
// @ts-expect-error false 字段不要写 默认false
|
|
22
|
+
// @ts-expect-error 1.4 false 字段不要写 默认false
|
|
23
23
|
error4: {
|
|
24
24
|
detail: Boolean,
|
|
25
25
|
options: { capturePhase: false },
|
|
26
26
|
},
|
|
27
|
-
// @ts-expect-error composed字段不可以单独开启,必须存在 bubbles或capturePhase字段为true时
|
|
27
|
+
// @ts-expect-error 1.5 composed字段不可以单独开启,必须存在 bubbles或capturePhase字段为true时
|
|
28
28
|
error5: {
|
|
29
29
|
detail: Boolean,
|
|
30
30
|
options: { composed: true },
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export type DataConstraint = Record<string,
|
|
1
|
+
export type DataConstraint = Record<string, unknown>;
|
|
@@ -1,19 +1,21 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
2
|
|
|
3
|
-
export type DataOption<TData extends object,
|
|
3
|
+
export type DataOption<TData extends object, PropertiesKeys extends PropertyKey> = {
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* 定义实例基本数据,默认下划线(`_`)开头的为内部数据,不会被渲染
|
|
6
|
+
* @remarks 与properties字段重复校验
|
|
6
7
|
* @example
|
|
7
8
|
* ```ts
|
|
8
9
|
* {
|
|
9
10
|
* //...
|
|
10
11
|
* data:{
|
|
11
|
-
*
|
|
12
|
+
* num:123,
|
|
13
|
+
* _str:'string' //不会被渲染的内部数据
|
|
12
14
|
* }
|
|
13
15
|
* }
|
|
14
16
|
* ```
|
|
15
17
|
*/
|
|
16
18
|
data?:
|
|
17
19
|
& TData
|
|
18
|
-
& V.DuplicateFieldValidator<TData,
|
|
20
|
+
& V.DuplicateFieldValidator<TData, PropertiesKeys, "与properties字段重复">;
|
|
19
21
|
};
|
|
@@ -1,25 +1,8 @@
|
|
|
1
|
-
import type { O } from "hry-types";
|
|
2
|
-
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
3
|
-
import type { Func } from "hry-types/src/Misc/Func";
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* 获取data字段文档类型
|
|
7
3
|
* @param TData - `DataConstraint`
|
|
8
|
-
* @param Type - "去掉函数字段" | "返回函数字段" | "函数值类型变为函数返回类型"
|
|
9
4
|
* @returns object
|
|
10
5
|
*/
|
|
11
6
|
export type GetDataDoc<
|
|
12
7
|
TData extends object,
|
|
13
|
-
|
|
14
|
-
> = IfExtends<
|
|
15
|
-
Type,
|
|
16
|
-
"函数值类型变为函数返回类型",
|
|
17
|
-
O.ReturnTypeInObject<TData>,
|
|
18
|
-
IfExtends<
|
|
19
|
-
Type,
|
|
20
|
-
"去掉函数字段",
|
|
21
|
-
O.Filter<TData, Func>,
|
|
22
|
-
// "返回函数字段"
|
|
23
|
-
O.Select<TData, Func>
|
|
24
|
-
>
|
|
25
|
-
>;
|
|
8
|
+
> = TData;
|
|
@@ -1,43 +1,32 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
|
|
3
|
-
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
4
3
|
import type { GetDataDoc } from "../GetDataDoc";
|
|
5
4
|
|
|
6
5
|
export const mock_data = {
|
|
7
|
-
|
|
6
|
+
func: {
|
|
7
|
+
foo(num: number) {
|
|
8
|
+
return num + 1;
|
|
9
|
+
},
|
|
10
|
+
},
|
|
8
11
|
num: 2,
|
|
9
12
|
str: "str",
|
|
10
13
|
};
|
|
11
14
|
|
|
12
|
-
type Test1 = GetDataDoc<typeof mock_data
|
|
15
|
+
type Test1 = GetDataDoc<typeof mock_data>;
|
|
13
16
|
|
|
14
|
-
type Test1Expected = {
|
|
17
|
+
type Test1Expected = {
|
|
18
|
+
func: {
|
|
19
|
+
foo(num: number): number;
|
|
20
|
+
};
|
|
21
|
+
num: number;
|
|
22
|
+
str: string;
|
|
23
|
+
};
|
|
15
24
|
|
|
16
25
|
Checking<Test1, Test1Expected, Test.Pass>;
|
|
17
26
|
|
|
18
|
-
type Test2 = GetDataDoc<typeof mock_data, "去掉函数字段">;
|
|
19
|
-
|
|
20
|
-
type Test2Expected = { num: number; str: string };
|
|
21
|
-
|
|
22
|
-
Checking<Test2, Test2Expected, Test.Pass>;
|
|
23
|
-
|
|
24
|
-
type Test3 = GetDataDoc<typeof mock_data, "返回函数字段">;
|
|
25
|
-
|
|
26
|
-
type Test3Expected = { reactiveUser: () => Mock_User };
|
|
27
|
-
|
|
28
|
-
Checking<Test3, Test3Expected, Test.Pass>;
|
|
29
|
-
|
|
30
27
|
// 测试空对象
|
|
31
|
-
type Test4 = GetDataDoc<{}
|
|
28
|
+
type Test4 = GetDataDoc<{}>;
|
|
32
29
|
|
|
33
30
|
type Test4Expected = {};
|
|
34
31
|
|
|
35
32
|
Checking<Test4, Test4Expected, Test.Pass>;
|
|
36
|
-
|
|
37
|
-
type Test5 = GetDataDoc<{}, "去掉函数字段">;
|
|
38
|
-
|
|
39
|
-
Checking<Test5, Test4Expected, Test.Pass>;
|
|
40
|
-
|
|
41
|
-
type Test6 = GetDataDoc<{}, "返回函数字段">;
|
|
42
|
-
|
|
43
|
-
Checking<Test6, Test4Expected, Test.Pass>;
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { RootComponent } from "../..";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* 字段重复
|
|
5
5
|
*/
|
|
6
6
|
RootComponent()({
|
|
7
7
|
properties: {
|
|
8
8
|
aaa: String,
|
|
9
9
|
},
|
|
10
10
|
data: {
|
|
11
|
-
// @ts-expect-error ⚠️与properties字段重复⚠️
|
|
11
|
+
// @ts-expect-error 1 ⚠️与properties字段重复⚠️
|
|
12
12
|
aaa: 123,
|
|
13
13
|
},
|
|
14
14
|
});
|
|
@@ -3,21 +3,19 @@ import { Checking, type Test } from "hry-types";
|
|
|
3
3
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
4
4
|
import { RootComponent } from "../..";
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
6
|
+
type Gender = "male" | "female";
|
|
7
|
+
|
|
9
8
|
const RootDoc = RootComponent()({
|
|
10
9
|
data: {
|
|
11
|
-
gender: <
|
|
10
|
+
gender: <Gender> "male", // 联合字面量
|
|
12
11
|
num: 123,
|
|
13
12
|
_innernalFields: 123, // 内部字段无法在wxml中使用
|
|
14
13
|
},
|
|
15
14
|
methods: {
|
|
16
15
|
foo() {
|
|
17
|
-
// 1. data配置类型为函数时,this.data中变为函数返回类型
|
|
18
16
|
Checking<
|
|
19
17
|
typeof this.data,
|
|
20
|
-
ReadonlyDeep<{ gender:
|
|
18
|
+
ReadonlyDeep<{ gender: Gender; num: number; _innernalFields: number }>,
|
|
21
19
|
Test.Pass
|
|
22
20
|
>;
|
|
23
21
|
},
|
|
@@ -25,12 +23,11 @@ const RootDoc = RootComponent()({
|
|
|
25
23
|
});
|
|
26
24
|
|
|
27
25
|
type RootDocExpected = {
|
|
28
|
-
gender:
|
|
26
|
+
gender: Gender;
|
|
29
27
|
num: number;
|
|
30
28
|
_innernalFields: number;
|
|
31
29
|
};
|
|
32
30
|
|
|
33
|
-
// 2. data配置类型为函数时,dataDoc中变为函数返回类型
|
|
34
31
|
Checking<typeof RootDoc["data"], RootDocExpected, Test.Pass>;
|
|
35
32
|
|
|
36
33
|
// data为空对象时
|