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
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
// import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
+
import type { IfExtends } from "hry-types/src/Any/_api";
|
|
1
3
|
import type { Select } from "hry-types/src/Object/_api";
|
|
2
4
|
import type { Detail, WMBaseEvent } from "../../../types/OfficialTypeAlias";
|
|
3
5
|
import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
|
|
@@ -16,9 +18,9 @@ type FilterNormalFields<O extends object> = Select<O, Bubbles | Capture, "contai
|
|
|
16
18
|
|
|
17
19
|
// 获取冒泡或捕获的事件
|
|
18
20
|
type GetBubblesOrCaptureEventsFromCompDoc<
|
|
19
|
-
|
|
21
|
+
ComponentDocList extends ComponentDoc[],
|
|
20
22
|
Result extends CustomEventsDoc = {},
|
|
21
|
-
> =
|
|
23
|
+
> = ComponentDocList extends [infer Head extends ComponentDoc, ...infer Rest extends ComponentDoc[]]
|
|
22
24
|
? GetBubblesOrCaptureEventsFromCompDoc<
|
|
23
25
|
Rest,
|
|
24
26
|
Result & (FilterNormalFields<Head["customEvents"] & {}>)
|
|
@@ -47,23 +49,26 @@ type TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<T extends CustomEven
|
|
|
47
49
|
};
|
|
48
50
|
|
|
49
51
|
// 所有子组件自定义事件(过滤掉非冒泡或捕获)的key加入后缀并把值(detail)转换为函数类型
|
|
50
|
-
type GetAllSubCustomEventsConstraint<
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
52
|
+
type GetAllSubCustomEventsConstraint<
|
|
53
|
+
ComponentDocList extends ComponentDoc[],
|
|
54
|
+
AllCustomEvents extends CustomEventsDoc = GetBubblesOrCaptureEventsFromCompDoc<ComponentDocList>,
|
|
55
|
+
> = IfExtends<
|
|
56
|
+
{},
|
|
57
|
+
AllCustomEvents,
|
|
58
|
+
BaseEvent,
|
|
59
|
+
TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<
|
|
60
|
+
AllCustomEvents
|
|
61
|
+
>
|
|
62
|
+
>;
|
|
63
|
+
|
|
64
|
+
type BaseEvent = Record<string, (e: WMBaseEvent) => any>;
|
|
56
65
|
|
|
57
66
|
/**
|
|
58
|
-
* events字段约束
|
|
67
|
+
* events字段约束 由自身事件和冒泡的子组件事件组成。带前缀是子组件事件,带后缀(_catch)表示阻止冒泡
|
|
59
68
|
*/
|
|
60
|
-
export type EventsConstraint<
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
}
|
|
67
|
-
: GetAllSubCustomEventsConstraint<TReceivedComponentDoc>;
|
|
68
|
-
// // 一般事件字段约束
|
|
69
|
-
// & Record<string, (e: WMBaseEvent) => any>;
|
|
69
|
+
export type EventsConstraint<ComponentDocList extends ComponentDoc[] = []> = IfExtends<
|
|
70
|
+
[],
|
|
71
|
+
ComponentDocList,
|
|
72
|
+
BaseEvent,
|
|
73
|
+
GetAllSubCustomEventsConstraint<ComponentDocList>
|
|
74
|
+
>;
|
|
@@ -1,7 +1,55 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
export type EventsOption<TEvents extends object> = {
|
|
2
|
+
/**
|
|
3
|
+
* 根组件事件字段,当RootComopnent传入组件泛型时,有子组件事件提示
|
|
4
|
+
*
|
|
5
|
+
* @example A 无子组件时
|
|
6
|
+
* ```ts
|
|
7
|
+
* RootComponent()({
|
|
8
|
+
* events: {
|
|
9
|
+
* onTap(e) {
|
|
10
|
+
* Checking<typeof e, WMBaseEvent, Test.Pass>;
|
|
11
|
+
* },
|
|
12
|
+
* },
|
|
13
|
+
* });
|
|
14
|
+
* ```
|
|
15
|
+
* @example B
|
|
16
|
+
* ```ts
|
|
17
|
+
* type ComponentDocA = {
|
|
18
|
+
* customEvents: {
|
|
19
|
+
* aaa_str: string;
|
|
20
|
+
* aaa_num: number | Bubbles;
|
|
21
|
+
* };
|
|
22
|
+
* };
|
|
23
|
+
*
|
|
24
|
+
* type ComponentDocB = {
|
|
25
|
+
* customEvents: {
|
|
26
|
+
* bbb_str: string;
|
|
27
|
+
* bbb_num: number | Capture;
|
|
28
|
+
* };
|
|
29
|
+
* };
|
|
30
|
+
* RootComponent<[ComponentDocA, ComponentDocB]>()({
|
|
31
|
+
* events: {
|
|
32
|
+
* // 后缀bubbles表示为子组件的冒泡事件
|
|
33
|
+
* aaa_num_bubbles(e) {
|
|
34
|
+
* Checking<typeof e.detail, number, Test.Pass>;
|
|
35
|
+
* },
|
|
36
|
+
* // 后缀加catch表示阻止事件传递,当前组件类型将不会向上传递此事件类型。
|
|
37
|
+
* aaa_num_bubbles_catch(e) {
|
|
38
|
+
* Checking<typeof e.detail, number, Test.Pass>;
|
|
39
|
+
* },
|
|
40
|
+
* // 后缀capture表示是捕获事件
|
|
41
|
+
* bbb_num_capture(e: Dataset<{ currentTargetDataset: number }, { targetDataset: string }, number>) {
|
|
42
|
+
* Checking<typeof e.detail, number, Test.Pass>;
|
|
43
|
+
* Checking<typeof e.currentTarget.dataset.currentTargetDataset, number, Test.Pass>;
|
|
44
|
+
* Checking<typeof e.target.dataset.targetDataset, string, Test.Pass>;
|
|
45
|
+
* },
|
|
46
|
+
* // 后缀加catch表示阻止事件传递,由于捕获事件向下阻止,所以当发现捕获事件不触发时应查看上级组件是否有阻止事件。
|
|
47
|
+
* bbb_num_capture_catch(e) {
|
|
48
|
+
* Checking<typeof e.detail, number, Test.Pass>;
|
|
49
|
+
* },
|
|
50
|
+
* },
|
|
51
|
+
* });
|
|
52
|
+
* ```
|
|
53
|
+
*/
|
|
54
|
+
events?: TEvents;
|
|
7
55
|
};
|
|
@@ -13,22 +13,22 @@ import { RootComponent } from "../..";
|
|
|
13
13
|
import type { Bubbles, Capture } from "../../CustomEvents/CustomEventsTag";
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
|
-
* 1.
|
|
16
|
+
* 1. 没有子组件时,事件参数e的类型默认为官方基础类型
|
|
17
17
|
*/
|
|
18
18
|
RootComponent()({
|
|
19
19
|
events: {
|
|
20
|
-
|
|
20
|
+
onTap(e) {
|
|
21
21
|
Checking<typeof e, WMBaseEvent, Test.Pass>;
|
|
22
22
|
},
|
|
23
23
|
},
|
|
24
24
|
});
|
|
25
25
|
|
|
26
26
|
/**
|
|
27
|
-
* 2.
|
|
27
|
+
* 2. 没有子组件时,事件参数e可通过WMBaseEvent和WMCustomEvent(多一个detail类型)定义内部类型。
|
|
28
28
|
*/
|
|
29
29
|
RootComponent()({
|
|
30
30
|
events: {
|
|
31
|
-
// 通过WMCustomEvent定义detai,mark,CurrentTargetDataset,targetDataset数据类型
|
|
31
|
+
// 2.1 通过WMCustomEvent定义detai,mark,CurrentTargetDataset,targetDataset数据类型
|
|
32
32
|
customA(
|
|
33
33
|
e: WMCustomEvent<
|
|
34
34
|
{ detailData: string },
|
|
@@ -47,21 +47,21 @@ RootComponent()({
|
|
|
47
47
|
|
|
48
48
|
Checking<typeof e.target.dataset.targetDatasetData, number, Test.Pass>;
|
|
49
49
|
},
|
|
50
|
-
// 通过Detail定义detai类型
|
|
50
|
+
// 2.2 通过Detail定义detai类型
|
|
51
51
|
bbb(e: Detail<{ str: string }>) {
|
|
52
52
|
Checking<typeof e.detail.str, string, Test.Pass>;
|
|
53
53
|
},
|
|
54
|
-
// 通过Mark定义mark类型
|
|
54
|
+
// 2.3 通过Mark定义mark类型
|
|
55
55
|
ccc(e: Mark<{ id: string }>) {
|
|
56
56
|
const markId = e.mark!.id;
|
|
57
57
|
|
|
58
58
|
Checking<typeof markId, string, Test.Pass>;
|
|
59
59
|
},
|
|
60
|
-
// 通过CurrentTargetDataset定义currentTarget.dataset类型
|
|
60
|
+
// 2.4 通过CurrentTargetDataset定义currentTarget.dataset类型
|
|
61
61
|
ddd(e: CurrentTargetDataset<{ str: string }>) {
|
|
62
62
|
Checking<typeof e.currentTarget.dataset.str, string, Test.Pass>;
|
|
63
63
|
},
|
|
64
|
-
// 通过TargetDataset定义target.dateset类型
|
|
64
|
+
// 2.5 通过TargetDataset定义target.dateset类型
|
|
65
65
|
eee(e: TargetDataset<{ str: string }>) {
|
|
66
66
|
Checking<typeof e.target.dataset.str, string, Test.Pass>;
|
|
67
67
|
},
|
|
@@ -86,19 +86,19 @@ type ComponentDocB = ComponentDoc<{
|
|
|
86
86
|
}>;
|
|
87
87
|
|
|
88
88
|
/**
|
|
89
|
-
*
|
|
89
|
+
* 3. 当传入子组件文档列表时,提供子组件的冒泡和捕获事件的字段提示
|
|
90
90
|
*/
|
|
91
91
|
const RootDoc = RootComponent<[ComponentDocA, ComponentDocB]>()({
|
|
92
92
|
events: {
|
|
93
|
-
// 后缀bubbles表示为子组件的冒泡事件
|
|
93
|
+
// 3.1 后缀bubbles表示为子组件的冒泡事件
|
|
94
94
|
aaa_num_bubbles(e) {
|
|
95
95
|
Checking<typeof e.detail, number, Test.Pass>;
|
|
96
96
|
},
|
|
97
|
-
// 后缀加catch表示阻止事件传递,当前组件类型将不会向上传递此事件类型。
|
|
97
|
+
// 3.2 后缀加catch表示阻止事件传递,当前组件类型将不会向上传递此事件类型。
|
|
98
98
|
aaa_num_bubbles_catch(e) {
|
|
99
99
|
Checking<typeof e.detail, number, Test.Pass>;
|
|
100
100
|
},
|
|
101
|
-
// 后缀capture表示是捕获事件
|
|
101
|
+
// 3.3 后缀capture表示是捕获事件
|
|
102
102
|
bbb_num_capture(e: Dataset<{ currentTargetDataset: number }, { targetDataset: string }, number>) {
|
|
103
103
|
Checking<typeof e.detail, number, Test.Pass>;
|
|
104
104
|
|
|
@@ -106,7 +106,7 @@ const RootDoc = RootComponent<[ComponentDocA, ComponentDocB]>()({
|
|
|
106
106
|
|
|
107
107
|
Checking<typeof e.target.dataset.targetDataset, string, Test.Pass>;
|
|
108
108
|
},
|
|
109
|
-
// 后缀加catch表示阻止事件传递,由于捕获事件向下阻止,所以当发现捕获事件不触发时应查看上级组件是否有阻止事件。
|
|
109
|
+
// 3.4 后缀加catch表示阻止事件传递,由于捕获事件向下阻止,所以当发现捕获事件不触发时应查看上级组件是否有阻止事件。
|
|
110
110
|
bbb_num_capture_catch(e) {
|
|
111
111
|
Checking<typeof e.detail, number, Test.Pass>;
|
|
112
112
|
},
|
|
@@ -122,11 +122,11 @@ type RootDocExpect = {
|
|
|
122
122
|
};
|
|
123
123
|
};
|
|
124
124
|
|
|
125
|
-
//
|
|
125
|
+
// 4 返回EventsDoc正常
|
|
126
126
|
Checking<typeof RootDoc, RootDocExpect, Test.Pass>;
|
|
127
127
|
|
|
128
128
|
/**
|
|
129
|
-
*
|
|
129
|
+
* 5 events字段为`{}`时,返回类型中无events字段。
|
|
130
130
|
*/
|
|
131
131
|
const EmptyEventsFields = RootComponent<[ComponentDocA, ComponentDocB]>()({
|
|
132
132
|
events: {},
|
|
@@ -135,7 +135,7 @@ const EmptyEventsFields = RootComponent<[ComponentDocA, ComponentDocB]>()({
|
|
|
135
135
|
Checking<typeof EmptyEventsFields, {}, Test.Pass>;
|
|
136
136
|
|
|
137
137
|
/**
|
|
138
|
-
*
|
|
138
|
+
* 6 没有events字段时,返回类型中无events字段。
|
|
139
139
|
*/
|
|
140
140
|
const NoEventsFields = RootComponent<[ComponentDocA, ComponentDocB]>()({});
|
|
141
141
|
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
+
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
1
2
|
import type { WMCompLifetimes } from "../../../types/OfficialTypeAlias";
|
|
2
|
-
import type {
|
|
3
|
+
import type { FinalOptionsOfComponent } from "../../DefineComponent";
|
|
3
4
|
|
|
4
5
|
export type LifetimesConstraint = // 官方组件生命周期
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
ComputeIntersection<
|
|
7
|
+
& WMCompLifetimes["lifetimes"]
|
|
8
|
+
& {
|
|
9
|
+
/**
|
|
10
|
+
* 建立组件时的真正配置对象
|
|
11
|
+
*/
|
|
12
|
+
beforeCreate?: (options: FinalOptionsOfComponent) => void;
|
|
13
|
+
}
|
|
14
|
+
>;
|
|
@@ -2,6 +2,32 @@ import type { LifetimesConstraint } from "./LifetimesConstraint";
|
|
|
2
2
|
|
|
3
3
|
export type LifetimesOption<TIsPage extends boolean> = TIsPage extends false // 组件开通lifetimes字段
|
|
4
4
|
? {
|
|
5
|
+
/**
|
|
6
|
+
* 在原生类型上增加了beforeCreate周期
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* RootComponent()({
|
|
10
|
+
* lifetimes: {
|
|
11
|
+
* beforeCreate(opitons) {
|
|
12
|
+
* opitons;//为最终进入Component的配置对象
|
|
13
|
+
* },
|
|
14
|
+
* created() {
|
|
15
|
+
* },
|
|
16
|
+
* attached() {
|
|
17
|
+
* },
|
|
18
|
+
* ready() {
|
|
19
|
+
* },
|
|
20
|
+
* detached() {
|
|
21
|
+
* },
|
|
22
|
+
* error(err) {
|
|
23
|
+
* err.cause;
|
|
24
|
+
* },
|
|
25
|
+
* moved() {
|
|
26
|
+
* },
|
|
27
|
+
* },
|
|
28
|
+
* });
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
5
31
|
lifetimes?: LifetimesConstraint;
|
|
6
32
|
}
|
|
7
33
|
// 页面关闭lifetimes字段(其实也可以开启)
|
|
@@ -1,33 +1,23 @@
|
|
|
1
1
|
import { RootComponent } from "../..";
|
|
2
|
-
|
|
3
|
-
* 1 组件时(无ispage字段或为false),
|
|
4
|
-
*/
|
|
2
|
+
|
|
5
3
|
RootComponent()({
|
|
6
4
|
lifetimes: {
|
|
7
5
|
beforeCreate() {},
|
|
8
|
-
|
|
9
6
|
created() {},
|
|
10
|
-
|
|
11
7
|
attached() {},
|
|
12
|
-
|
|
13
8
|
ready() {},
|
|
14
|
-
|
|
15
9
|
detached() {},
|
|
16
|
-
|
|
17
10
|
error(err) {
|
|
18
11
|
err.cause;
|
|
19
12
|
},
|
|
20
13
|
moved() {},
|
|
21
|
-
// @ts-expect-error 错误的声明周期字段报错
|
|
14
|
+
// @ts-expect-error 1 错误的声明周期字段报错
|
|
22
15
|
xxx() {},
|
|
23
16
|
},
|
|
24
17
|
});
|
|
25
18
|
|
|
26
|
-
/**
|
|
27
|
-
* 2. 页面时 不开启lifetimes字段
|
|
28
|
-
*/
|
|
29
19
|
RootComponent()({
|
|
30
20
|
isPage: true,
|
|
31
|
-
// @ts-expect-error 页面时未开启此字段
|
|
21
|
+
// @ts-expect-error 2 页面时未开启此字段
|
|
32
22
|
lifetimes: {},
|
|
33
23
|
});
|
|
@@ -1,31 +1,42 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
3
|
import type { WMCompPageLifetimes, WMPageLifetimes } from "../../../types/OfficialTypeAlias";
|
|
4
|
-
import type { RemoveNullOfRequired } from "../../../types/RemoveNullOfRequired";
|
|
5
4
|
|
|
6
5
|
export type PageLifetimesOption<TIsPage extends boolean, PropertiesDoc extends object> = IfExtends<
|
|
7
6
|
TIsPage,
|
|
8
7
|
false,
|
|
9
8
|
{
|
|
10
|
-
|
|
9
|
+
/**
|
|
10
|
+
* 比官方定义新增load周期,发生在页面onLoad事件后
|
|
11
|
+
*/
|
|
12
|
+
pageLifetimes?: ComputeIntersection<
|
|
11
13
|
// 官方组件页面生命周期
|
|
12
14
|
& Partial<WMCompPageLifetimes>
|
|
13
15
|
& {
|
|
14
16
|
/**
|
|
15
|
-
* 事件发生在页面
|
|
17
|
+
* 事件发生在页面onLoad事件后,要求组件为同步组件
|
|
16
18
|
*/
|
|
17
|
-
load?: () => void
|
|
18
|
-
}
|
|
19
|
+
load?: (props: object) => void | Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
>;
|
|
19
22
|
},
|
|
20
23
|
{
|
|
21
|
-
|
|
24
|
+
/**
|
|
25
|
+
* 官方要求写入methods中的页面生命周期
|
|
26
|
+
*/
|
|
27
|
+
pageLifetimes?: ComputeIntersection<
|
|
22
28
|
& Partial<Omit<WMPageLifetimes, "onLoad">>
|
|
23
29
|
// 替换掉官方的 Parameters<WechatMiniprogram.Page.ILifetime['onLoad']>
|
|
24
30
|
& {
|
|
31
|
+
/** 生命周期回调—监听页面加载
|
|
32
|
+
*
|
|
33
|
+
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取Properties定义的数据。
|
|
34
|
+
*/
|
|
25
35
|
onLoad?: (
|
|
26
|
-
//
|
|
27
|
-
props:
|
|
28
|
-
) => void
|
|
29
|
-
}
|
|
36
|
+
// 页面时PropertiesDoc对象字段是格外不加null的
|
|
37
|
+
props: PropertiesDoc,
|
|
38
|
+
) => void | Promise<void>;
|
|
39
|
+
}
|
|
40
|
+
>;
|
|
30
41
|
}
|
|
31
42
|
>;
|
|
@@ -1,20 +1,22 @@
|
|
|
1
1
|
import { RootComponent } from "../..";
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
3
|
+
* 组件时 非法字段错误
|
|
4
4
|
*/
|
|
5
5
|
RootComponent()({
|
|
6
6
|
pageLifetimes: {
|
|
7
7
|
show() {},
|
|
8
8
|
hide() {},
|
|
9
9
|
resize() {},
|
|
10
|
-
load() {
|
|
11
|
-
|
|
10
|
+
load(props) {
|
|
11
|
+
props;
|
|
12
|
+
},
|
|
13
|
+
// @ts-expect-error 1 错误的声明周期
|
|
12
14
|
xxx() {},
|
|
13
15
|
},
|
|
14
16
|
});
|
|
15
17
|
|
|
16
18
|
/**
|
|
17
|
-
*
|
|
19
|
+
* 页面时
|
|
18
20
|
*/
|
|
19
21
|
RootComponent()({
|
|
20
22
|
isPage: true,
|
|
@@ -22,7 +24,7 @@ RootComponent()({
|
|
|
22
24
|
onLoad(props) {
|
|
23
25
|
props;
|
|
24
26
|
},
|
|
25
|
-
// @ts-expect-error 错误的声明周期
|
|
27
|
+
// @ts-expect-error 2 错误的声明周期
|
|
26
28
|
xxx() {},
|
|
27
29
|
},
|
|
28
30
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import { type DetailedType, RootComponent } from "../../../..";
|
|
3
3
|
|
|
4
|
-
import type { RemoveNullOfRequired } from "../../../../types/RemoveNullOfRequired";
|
|
5
4
|
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
6
5
|
|
|
7
6
|
/**
|
|
@@ -16,7 +15,9 @@ RootComponent()({
|
|
|
16
15
|
},
|
|
17
16
|
show() {},
|
|
18
17
|
// 新增周期函数
|
|
19
|
-
load() {
|
|
18
|
+
load(obj) {
|
|
19
|
+
Checking<typeof obj, object, Test.Pass>;
|
|
20
|
+
},
|
|
20
21
|
},
|
|
21
22
|
});
|
|
22
23
|
|
|
@@ -43,14 +44,12 @@ RootComponent()({
|
|
|
43
44
|
onLoad(props) {
|
|
44
45
|
Checking<
|
|
45
46
|
typeof props,
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}>
|
|
53
|
-
>,
|
|
47
|
+
{
|
|
48
|
+
union?: Mock_User;
|
|
49
|
+
optionalObject?: Mock_User | null;
|
|
50
|
+
str: string;
|
|
51
|
+
obj: object;
|
|
52
|
+
},
|
|
54
53
|
Test.Pass
|
|
55
54
|
>;
|
|
56
55
|
},
|
|
@@ -3,37 +3,24 @@ import type { Validators } from "../../../types/Validators";
|
|
|
3
3
|
import type { PropertiesConstraint } from "./PropertiesConstraint";
|
|
4
4
|
import type { PropertiesValueValidator } from "./PropertiesValueValidator";
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* properties 配置字段
|
|
8
|
-
* @remarks 二参 三参为了让AnyPropertiesOption也可以复用这个泛型
|
|
9
|
-
*/
|
|
10
6
|
export type PropertiesOption<
|
|
11
7
|
TProperties extends PropertiesConstraint,
|
|
12
|
-
>
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
// G extends object,
|
|
32
|
-
// TPrefix extends string,
|
|
33
|
-
// Message extends string = "前缀错误",
|
|
34
|
-
// Result = TPrefix extends "" ? unknown : {
|
|
35
|
-
// [
|
|
36
|
-
// k in keyof G as k extends `${TPrefix}_${string}` ? never : k
|
|
37
|
-
// ]: G[k] extends object ? `⚠️${Message}` : () => `⚠️${Message}`;
|
|
38
|
-
// },
|
|
39
|
-
// > = EmptyObject extends Result ? unknown : Result;
|
|
8
|
+
> = {
|
|
9
|
+
/**
|
|
10
|
+
* 可通过 as DetailedType<anyType> 书写任意类型
|
|
11
|
+
* @remarks
|
|
12
|
+
*
|
|
13
|
+
* 禁用observable字段(watch代替)
|
|
14
|
+
*
|
|
15
|
+
* 简写或对象写法(无value字段)时为必传属性(组件时必传对象实际类型加入null,页面不加),对象写法有value字段为可选属性.
|
|
16
|
+
*
|
|
17
|
+
* 有value类型检测和非法字段检测(例如value写出values)
|
|
18
|
+
*/
|
|
19
|
+
properties?:
|
|
20
|
+
& TProperties
|
|
21
|
+
& Validators<[
|
|
22
|
+
PropertiesValueValidator<TProperties>,
|
|
23
|
+
// 放在最后一个,正常返回不是unknown 而是Record<string,unknown>
|
|
24
|
+
V.IllegalFieldValidator<TProperties, "value" | "type" | "optionalTypes", 1>,
|
|
25
|
+
]>;
|
|
26
|
+
};
|
|
@@ -13,11 +13,11 @@ type _RootComponentDoc = {
|
|
|
13
13
|
store?: object;
|
|
14
14
|
watch?: Record<string, Func>;
|
|
15
15
|
lifetimes?: LifetimesConstraint;
|
|
16
|
-
pageLifetimes?: Partial<WMCompPageLifetimes & { load: Func }
|
|
16
|
+
pageLifetimes?: Partial<WMCompPageLifetimes & { load: Func }>;
|
|
17
17
|
};
|
|
18
18
|
|
|
19
19
|
// 验证key是否合法
|
|
20
|
-
type _Validator<O, ErrKeys = Exclude<keyof O, keyof
|
|
20
|
+
type _Validator<O, Doc, ErrKeys = Exclude<keyof O, keyof Doc>> = [ErrKeys] extends [never] ? Doc
|
|
21
21
|
: `错误的字段${ErrKeys & string}`;
|
|
22
22
|
|
|
23
23
|
/**
|
|
@@ -35,4 +35,20 @@ type _Validator<O, ErrKeys = Exclude<keyof O, keyof _RootComponentDoc>> = [ErrKe
|
|
|
35
35
|
* };
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
|
-
export type RootComponentDoc<O extends _Validator<O> = _RootComponentDoc> = O;
|
|
38
|
+
export type RootComponentDoc<O extends _Validator<O, _RootComponentDoc> = _RootComponentDoc> = O;
|
|
39
|
+
|
|
40
|
+
type _RootPageDoc = {
|
|
41
|
+
isPage?: boolean;
|
|
42
|
+
properties?: object;
|
|
43
|
+
data?: object;
|
|
44
|
+
computed?: object;
|
|
45
|
+
customEvents?: object;
|
|
46
|
+
methods?: object;
|
|
47
|
+
events?: object;
|
|
48
|
+
store?: object;
|
|
49
|
+
watch?: Record<string, Func>;
|
|
50
|
+
lifetimes?: LifetimesConstraint;
|
|
51
|
+
pageLifetimes?: Partial<WMPageLifetimes>;
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
export type RootPageDoc<O extends _Validator<O, _RootPageDoc> = _RootPageDoc> = O;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { StoreConstraint } from "./StoreConstraint";
|
|
2
2
|
|
|
3
|
-
export type
|
|
3
|
+
export type GetStoreDoc<TStore extends StoreConstraint> = { [k in keyof TStore]: ReturnType<TStore[k]> };
|
|
@@ -1,8 +1,20 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
2
|
import type { StoreConstraint } from "./StoreConstraint";
|
|
3
3
|
|
|
4
|
-
export type StoreOption<TStore extends StoreConstraint,
|
|
4
|
+
export type StoreOption<TStore extends StoreConstraint, TDuplicateKeys extends PropertyKey> = {
|
|
5
|
+
/**
|
|
6
|
+
* 全局响应式数据字段,全局store对应数据变化实例对应数据自动setData。与properties和data字段有重复检测
|
|
7
|
+
* @example
|
|
8
|
+
* ```ts
|
|
9
|
+
* {
|
|
10
|
+
* //...
|
|
11
|
+
* store: {
|
|
12
|
+
* responsiveData: () => sroreX.str,
|
|
13
|
+
* },
|
|
14
|
+
* }
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
5
17
|
store?:
|
|
6
18
|
& TStore
|
|
7
|
-
& V.DuplicateFieldValidator<TStore,
|
|
19
|
+
& V.DuplicateFieldValidator<TStore, TDuplicateKeys, "字段重复">;
|
|
8
20
|
};
|
|
@@ -5,15 +5,15 @@ const user = observable({
|
|
|
5
5
|
age: 20,
|
|
6
6
|
});
|
|
7
7
|
|
|
8
|
-
// 约束错误
|
|
8
|
+
// 1 约束错误
|
|
9
9
|
RootComponent()({
|
|
10
10
|
store: {
|
|
11
|
-
// @ts-expect-error 不能将类型“string”分配给类型“() => unknown”
|
|
11
|
+
// @ts-expect-error 1.1 不能将类型“string”分配给类型“() => unknown”
|
|
12
12
|
userName: user.name,
|
|
13
13
|
},
|
|
14
14
|
});
|
|
15
15
|
|
|
16
|
-
// 重复字段错误
|
|
16
|
+
// 2 重复字段错误
|
|
17
17
|
RootComponent()({
|
|
18
18
|
properties: {
|
|
19
19
|
userName: String,
|
|
@@ -22,9 +22,9 @@ RootComponent()({
|
|
|
22
22
|
userAge: 20,
|
|
23
23
|
},
|
|
24
24
|
store: {
|
|
25
|
-
// @ts-expect-error 1 与properties字段重复
|
|
25
|
+
// @ts-expect-error 2.1 与properties字段重复
|
|
26
26
|
userName: () => user.name,
|
|
27
|
-
// @ts-expect-error 2 与userAge字段重复
|
|
27
|
+
// @ts-expect-error 2.2 与userAge字段重复
|
|
28
28
|
userAge: () => user.age,
|
|
29
29
|
},
|
|
30
30
|
});
|