annil 1.1.1 → 1.2.0-beta.0
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 +24 -28
- package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -1
- package/dist/api/DefineComponent/index.d.ts +12 -12
- package/dist/api/DefineComponent/index.js.map +1 -1
- 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 +9 -10
- 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/SubPageLifetimesOption.d.ts +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 +19 -13
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/index.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 +3 -3
- package/dist/index.js +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/dist/utils/InnerMarker.js +1 -1
- package/dist/utils/InnerMarker.js.map +1 -1
- package/dist/utils/deepClone.js.map +1 -1
- package/package.json +4 -2
- package/src/api/DefineComponent/collectOptionsForComponent.ts +176 -66
- package/src/api/DefineComponent/index.ts +13 -9
- 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 +20 -19
- 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/SubPageLifetimesOption.ts +2 -2
- 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 +28 -17
- package/src/behaviors/BComputedAndWatch/index.ts +2 -2
- package/src/behaviors/BComputedAndWatch/types.ts +1 -0
- package/src/behaviors/BStore.ts +4 -6
- package/src/behaviors/BbeforeCreated.ts +2 -2
- package/src/index.ts +12 -8
- package/src/types/OfficialTypeAlias.ts +7 -11
- package/src/types/RemoveInnerData.ts +5 -0
- package/src/utils/InnerMarker.ts +1 -1
- package/src/utils/deepClone.ts +1 -0
|
@@ -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
|
+
* 周期发生在组件attached之后,页面onLoad之前,要求组件为同步组件
|
|
18
|
+
* 最低基础库: `3.0.2`
|
|
16
19
|
*/
|
|
17
|
-
load?: () => void
|
|
18
|
-
}
|
|
20
|
+
load?: (props: object) => void | Promise<void>;
|
|
21
|
+
}
|
|
22
|
+
>;
|
|
19
23
|
},
|
|
20
24
|
{
|
|
21
|
-
|
|
25
|
+
/**
|
|
26
|
+
* 官方要求写入methods中的页面生命周期
|
|
27
|
+
*/
|
|
28
|
+
pageLifetimes?: ComputeIntersection<
|
|
22
29
|
& Partial<Omit<WMPageLifetimes, "onLoad">>
|
|
23
30
|
// 替换掉官方的 Parameters<WechatMiniprogram.Page.ILifetime['onLoad']>
|
|
24
31
|
& {
|
|
32
|
+
/** 生命周期回调—监听页面加载
|
|
33
|
+
*
|
|
34
|
+
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取Properties定义的数据。
|
|
35
|
+
*/
|
|
25
36
|
onLoad?: (
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
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
|
});
|
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
|
|
3
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
4
|
-
import { RootComponent } from "../..";
|
|
5
|
-
|
|
6
3
|
import type { DetailedType } from "../../../..";
|
|
7
|
-
|
|
8
|
-
// type Mock_Cart,
|
|
9
|
-
// mock_requiredTypes,
|
|
10
|
-
// mock_requiredUnion,
|
|
11
|
-
// type Mock_User,
|
|
12
|
-
// } from "../../Properties/expected/normalRequired";
|
|
4
|
+
import { RootComponent } from "../..";
|
|
13
5
|
import type { OptionalType } from "../../Properties/PropertiesConstraint";
|
|
14
6
|
import {
|
|
15
7
|
type Mock_Cart,
|
|
@@ -155,8 +147,5 @@ RootComponent()({
|
|
|
155
147
|
|
|
156
148
|
Checking<string, typeof oldValue, Test.Pass>;
|
|
157
149
|
},
|
|
158
|
-
|
|
159
|
-
"optional_objOrNull.age"() {
|
|
160
|
-
},
|
|
161
150
|
},
|
|
162
151
|
});
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type { NoInfer } from "hry-types/src/Generic/NoInfer";
|
|
3
2
|
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
4
3
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
5
4
|
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
6
5
|
import type { ComputeObject } from "../../types/ComputeObj";
|
|
7
|
-
import type { WMCompOtherOption
|
|
6
|
+
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
8
7
|
import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
|
|
9
8
|
import type { ComputedConstraint } from "./Computed/ComputedConstraint";
|
|
10
9
|
import type { ComputedOption } from "./Computed/ComputedOption";
|
|
@@ -26,13 +25,12 @@ import type { PageLifetimesOption } from "./PageLifetimes/PageLifetimesOption";
|
|
|
26
25
|
import type { GetPropertiesDoc } from "./Properties/GetPropertiesDoc";
|
|
27
26
|
import type { PropertiesConstraint } from "./Properties/PropertiesConstraint";
|
|
28
27
|
import type { PropertiesOption } from "./Properties/PropertiesOption";
|
|
29
|
-
import type {
|
|
28
|
+
import type { GetStoreDoc } from "./Store/GeTStoreDoc";
|
|
30
29
|
import type { StoreConstraint } from "./Store/StoreConstraint";
|
|
31
30
|
import type { StoreOption } from "./Store/StoreOption";
|
|
32
31
|
import type { WatchOption } from "./Watch/WatchOption";
|
|
33
32
|
|
|
34
33
|
type RootComponentOptions<
|
|
35
|
-
TReceivedComponentDoc extends object,
|
|
36
34
|
TEvents extends object,
|
|
37
35
|
TIsPage extends boolean,
|
|
38
36
|
TCustomEvents extends CustomEventConstraint,
|
|
@@ -51,12 +49,12 @@ type RootComponentOptions<
|
|
|
51
49
|
& MethodsOption<TMethods, keyof (EventsDoc & CustomEventsDoc)>
|
|
52
50
|
& PropertiesOption<TProperties>
|
|
53
51
|
& IsPageOption<TIsPage>
|
|
54
|
-
&
|
|
55
|
-
&
|
|
56
|
-
& DataOption<TData, PropertiesDoc>
|
|
57
|
-
& StoreOption<TStore, PropertiesDoc & DataDoc>
|
|
58
|
-
& ComputedOption<TComputed,
|
|
59
|
-
& PageLifetimesOption<TIsPage,
|
|
52
|
+
& EventsOption<TEvents>
|
|
53
|
+
& CustomEventsOption<TCustomEvents, keyof EventsDoc>
|
|
54
|
+
& DataOption<TData, keyof PropertiesDoc>
|
|
55
|
+
& StoreOption<TStore, keyof (PropertiesDoc & DataDoc)>
|
|
56
|
+
& ComputedOption<TComputed, keyof (PropertiesDoc & DataDoc & StoreDoc)>
|
|
57
|
+
& PageLifetimesOption<TIsPage, PropertiesDoc>
|
|
60
58
|
& LifetimesOption<TIsPage>
|
|
61
59
|
& WatchOption<
|
|
62
60
|
& ComputedDoc
|
|
@@ -76,10 +74,10 @@ type RootComponentOptions<
|
|
|
76
74
|
>
|
|
77
75
|
>;
|
|
78
76
|
|
|
79
|
-
type RootComponentConstructor<
|
|
77
|
+
type RootComponentConstructor<TComponentDocList extends ComponentDoc[]> = {
|
|
80
78
|
<
|
|
81
79
|
// TEvents 不能有默认值 {} 会引起事件参数类型(e)失效
|
|
82
|
-
TEvents extends EventsConstraint<
|
|
80
|
+
TEvents extends EventsConstraint<TComponentDocList>,
|
|
83
81
|
TIsPage extends boolean = false,
|
|
84
82
|
const TProperties extends PropertiesConstraint = {},
|
|
85
83
|
TData extends object = {},
|
|
@@ -88,15 +86,14 @@ type RootComponentConstructor<TReceivedComponentDoc extends ComponentDoc[] | Com
|
|
|
88
86
|
// 页面时自定义事件无意义
|
|
89
87
|
TCustomEvents extends IfExtends<TIsPage, false, CustomEventConstraint, EmptyObject> = {},
|
|
90
88
|
TMethods extends MethodsConstraint = {},
|
|
91
|
-
EventsDoc extends object = IfExtends<EventsConstraint<
|
|
89
|
+
EventsDoc extends object = IfExtends<EventsConstraint<TComponentDocList>, TEvents, {}, TEvents>,
|
|
92
90
|
CustomEventsDoc extends object = GetCustomEventDoc<TCustomEvents>,
|
|
93
91
|
PropertiesDoc extends object = GetPropertiesDoc<TProperties, TIsPage>,
|
|
94
92
|
DataDoc extends object = TData,
|
|
95
|
-
StoreDoc extends object =
|
|
93
|
+
StoreDoc extends object = GetStoreDoc<TStore>,
|
|
96
94
|
ComputedDoc extends object = GetComputedDoc<TComputed>,
|
|
97
95
|
>(
|
|
98
96
|
options: RootComponentOptions<
|
|
99
|
-
TReceivedComponentDoc,
|
|
100
97
|
TEvents,
|
|
101
98
|
TIsPage,
|
|
102
99
|
TCustomEvents,
|
|
@@ -126,10 +123,10 @@ type RootComponentConstructor<TReceivedComponentDoc extends ComponentDoc[] | Com
|
|
|
126
123
|
};
|
|
127
124
|
|
|
128
125
|
export function RootComponent<
|
|
129
|
-
//
|
|
130
|
-
|
|
126
|
+
// TComponentDocList泛型为了给events字段提供类型约束
|
|
127
|
+
TComponentDocList extends ComponentDoc[] = [],
|
|
131
128
|
>(): RootComponentConstructor<
|
|
132
|
-
|
|
129
|
+
TComponentDocList
|
|
133
130
|
> {
|
|
134
131
|
return ((options: any) => options as RootComponentTrueOptions) as any;
|
|
135
132
|
}
|
|
@@ -140,10 +137,14 @@ export type RootComponentTrueOptions = {
|
|
|
140
137
|
data?: DataConstraint;
|
|
141
138
|
computed?: ComputedConstraint;
|
|
142
139
|
customEvents?: CustomEventConstraint;
|
|
140
|
+
observers?: Record<string, Func>;
|
|
143
141
|
methods?: MethodsConstraint;
|
|
142
|
+
behaviors?: string[];
|
|
144
143
|
events?: EventsConstraint;
|
|
145
144
|
store?: StoreConstraint;
|
|
146
145
|
watch?: Record<string, Func>;
|
|
147
146
|
lifetimes?: LifetimesConstraint;
|
|
148
|
-
pageLifetimes?:
|
|
147
|
+
pageLifetimes?:
|
|
148
|
+
| PageLifetimesOption<false, object>["pageLifetimes"]
|
|
149
|
+
| PageLifetimesOption<true, object>["pageLifetimes"];
|
|
149
150
|
};
|
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { ReadonlyDeep } from "hry-types/src/Any/_api";
|
|
3
|
-
import type { Wm } from "../../../../thirdLib";
|
|
4
|
-
import type { ComponentDocExtension } from "../../../../types/ComponentDocExtension";
|
|
5
3
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
6
4
|
|
|
7
5
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
@@ -15,61 +13,32 @@ type CompDoc = ComponentDoc<{
|
|
|
15
13
|
};
|
|
16
14
|
}>;
|
|
17
15
|
|
|
18
|
-
// 1 data字段的key提示为:组件文档字段去除inherit字段后的字段.值类型为:文档对应字段类型或函数返回类型(表示引入的Store数据)。或临时字段(内部运算所用字段,无法渲染到页面)key,值类型为unknown
|
|
19
16
|
SubComponent<{}, CompDoc>()({
|
|
20
17
|
inherit: {
|
|
21
18
|
aaa_obj: "wxml",
|
|
22
19
|
},
|
|
23
20
|
data: {
|
|
21
|
+
// 1. 子组件key和对应的类型。
|
|
24
22
|
aaa_str: "a",
|
|
25
23
|
aaa_num: 123,
|
|
24
|
+
// 2. 可写内部字段,一般作为公共的临时数据。
|
|
26
25
|
_aaa_template: "internal", // 内部临时数据
|
|
27
26
|
},
|
|
28
27
|
});
|
|
29
28
|
|
|
30
|
-
//
|
|
31
|
-
|
|
32
|
-
Wm.View,
|
|
33
|
-
{ properties: { view_obj: Mock_User | null; view_str: string; view_ddd: number } }
|
|
34
|
-
>;
|
|
35
|
-
|
|
36
|
-
const res = SubComponent<{}, viewExtends>()({
|
|
37
|
-
inherit: {
|
|
38
|
-
view_style: "wxml",
|
|
39
|
-
},
|
|
40
|
-
data: {
|
|
41
|
-
// view组件key
|
|
42
|
-
view_class: "h-full",
|
|
43
|
-
view_hover_class: "none",
|
|
44
|
-
// 拓展的字段
|
|
45
|
-
view_obj: {} as Mock_User | null,
|
|
46
|
-
view_str: "a",
|
|
47
|
-
view_ddd: 123,
|
|
48
|
-
},
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
Checking<typeof res, never, Test.Pass>;
|
|
52
|
-
|
|
53
|
-
// 2 CompDoc去除Inherit字段后为空,可写非临时字段(内部字段)
|
|
54
|
-
SubComponent<{}, CompDoc>()({
|
|
29
|
+
//
|
|
30
|
+
SubComponent<{ data: { _num: number } }, CompDoc>()({
|
|
55
31
|
inherit: {
|
|
56
32
|
aaa_str: "wxml",
|
|
57
33
|
aaa_num: "wxml",
|
|
58
34
|
aaa_obj: "wxml",
|
|
59
35
|
},
|
|
60
36
|
data: {
|
|
37
|
+
// 3 CompDoc去除Inherit字段后为空时,可写内部字段
|
|
61
38
|
_aaa_str: "str",
|
|
62
39
|
},
|
|
63
40
|
});
|
|
64
41
|
|
|
65
|
-
// 3 CompDoc 为空对象时,参数为空对象,返回never
|
|
66
|
-
|
|
67
|
-
type EmptyCompDoc = ComponentDoc<{}>;
|
|
68
|
-
|
|
69
|
-
const res1 = SubComponent<{}, EmptyCompDoc>()({});
|
|
70
|
-
|
|
71
|
-
Checking<typeof res1, never, Test.Pass>;
|
|
72
|
-
|
|
73
42
|
SubComponent<{}, CompDoc>()({
|
|
74
43
|
data: {
|
|
75
44
|
aaa_str: "a",
|
|
@@ -79,7 +48,7 @@ SubComponent<{}, CompDoc>()({
|
|
|
79
48
|
},
|
|
80
49
|
methods: {
|
|
81
50
|
aaa_1() {
|
|
82
|
-
// 4 this.data
|
|
51
|
+
// 4 this.data中的data配置数据
|
|
83
52
|
Checking<
|
|
84
53
|
typeof this.data,
|
|
85
54
|
ReadonlyDeep<{
|
|
@@ -4,18 +4,23 @@ import type { Detail, WMBaseEvent } from "../../../types/OfficialTypeAlias";
|
|
|
4
4
|
import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
|
|
5
5
|
import type { Bubbles, Capture, CustomEventsTags } from "../../RootComponent/CustomEvents/CustomEventsTag";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 把组件事件类型转为函数类型,冒泡事件捕获事件会多一个加后缀(_catch)的key,表示阻止事件冒泡和捕获。
|
|
9
|
+
*/
|
|
7
10
|
export type SubEventsConstraint<
|
|
8
11
|
CompDoc extends ComponentDoc,
|
|
9
|
-
keys extends keyof CompDoc["customEvents"] = keyof CompDoc["customEvents"],
|
|
10
12
|
> = {
|
|
11
13
|
[
|
|
12
|
-
k in
|
|
14
|
+
k in keyof CompDoc["customEvents"] as Contains<CompDoc["customEvents"][k], Bubbles | Capture> extends true
|
|
15
|
+
? (k | `${k & string}_catch`)
|
|
13
16
|
: k
|
|
14
17
|
]?: (
|
|
15
18
|
e: IfExtends<
|
|
19
|
+
// 有可能是基础组件(手写类型),所以事件类型可能为WMBaseEvent
|
|
16
20
|
WMBaseEvent,
|
|
17
21
|
CompDoc["customEvents"][k],
|
|
18
22
|
WMBaseEvent,
|
|
23
|
+
// 去除 CustomEventsTags 标记
|
|
19
24
|
Detail<Exclude<CompDoc["customEvents"][k], CustomEventsTags>>
|
|
20
25
|
>,
|
|
21
26
|
) => void;
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
import type { V } from "hry-types";
|
|
2
2
|
|
|
3
|
-
export type SubEventsOption<TSubEvents, SubEventsDoc extends object,
|
|
3
|
+
export type SubEventsOption<TSubEvents, SubEventsDoc extends object, legalKeys extends PropertyKey> = {
|
|
4
|
+
/**
|
|
5
|
+
* 子组件事件(基础事件|自定义事件)
|
|
6
|
+
* 可使用内部泛型(Detail、Mark、WMBaseEvent、WMCustomEvent、CurrentTargetDataset、TargetDataset)自定义事件类型
|
|
7
|
+
* 非法字段检测(除了组件事件的key均属于非法字段)
|
|
8
|
+
*/
|
|
4
9
|
events?:
|
|
5
10
|
& TSubEvents
|
|
6
|
-
& V.IllegalFieldValidator<SubEventsDoc,
|
|
11
|
+
& V.IllegalFieldValidator<SubEventsDoc, legalKeys>;
|
|
7
12
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
|
|
2
|
+
import type { Bubbles } from "../../../RootComponent/CustomEvents/CustomEventsTag";
|
|
2
3
|
import { SubComponent } from "../..";
|
|
3
4
|
|
|
4
5
|
type CompDoc = ComponentDoc<{
|
|
@@ -17,16 +18,16 @@ SubComponent<{}, CompDoc>()({
|
|
|
17
18
|
|
|
18
19
|
type CompDoc1 = ComponentDoc<{
|
|
19
20
|
customEvents: {
|
|
20
|
-
aaa_str: string;
|
|
21
|
+
aaa_str: string | Bubbles;
|
|
21
22
|
};
|
|
22
23
|
}>;
|
|
23
24
|
|
|
24
|
-
// 组件文档有自定义事件时,events下的字段仅可写文档包含字段
|
|
25
|
+
// 非法字段检测 组件文档有自定义事件时,events下的字段仅可写文档包含字段
|
|
25
26
|
SubComponent<{}, CompDoc1>()({
|
|
26
27
|
events: {
|
|
27
|
-
aaa_str(e) {
|
|
28
|
+
aaa_str(e) { // ok
|
|
28
29
|
e;
|
|
29
|
-
},
|
|
30
|
+
},
|
|
30
31
|
// @ts-expect-error 非法字段
|
|
31
32
|
aaa_other() {},
|
|
32
33
|
},
|