annil 1.7.5-beta.4 → 1.7.6
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/README.md +45 -38
- package/dist/api/DefineComponent/ReturnType/ComponentType.d.ts +18 -0
- package/dist/api/DefineComponent/ReturnType/ComponentType.js +2 -0
- package/dist/api/DefineComponent/ReturnType/ComponentType.js.map +1 -0
- package/dist/api/DefineComponent/ReturnType/CreateComponentDoc.d.ts +3 -3
- package/dist/api/DefineComponent/ReturnType/CreatePageDoc.d.ts +2 -2
- package/dist/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.d.ts +3 -3
- package/dist/api/DefineComponent/RootComponent/RootComponentOption.d.ts +2 -2
- package/dist/api/DefineComponent/SubComponents/SubComponentsOption.d.ts +2 -2
- package/dist/api/DefineComponent/index.d.ts +5 -5
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js +2 -2
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js +1 -0
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js +2 -2
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/index.js +1 -1
- package/dist/api/DefineComponent/normalizeOptions/index.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js +1 -0
- package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js.map +1 -1
- package/dist/api/RootComponent/Events/EventsConstraint.d.ts +4 -4
- package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +3 -1
- package/dist/api/RootComponent/Properties/GetPropertiesDoc.d.ts +2 -1
- package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +2 -2
- package/dist/api/RootComponent/{RootComponentDoc.d.ts → RootComponentType.d.ts} +16 -15
- package/dist/api/RootComponent/RootComponentType.js +2 -0
- package/dist/api/RootComponent/RootComponentType.js.map +1 -0
- package/dist/api/RootComponent/index.d.ts +5 -4
- package/dist/api/RootComponent/index.js.map +1 -1
- package/dist/api/SubComponent/{SubComponentDoc.d.ts → SubComponentType.d.ts} +3 -3
- package/dist/api/SubComponent/SubComponentType.js +2 -0
- package/dist/api/SubComponent/SubComponentType.js.map +1 -0
- package/dist/api/SubComponent/SubComputed/SubComputedOption.d.ts +2 -2
- package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +2 -2
- package/dist/api/SubComponent/index.d.ts +9 -6
- package/dist/api/SubComponent/index.js.map +1 -1
- package/dist/behaviors/BStore.d.ts +1 -1
- package/dist/behaviors/BStore.js +33 -18
- package/dist/behaviors/BStore.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/types/CreateComponentType.d.ts +23 -2
- package/dist/types/ExtendComponentType.d.ts +34 -0
- package/dist/types/ExtendComponentType.js +6 -0
- package/dist/types/ExtendComponentType.js.map +1 -0
- package/dist/types/GetComponentPrefix.d.ts +2 -2
- package/dist/types/RemoveNullOfRequired.d.ts +7 -0
- package/dist/types/RemoveNullOfRequired.js +2 -0
- package/dist/types/RemoveNullOfRequired.js.map +1 -0
- package/dist/types/ReplacePrefix.d.ts +2 -2
- package/dist/utils/assertNonNullable.js +1 -0
- package/dist/utils/assertNonNullable.js.map +1 -1
- package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.d.ts → utils/deepEqual.d.ts} +1 -1
- package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js → utils/deepEqual.js} +3 -3
- package/dist/utils/deepEqual.js.map +1 -0
- package/package.json +2 -3
- package/src/api/DefineComponent/NameOrPage/test/error.test.ts +6 -6
- package/src/api/DefineComponent/ReturnType/{ComponentDoc.ts → ComponentType.ts} +6 -7
- package/src/api/DefineComponent/ReturnType/CreateComponentDoc.ts +4 -4
- package/src/api/DefineComponent/ReturnType/CreatePageDoc.ts +2 -2
- package/src/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.ts +3 -3
- package/src/api/DefineComponent/ReturnType/GetPropertiesDocOfSubDoc.ts +3 -3
- package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +5 -5
- package/src/api/DefineComponent/RootComponent/RootComponentOption.ts +2 -2
- package/src/api/DefineComponent/SubComponents/SubComponentsOption.ts +2 -2
- package/src/api/DefineComponent/SubComponents/test/normal.test.ts +3 -3
- package/src/api/DefineComponent/index.ts +7 -7
- package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.ts +2 -2
- package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.ts +1 -0
- package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/index.ts +2 -2
- package/src/api/DefineComponent/normalizeOptions/index.ts +1 -1
- package/src/api/DefineComponent/normalizeOptions/internalFieldProtection.ts +1 -0
- package/src/api/RootComponent/Computed/test/normal.test.ts +20 -0
- package/src/api/RootComponent/Events/EventsConstraint.ts +5 -5
- package/src/api/RootComponent/Events/test/normal.test.ts +5 -5
- package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +2 -4
- package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +4 -1
- package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +26 -0
- package/src/api/RootComponent/Properties/GetOptionalDoc.ts +4 -4
- package/src/api/RootComponent/Properties/GetPropertiesDoc.ts +2 -1
- package/src/api/RootComponent/Properties/GetRequiredDoc.ts +9 -23
- package/src/api/RootComponent/{RootComponentDoc.ts → RootComponentType.ts} +16 -15
- package/src/api/RootComponent/index.ts +10 -4
- package/src/api/SubComponent/{SubComponentDoc.ts → SubComponentType.ts} +3 -3
- package/src/api/SubComponent/SubComputed/SubComputedOption.ts +2 -0
- package/src/api/SubComponent/SubComputed/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +5 -5
- package/src/api/SubComponent/SubData/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubData/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +2 -2
- package/src/api/SubComponent/SubEvents/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubEvents/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +2 -2
- package/src/api/SubComponent/SubInherit/test/error.test.ts +6 -6
- package/src/api/SubComponent/SubInherit/test/normal.test.ts +18 -4
- package/src/api/SubComponent/SubInstance/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubInstance/test/normal.test.ts +4 -4
- package/src/api/SubComponent/SubMethods/test/error.test.ts +4 -4
- package/src/api/SubComponent/SubMethods/test/normarl.test.ts +4 -4
- package/src/api/SubComponent/SubReturnType/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubReturnType/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubStore/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +4 -4
- package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +2 -2
- package/src/api/SubComponent/SubWatch/test/WatchSubData.test.ts +2 -2
- package/src/api/SubComponent/index.ts +17 -11
- package/src/behaviors/BStore.ts +37 -23
- package/src/index.ts +2 -2
- package/src/types/CreateComponentType.ts +23 -2
- package/src/types/ExtendComponentType.ts +60 -0
- package/src/types/GetComponentPrefix.ts +2 -2
- package/src/types/GetPropertiesDuplicatedKeys.ts +3 -3
- package/src/types/ReplacePrefix.ts +2 -2
- package/src/utils/assertNonNullable.ts +1 -0
- package/src/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.ts → utils/deepEqual.ts} +2 -3
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.d.ts +0 -18
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.js +0 -2
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.js.map +0 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js.map +0 -1
- package/dist/api/RootComponent/RootComponentDoc.js +0 -2
- package/dist/api/RootComponent/RootComponentDoc.js.map +0 -1
- package/dist/api/SubComponent/SubComponentDoc.js +0 -2
- package/dist/api/SubComponent/SubComponentDoc.js.map +0 -1
- package/dist/types/DocAssign.d.ts +0 -10
- package/dist/types/DocAssign.js +0 -6
- package/dist/types/DocAssign.js.map +0 -1
- package/src/types/DocAssign.ts +0 -36
- package/tsconfig.json +0 -23
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RootComponentType } from "../../RootComponent/RootComponentType";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* DefineComponent API`rootComponent`字段配置
|
|
5
5
|
*/
|
|
6
|
-
export type RootComponentOption<TRootComponent extends
|
|
6
|
+
export type RootComponentOption<TRootComponent extends RootComponentType> = {
|
|
7
7
|
/**
|
|
8
8
|
* 根组件配置
|
|
9
9
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SubComponentType } from "../../SubComponent/SubComponentType";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* RootComponent API 的`subComponents`字段配置
|
|
5
5
|
*/
|
|
6
6
|
export type SubComponentsOption<
|
|
7
|
-
TSubComponentTuple extends
|
|
7
|
+
TSubComponentTuple extends SubComponentType[],
|
|
8
8
|
> = {
|
|
9
9
|
/**
|
|
10
10
|
* 子组件列表
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { Bubbles, Composed } from "../../../RootComponent/CustomEvents/CustomEventsTag";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SubComponentType } from "../../../SubComponent/SubComponentType";
|
|
4
4
|
import { DefineComponent } from "../..";
|
|
5
5
|
|
|
6
|
-
const SubDocIsAny = {} as
|
|
6
|
+
const SubDocIsAny = {} as SubComponentType<{
|
|
7
7
|
a: number | Composed;
|
|
8
8
|
}>;
|
|
9
9
|
|
|
10
|
-
const NonEmptyRootDoc = {} as
|
|
10
|
+
const NonEmptyRootDoc = {} as SubComponentType<{
|
|
11
11
|
a: string | Bubbles | Composed;
|
|
12
12
|
}>;
|
|
13
13
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { RootComponentTrueOptions } from "../RootComponent";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { RootComponentType } from "../RootComponent/RootComponentType";
|
|
4
|
+
import type { SubComponentType } from "../SubComponent/SubComponentType";
|
|
5
5
|
import type { NameOrPathOption } from "./NameOrPage/NameOrPathOption";
|
|
6
6
|
import { normalizeOptions } from "./normalizeOptions";
|
|
7
7
|
import type { CreateComponentDoc } from "./ReturnType/CreateComponentDoc";
|
|
@@ -11,8 +11,8 @@ import type { SubComponentsOption } from "./SubComponents/SubComponentsOption";
|
|
|
11
11
|
export type Path = `/${string}`;
|
|
12
12
|
|
|
13
13
|
type RootOptions<
|
|
14
|
-
TRootComponentDoc extends
|
|
15
|
-
TSubComponentTuple extends
|
|
14
|
+
TRootComponentDoc extends RootComponentType,
|
|
15
|
+
TSubComponentTuple extends SubComponentType[],
|
|
16
16
|
TName extends string,
|
|
17
17
|
TPath extends Path,
|
|
18
18
|
> =
|
|
@@ -21,8 +21,8 @@ type RootOptions<
|
|
|
21
21
|
& SubComponentsOption<TSubComponentTuple>;
|
|
22
22
|
|
|
23
23
|
type DefineComponentConstructor = <
|
|
24
|
-
TRootComponentDoc extends
|
|
25
|
-
TSubComponentTuple extends
|
|
24
|
+
TRootComponentDoc extends RootComponentType = {},
|
|
25
|
+
TSubComponentTuple extends SubComponentType[] = [],
|
|
26
26
|
TName extends string = "",
|
|
27
27
|
TPath extends Path = "/",
|
|
28
28
|
>(
|
|
@@ -41,7 +41,7 @@ export type DefineComponentOption = {
|
|
|
41
41
|
name?: string;
|
|
42
42
|
path?: string;
|
|
43
43
|
rootComponent?: RootComponentTrueOptions;
|
|
44
|
-
subComponents?:
|
|
44
|
+
subComponents?: SubComponentType[];
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { deepEqual } from "../../../../utils/deepEqual";
|
|
1
2
|
import type { Instance } from "../../../RootComponent/Instance/RootComponentInstance";
|
|
2
3
|
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
3
4
|
import { removeSubDependences } from "./dependencesOptimize";
|
|
4
5
|
import { getPathsValue } from "./getPathsValue";
|
|
5
6
|
|
|
6
|
-
import { isEqual } from "./isEqual";
|
|
7
7
|
export type ComputedDependence = { paths: string[]; val: unknown };
|
|
8
8
|
|
|
9
9
|
export function computedUpdater(this: Instance, isUpdated = false): boolean {
|
|
@@ -15,7 +15,7 @@ export function computedUpdater(this: Instance, isUpdated = false): boolean {
|
|
|
15
15
|
const curVal = getPathsValue(this.data, dep.paths.join("."))[0];
|
|
16
16
|
|
|
17
17
|
// 检查依赖是否更新
|
|
18
|
-
if (!
|
|
18
|
+
if (!deepEqual(curVal, dep.val)) {
|
|
19
19
|
changed = true;
|
|
20
20
|
|
|
21
21
|
break;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
2
|
+
import { deepEqual } from "../../../../utils/deepEqual";
|
|
2
3
|
import { computedUpdater } from "./computedUpdater";
|
|
3
4
|
import { getPathsValue } from "./getPathsValue";
|
|
4
5
|
import { getPropertiesValue } from "./getPropertiesValue";
|
|
5
6
|
import { initComputedAndGetCache } from "./initComputedAndGetCache";
|
|
6
|
-
import { isEqual } from "./isEqual";
|
|
7
7
|
|
|
8
8
|
import { assertNonNullable } from "../../../../utils/assertNonNullable";
|
|
9
9
|
import { deepClone } from "../../../../utils/deepClone";
|
|
@@ -71,7 +71,7 @@ export function computedWatchHandle(options: FinalOptionsOfComponent) {
|
|
|
71
71
|
const watchOldValue = assertNonNullable(this.data.__watchOldValue__);
|
|
72
72
|
const oldValue = watchOldValue[key];
|
|
73
73
|
|
|
74
|
-
if (
|
|
74
|
+
if (deepEqual(newValue, oldValue)) return;
|
|
75
75
|
watchOldValue[key] = deepClone(newValue);
|
|
76
76
|
|
|
77
77
|
watchHadle.call(this, ...newValue, ...oldValue);
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { Func } from "hry-types/src/Misc/_api";
|
|
2
|
-
import { instanceConfig } from "../../..";
|
|
3
2
|
import { BBeforeCreate } from "../../../behaviors/BbeforeCreated";
|
|
4
3
|
import { BStore } from "../../../behaviors/BStore";
|
|
5
4
|
import { isEmptyObject } from "../../../utils/isEmptyObject";
|
|
5
|
+
import { instanceConfig } from "../../InstanceInject/instanceConfig";
|
|
6
6
|
import type { ComputedConstraint } from "../../RootComponent/Computed/ComputedConstraint";
|
|
7
7
|
import type { DataConstraint } from "../../RootComponent/Data/DataConstraint";
|
|
8
8
|
import type { LifetimesConstraint } from "../../RootComponent/Lifetimes/LifetimesConstraint";
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
3
3
|
import { Checking, type Test } from "hry-types";
|
|
4
4
|
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
5
|
+
import type { User } from "../../../../../jest/common";
|
|
6
|
+
import type { DetailedType } from "../../../../types/DetailedType";
|
|
5
7
|
import type { IInjectAllData } from "../../../InstanceInject/instanceConfig";
|
|
6
8
|
import { RootComponent } from "../..";
|
|
7
9
|
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
@@ -94,3 +96,21 @@ const EmptyComputedFieldDoc = RootComponent()({
|
|
|
94
96
|
});
|
|
95
97
|
|
|
96
98
|
Checking<typeof EmptyComputedFieldDoc, { methods: { M1: () => void } }, Test.Pass>;
|
|
99
|
+
RootComponent()({
|
|
100
|
+
isPage: true,
|
|
101
|
+
properties: {
|
|
102
|
+
optionalObj: {
|
|
103
|
+
type: Object,
|
|
104
|
+
value: {},
|
|
105
|
+
},
|
|
106
|
+
requiredObj: Object as DetailedType<User>,
|
|
107
|
+
},
|
|
108
|
+
|
|
109
|
+
pageLifetimes: {
|
|
110
|
+
onLoad(prop) {
|
|
111
|
+
Checking<typeof prop.optionalObj, object | undefined, true>;
|
|
112
|
+
Checking<typeof prop.requiredObj, User, true>;
|
|
113
|
+
Checking<typeof this.data.optionalObj, object, true>;
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
});
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { IfExtends } from "hry-types/src/Any/_api";
|
|
3
3
|
import type { Select } from "hry-types/src/Object/_api";
|
|
4
4
|
import type { Detail, WMBaseEvent } from "../../../types/OfficialTypeAlias";
|
|
5
|
-
import type {
|
|
5
|
+
import type { ComponentType } from "../../DefineComponent/ReturnType/ComponentType";
|
|
6
6
|
import type { CustomEventsDoc } from "../CustomEvents/CustomEventsDoc";
|
|
7
7
|
import type {
|
|
8
8
|
Bubbles,
|
|
@@ -18,9 +18,9 @@ type FilterNormalFields<O extends object> = Select<O, Bubbles | Capture, "contai
|
|
|
18
18
|
|
|
19
19
|
// 获取冒泡或捕获的事件
|
|
20
20
|
type GetBubblesOrCaptureEventsFromCompDoc<
|
|
21
|
-
ComponentDocList extends
|
|
21
|
+
ComponentDocList extends ComponentType[],
|
|
22
22
|
Result extends CustomEventsDoc = {},
|
|
23
|
-
> = ComponentDocList extends [infer Head extends
|
|
23
|
+
> = ComponentDocList extends [infer Head extends ComponentType, ...infer Rest extends ComponentType[]]
|
|
24
24
|
? GetBubblesOrCaptureEventsFromCompDoc<
|
|
25
25
|
Rest,
|
|
26
26
|
Result & (FilterNormalFields<Head["customEvents"] & {}>)
|
|
@@ -50,7 +50,7 @@ type TransformCustomEventsDocTypeToFunctionTypeAndAddSuffix<T extends CustomEven
|
|
|
50
50
|
|
|
51
51
|
// 所有子组件自定义事件(过滤掉非冒泡或捕获)的key加入后缀并把值(detail)转换为函数类型
|
|
52
52
|
type GetAllSubCustomEventsConstraint<
|
|
53
|
-
ComponentDocList extends
|
|
53
|
+
ComponentDocList extends ComponentType[],
|
|
54
54
|
AllCustomEvents extends CustomEventsDoc = GetBubblesOrCaptureEventsFromCompDoc<ComponentDocList>,
|
|
55
55
|
> = IfExtends<
|
|
56
56
|
{},
|
|
@@ -66,7 +66,7 @@ type BaseEvent = Record<string, (e: WMBaseEvent) => unknown>;
|
|
|
66
66
|
/**
|
|
67
67
|
* events字段约束 由自身事件和冒泡的子组件事件组成。带前缀是子组件事件,带后缀(_catch)表示阻止冒泡
|
|
68
68
|
*/
|
|
69
|
-
export type EventsConstraint<ComponentDocList extends
|
|
69
|
+
export type EventsConstraint<ComponentDocList extends ComponentType[] = []> = IfExtends<
|
|
70
70
|
[],
|
|
71
71
|
ComponentDocList,
|
|
72
72
|
BaseEvent,
|
|
@@ -11,7 +11,7 @@ import type {
|
|
|
11
11
|
WMCustomEvent,
|
|
12
12
|
} from "../../../../types/OfficialTypeAlias";
|
|
13
13
|
import { assertNonNullable } from "../../../../utils/assertNonNullable";
|
|
14
|
-
import type {
|
|
14
|
+
import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
|
|
15
15
|
import { RootComponent } from "../..";
|
|
16
16
|
import type { Bubbles, Capture } from "../../CustomEvents/CustomEventsTag";
|
|
17
17
|
|
|
@@ -34,13 +34,13 @@ RootComponent()({
|
|
|
34
34
|
// 2.1 通过WMCustomEvent定义detai,mark,CurrentTargetDataset,targetDataset数据类型
|
|
35
35
|
customA(
|
|
36
36
|
e: WMCustomEvent<
|
|
37
|
-
|
|
37
|
+
string,
|
|
38
38
|
{ markData: { id: string } },
|
|
39
39
|
{ currentTargetDatasetData: string },
|
|
40
40
|
{ targetDatasetData: number }
|
|
41
41
|
>,
|
|
42
42
|
) {
|
|
43
|
-
Checking<typeof e.detail
|
|
43
|
+
Checking<typeof e.detail, string, Test.Pass>;
|
|
44
44
|
|
|
45
45
|
const markData = assertNonNullable(e.mark).markData;
|
|
46
46
|
|
|
@@ -71,7 +71,7 @@ RootComponent()({
|
|
|
71
71
|
},
|
|
72
72
|
});
|
|
73
73
|
|
|
74
|
-
type ComponentDocA =
|
|
74
|
+
type ComponentDocA = ComponentType<{
|
|
75
75
|
properties: {
|
|
76
76
|
aaa_str: string;
|
|
77
77
|
};
|
|
@@ -81,7 +81,7 @@ type ComponentDocA = ComponentDoc<{
|
|
|
81
81
|
};
|
|
82
82
|
}>;
|
|
83
83
|
|
|
84
|
-
type ComponentDocB =
|
|
84
|
+
type ComponentDocB = ComponentType<{
|
|
85
85
|
customEvents: {
|
|
86
86
|
bbb_str: string;
|
|
87
87
|
bbb_num: number | Capture;
|
|
@@ -49,11 +49,9 @@ RootComponent()({
|
|
|
49
49
|
};
|
|
50
50
|
obj: object;
|
|
51
51
|
}, Test.Pass>;
|
|
52
|
-
|
|
53
|
-
// 页面实例对象不额外添加null
|
|
52
|
+
// 页面可选对象不额外添加null
|
|
54
53
|
Checking<typeof this.data.optionalObj, { name: string }, Test.Pass>;
|
|
55
|
-
|
|
56
|
-
// 页面实例对象不额外添加null
|
|
54
|
+
// 页面必传对象没有null
|
|
57
55
|
Checking<typeof this.data.obj, object, Test.Pass>;
|
|
58
56
|
},
|
|
59
57
|
},
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
|
+
import type { ComputeObject } from "../../../types/ComputeObj";
|
|
3
4
|
import type { WMCompPageLifetimes, WMPageLifetimes } from "../../../types/OfficialTypeAlias";
|
|
5
|
+
import type { RemoveNullOfRequired } from "../../../types/RemoveNullOfRequired";
|
|
4
6
|
|
|
5
7
|
export type PageLifetimesOption<TIsPage extends boolean, PropertiesDoc extends object> = IfExtends<
|
|
6
8
|
TIsPage,
|
|
@@ -31,7 +33,8 @@ export type PageLifetimesOption<TIsPage extends boolean, PropertiesDoc extends o
|
|
|
31
33
|
* 页面加载时触发。一个页面只会调用一次,可以在 onLoad 的参数中获取Properties定义的数据。
|
|
32
34
|
*/
|
|
33
35
|
onLoad?: (
|
|
34
|
-
|
|
36
|
+
// 默认PropertiesDoc
|
|
37
|
+
props: ComputeObject<RemoveNullOfRequired<PropertiesDoc>>,
|
|
35
38
|
) => void | Promise<void>;
|
|
36
39
|
}
|
|
37
40
|
>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import { type DetailedType, RootComponent } from "../../../..";
|
|
3
3
|
|
|
4
|
+
import type { User } from "../../../../../jest/common";
|
|
4
5
|
import type { Mock_User } from "../../Properties/test/normalRequired.test";
|
|
5
6
|
|
|
6
7
|
/**
|
|
@@ -74,3 +75,28 @@ RootComponent()({
|
|
|
74
75
|
// ...
|
|
75
76
|
},
|
|
76
77
|
});
|
|
78
|
+
// prop中必传对象没有null,但在实例中却需要有null
|
|
79
|
+
RootComponent()({
|
|
80
|
+
isPage: true,
|
|
81
|
+
properties: {
|
|
82
|
+
optionalObj: {
|
|
83
|
+
type: Object,
|
|
84
|
+
value: {},
|
|
85
|
+
},
|
|
86
|
+
requiredObj: Object as DetailedType<User>,
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
pageLifetimes: {
|
|
90
|
+
onLoad(prop) {
|
|
91
|
+
void prop;
|
|
92
|
+
// 页面外部传值时没必要传null,组件时有需要的。
|
|
93
|
+
void Checking<typeof prop.requiredObj, User, true>;
|
|
94
|
+
// 虽然传值不应该是null,但由于实例建立时默认为null,所以实例类型加上null
|
|
95
|
+
void Checking<typeof this.data.requiredObj, User, true>;
|
|
96
|
+
// 页面传入的可选对象不需要null,有undefined
|
|
97
|
+
void Checking<typeof prop.optionalObj, object | undefined, true>;
|
|
98
|
+
// 实例中的可选对象不需要null,有默认值。
|
|
99
|
+
void Checking<typeof this.data.optionalObj, object, true>;
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
});
|
|
@@ -16,20 +16,20 @@ export type GetOptionalDoc<
|
|
|
16
16
|
IfExtends<
|
|
17
17
|
false,
|
|
18
18
|
TIsPage,
|
|
19
|
-
// 组件时 对象加null
|
|
19
|
+
// 组件时 对象加null 只所以加是为了异步组件传值时,方便传初始值null,这导致实例中可选对象类型包含null
|
|
20
20
|
AddNullForObject<InferDetailedType<TOptionalProperties[k]["type"]>>,
|
|
21
|
-
// 页面时
|
|
21
|
+
// 页面时 对象不加, 因为页面不存在异步传值。
|
|
22
22
|
InferDetailedType<TOptionalProperties[k]["type"]>
|
|
23
23
|
>,
|
|
24
24
|
IfExtends<
|
|
25
25
|
false,
|
|
26
26
|
TIsPage,
|
|
27
|
-
// 组件时 对象加null
|
|
27
|
+
// 组件时 对象加null 同上
|
|
28
28
|
AddNullForObject<
|
|
29
29
|
| InferDetailedType<TOptionalProperties[k]["type"]>
|
|
30
30
|
| InferDetailedType<(TOptionalProperties[k]["optionalTypes"] & {})[number]>
|
|
31
31
|
>,
|
|
32
|
-
// 页面时 对象不加
|
|
32
|
+
// 页面时 对象不加 同上
|
|
33
33
|
| InferDetailedType<TOptionalProperties[k]["type"]>
|
|
34
34
|
| InferDetailedType<(TOptionalProperties[k]["optionalTypes"] & {})[number]>
|
|
35
35
|
>
|
|
@@ -11,11 +11,12 @@ type _GetPropertiesDoc<
|
|
|
11
11
|
// @ts-ignore
|
|
12
12
|
OptionalDoc extends object = GetOptionalDoc<Select<TProperties, OptionalType>, TIsPage>,
|
|
13
13
|
// @ts-ignore
|
|
14
|
-
RequiredDoc extends object = GetRequiredDoc<Omit<TProperties, keyof OptionalDoc
|
|
14
|
+
RequiredDoc extends object = GetRequiredDoc<Omit<TProperties, keyof OptionalDoc>>,
|
|
15
15
|
> = ComputeIntersection<OptionalDoc & RequiredDoc>;
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* properties字段的文档类型
|
|
19
|
+
* @remarks 必传的字段如果是object,要联合上null类型,选传的object根据是否是页面来决定是否加null
|
|
19
20
|
*/
|
|
20
21
|
export type GetPropertiesDoc<
|
|
21
22
|
TProperties extends PropertiesConstraint,
|
|
@@ -9,34 +9,20 @@ import type { RequiredSingle, RequiredType } from "./PropertiesConstraint";
|
|
|
9
9
|
*/
|
|
10
10
|
export type GetRequiredDoc<
|
|
11
11
|
TProperties extends Record<string, RequiredType>,
|
|
12
|
-
|
|
13
|
-
|
|
12
|
+
> // TIsPage extends boolean,
|
|
13
|
+
= {
|
|
14
14
|
-readonly [k in keyof TProperties]: IfExtends<
|
|
15
15
|
TProperties[k],
|
|
16
16
|
// 非对象写法
|
|
17
17
|
RequiredSingle,
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
AddNullForObject<InferDetailedType<TProperties[k]>>,
|
|
23
|
-
// 页面的对象类型不加null
|
|
24
|
-
InferDetailedType<TProperties[k]>
|
|
25
|
-
>,
|
|
26
|
-
// 对象写法 RequiredUnion
|
|
27
|
-
IfExtends<
|
|
28
|
-
false,
|
|
29
|
-
TIsPage,
|
|
30
|
-
// 组件的对象类型加null
|
|
31
|
-
AddNullForObject<
|
|
32
|
-
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
33
|
-
| InferDetailedType<TProperties[k]["type"]>
|
|
34
|
-
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
35
|
-
| InferDetailedType<TProperties[k]["optionalTypes"][number]>
|
|
36
|
-
>,
|
|
37
|
-
// 页面的对象类型不加null
|
|
18
|
+
// 组件的对象类型加null
|
|
19
|
+
AddNullForObject<InferDetailedType<TProperties[k]>>,
|
|
20
|
+
// 组件的对象类型加null
|
|
21
|
+
AddNullForObject<
|
|
38
22
|
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
39
|
-
|
|
23
|
+
| InferDetailedType<TProperties[k]["type"]>
|
|
24
|
+
// @ts-ignore TProperties[k] 必为 RequiredUnion
|
|
25
|
+
| InferDetailedType<TProperties[k]["optionalTypes"][number]>
|
|
40
26
|
>
|
|
41
27
|
>;
|
|
42
28
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { WMCompPageLifetimes, WMPageLifetimes } from "../../types/OfficialTypeAlias";
|
|
2
2
|
import type { LifetimesConstraint } from "./Lifetimes/LifetimesConstraint";
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type _RootComponentType = {
|
|
5
5
|
isPage?: boolean;
|
|
6
6
|
properties?: object;
|
|
7
7
|
data?: object;
|
|
@@ -24,20 +24,21 @@ type _Validator<O, Doc, ErrKeys = Exclude<keyof O, keyof Doc>> = [ErrKeys] exten
|
|
|
24
24
|
/**
|
|
25
25
|
* RootComponent Api 返回的类型
|
|
26
26
|
* ```ts
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
27
|
+
* {
|
|
28
|
+
* isPage?: boolean;
|
|
29
|
+
* properties?: object;
|
|
30
|
+
* data?: object;
|
|
31
|
+
* computed?: object;
|
|
32
|
+
* customEvents?: object;
|
|
33
|
+
* methods?: object;
|
|
34
|
+
* events?: object;
|
|
35
|
+
* store?: object;
|
|
36
|
+
* watch?: Record<string, AnyFunction>;
|
|
37
|
+
* lifetimes?: LifetimesConstraint;
|
|
38
|
+
* pageLifetimes?: Partial<WMCompPageLifetimes & { load:AnyFunction }> | Partial<WMPageLifetimes>;
|
|
39
|
+
* export?:AnyFunction
|
|
40
|
+
* externalClasses?: string[];
|
|
40
41
|
* };
|
|
41
42
|
* ```
|
|
42
43
|
*/
|
|
43
|
-
export type
|
|
44
|
+
export type RootComponentType<O extends _Validator<O, _RootComponentType> = _RootComponentType> = O;
|
|
@@ -4,7 +4,8 @@ import type { Func } from "hry-types/src/Misc/Func";
|
|
|
4
4
|
import type { ComputeIntersection } from "hry-types/src/Object/_api";
|
|
5
5
|
import type { ComputeObject } from "../../types/ComputeObj";
|
|
6
6
|
import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
|
|
7
|
-
import type {
|
|
7
|
+
import type { RemoveNullOfRequired } from "../../types/RemoveNullOfRequired";
|
|
8
|
+
import type { ComponentType } from "../DefineComponent/ReturnType/ComponentType";
|
|
8
9
|
import type { IInjectAllData, IInjectStore } from "../InstanceInject/instanceConfig";
|
|
9
10
|
import type { ComputedConstraint } from "./Computed/ComputedConstraint";
|
|
10
11
|
import type { ComputedOption } from "./Computed/ComputedOption";
|
|
@@ -88,7 +89,7 @@ type RootComponentOptions<
|
|
|
88
89
|
>
|
|
89
90
|
>;
|
|
90
91
|
|
|
91
|
-
type RootComponentConstructor<TComponentDocList extends
|
|
92
|
+
type RootComponentConstructor<TComponentDocList extends ComponentType[]> = <
|
|
92
93
|
// TEvents 不能有默认值 {} 会引起事件参数类型(e)失效
|
|
93
94
|
TEvents extends EventsConstraint<TComponentDocList>,
|
|
94
95
|
TIsPage extends boolean = false,
|
|
@@ -126,7 +127,12 @@ type RootComponentConstructor<TComponentDocList extends ComponentDoc[]> = <
|
|
|
126
127
|
) => // 返回类型 satisfies RootComponentDoc
|
|
127
128
|
ComputeIntersection<
|
|
128
129
|
& IfExtends<TIsPage, false, {}, { isPage: true }>
|
|
129
|
-
& IfExtends<
|
|
130
|
+
& IfExtends<
|
|
131
|
+
EmptyObject,
|
|
132
|
+
PropertiesDoc,
|
|
133
|
+
{},
|
|
134
|
+
{ properties: IfExtends<false, TIsPage, PropertiesDoc, RemoveNullOfRequired<PropertiesDoc>> }
|
|
135
|
+
>
|
|
130
136
|
& IfExtends<EmptyObject, DataDoc, {}, { data: DataDoc }>
|
|
131
137
|
& IfExtends<EmptyObject, StoreDoc, {}, { store: ComputeObject<StoreDoc> }>
|
|
132
138
|
& IfExtends<EmptyObject, ComputedDoc, {}, { computed: ComputedDoc }>
|
|
@@ -137,7 +143,7 @@ ComputeIntersection<
|
|
|
137
143
|
|
|
138
144
|
export function RootComponent<
|
|
139
145
|
// TComponentDocList泛型为了给events字段提供类型约束
|
|
140
|
-
TComponentDocList extends
|
|
146
|
+
TComponentDocList extends ComponentType[] = [],
|
|
141
147
|
>(): RootComponentConstructor<
|
|
142
148
|
TComponentDocList
|
|
143
149
|
> {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { SelectKeys } from "hry-types/src/Object/_api";
|
|
2
2
|
import type { Composed, CustomEventsTags } from "../RootComponent/CustomEvents/CustomEventsTag";
|
|
3
3
|
|
|
4
|
-
type
|
|
4
|
+
type _SubComponentType = {
|
|
5
5
|
[k in string]:
|
|
6
6
|
| string
|
|
7
7
|
| number
|
|
@@ -15,7 +15,7 @@ type _SubComponentDoc = {
|
|
|
15
15
|
};
|
|
16
16
|
|
|
17
17
|
type _Validator<O, ErrKeys = Exclude<keyof O, SelectKeys<O, Composed, "contains->">>> = [ErrKeys] extends [never]
|
|
18
|
-
?
|
|
18
|
+
? _SubComponentType
|
|
19
19
|
: `${ErrKeys & string} 不是穿透事件`;
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -27,4 +27,4 @@ type _Validator<O, ErrKeys = Exclude<keyof O, SelectKeys<O, Composed, "contains-
|
|
|
27
27
|
* };
|
|
28
28
|
* ```
|
|
29
29
|
*/
|
|
30
|
-
export type
|
|
30
|
+
export type SubComponentType<O extends _Validator<O> = _SubComponentType> = O;
|
|
@@ -2,8 +2,10 @@ import type { G } from "hry-types";
|
|
|
2
2
|
export type SubComputedOption<
|
|
3
3
|
TComputed extends object,
|
|
4
4
|
legal extends PropertyKey,
|
|
5
|
+
Instance extends object,
|
|
5
6
|
> = {
|
|
6
7
|
computed?:
|
|
7
8
|
& TComputed
|
|
9
|
+
& ThisType<Instance>
|
|
8
10
|
& G.IllegalFieldValidator<TComputed, legal, 0, "", "重复或无效的字段">;
|
|
9
11
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
|
|
2
2
|
import { SubComponent } from "../..";
|
|
3
3
|
|
|
4
|
-
type OnlyCustomCompDoc =
|
|
4
|
+
type OnlyCustomCompDoc = ComponentType<{
|
|
5
5
|
customEvents: { aaa_str: string };
|
|
6
6
|
}>;
|
|
7
7
|
|
|
@@ -15,7 +15,7 @@ SubComponent<{}, OnlyCustomCompDoc>()({
|
|
|
15
15
|
},
|
|
16
16
|
});
|
|
17
17
|
|
|
18
|
-
type OnlyPropsCompDoc =
|
|
18
|
+
type OnlyPropsCompDoc = ComponentType<{
|
|
19
19
|
properties: {
|
|
20
20
|
aaa_str: "a" | "b";
|
|
21
21
|
aaa_num?: number;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
|
|
3
3
|
|
|
4
4
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
5
5
|
import type { IInjectAllData } from "../../../InstanceInject/instanceConfig";
|
|
6
6
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
7
7
|
import { SubComponent } from "../..";
|
|
8
8
|
|
|
9
|
-
type OnlyCustomCompDoc =
|
|
9
|
+
type OnlyCustomCompDoc = ComponentType<{
|
|
10
10
|
customEvents: { aaa_str: string };
|
|
11
11
|
}>;
|
|
12
12
|
|
|
@@ -31,7 +31,7 @@ interface Root {
|
|
|
31
31
|
};
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
type $aaa =
|
|
34
|
+
type $aaa = ComponentType<
|
|
35
35
|
{ properties: { aaa_str: string; aaa_user: User | null; aaa_num: number; aaa_age: number } }
|
|
36
36
|
>;
|
|
37
37
|
|
|
@@ -40,7 +40,7 @@ SubComponent<{}, OnlyCustomCompDoc>()({
|
|
|
40
40
|
computed: {},
|
|
41
41
|
});
|
|
42
42
|
|
|
43
|
-
type OnlyPropsCompDoc =
|
|
43
|
+
type OnlyPropsCompDoc = ComponentType<{
|
|
44
44
|
properties: {
|
|
45
45
|
aaa_str: "a" | "b";
|
|
46
46
|
aaa_num?: number;
|
|
@@ -75,7 +75,7 @@ SubComponent<Root, OnlyPropsCompDoc>()({
|
|
|
75
75
|
aaa_num123(): 123 {
|
|
76
76
|
return 123;
|
|
77
77
|
},
|
|
78
|
-
aaa_str()
|
|
78
|
+
aaa_str() {
|
|
79
79
|
return "a";
|
|
80
80
|
},
|
|
81
81
|
aaa_obj() {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
|
|
2
2
|
|
|
3
3
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
4
4
|
import { SubComponent } from "../..";
|
|
5
5
|
|
|
6
|
-
type OnlyCustomCompDoc =
|
|
6
|
+
type OnlyCustomCompDoc = ComponentType<{
|
|
7
7
|
customEvents: { aaa_str: string };
|
|
8
8
|
}>;
|
|
9
9
|
|
|
@@ -16,7 +16,7 @@ SubComponent<{}, OnlyCustomCompDoc>()({
|
|
|
16
16
|
},
|
|
17
17
|
});
|
|
18
18
|
|
|
19
|
-
type OnlyPropsCompDoc =
|
|
19
|
+
type OnlyPropsCompDoc = ComponentType<{
|
|
20
20
|
properties: {
|
|
21
21
|
aaa_str: "a" | "b";
|
|
22
22
|
aaa_num?: number;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
|
|
3
3
|
|
|
4
4
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
5
5
|
import type { IInjectAllData } from "../../../InstanceInject/instanceConfig";
|
|
6
6
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
7
7
|
import { SubComponent } from "../..";
|
|
8
8
|
|
|
9
|
-
type CompDoc =
|
|
9
|
+
type CompDoc = ComponentType<{
|
|
10
10
|
properties: {
|
|
11
11
|
aaa_str: "a" | "b";
|
|
12
12
|
aaa_num?: number;
|