annil 1.0.0 → 1.0.4

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.
Files changed (137) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +38 -2
  3. package/dist/api/DefineComponent/ReturnType/test/normalComponentDoc.test.js.map +1 -1
  4. package/dist/api/DefineComponent/ReturnType/test/normalPageDoc.test.js.map +1 -1
  5. package/dist/api/DefineComponent/collectOptionsForComponent.d.ts +4 -0
  6. package/dist/api/DefineComponent/collectOptionsForComponent.js +152 -0
  7. package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -0
  8. package/dist/api/DefineComponent/index.d.ts +4 -28
  9. package/dist/api/DefineComponent/index.js +2 -32
  10. package/dist/api/DefineComponent/index.js.map +1 -1
  11. package/dist/api/RootComponent/CustomEvents/CustomEventConstraint.d.ts +2 -1
  12. package/dist/api/RootComponent/Data/DataConstraint.d.ts +1 -0
  13. package/dist/api/RootComponent/Data/DataConstraint.js +2 -0
  14. package/dist/api/RootComponent/Data/DataConstraint.js.map +1 -0
  15. package/dist/api/RootComponent/Lifetimes/LifetimesConstraint.d.ts +4 -1
  16. package/dist/api/RootComponent/Lifetimes/test/error.test.js +1 -0
  17. package/dist/api/RootComponent/Lifetimes/test/error.test.js.map +1 -1
  18. package/dist/api/RootComponent/Lifetimes/test/normal.test.js +3 -0
  19. package/dist/api/RootComponent/Lifetimes/test/normal.test.js.map +1 -1
  20. package/dist/api/RootComponent/Properties/{expected/normalEmpty.js → test/normalEmpty.test.js} +1 -1
  21. package/dist/api/RootComponent/Properties/test/normalEmpty.test.js.map +1 -0
  22. package/dist/api/RootComponent/Properties/test/normalOptional.test.js +15 -0
  23. package/dist/api/RootComponent/Properties/test/normalOptional.test.js.map +1 -1
  24. package/dist/api/RootComponent/Watch/test/WatchProperties.test.js +1 -1
  25. package/dist/api/RootComponent/Watch/test/WatchProperties.test.js.map +1 -1
  26. package/dist/api/RootComponent/index.d.ts +19 -2
  27. package/dist/api/RootComponent/index.js +1 -1
  28. package/dist/api/RootComponent/index.js.map +1 -1
  29. package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
  30. package/dist/api/SubComponent/SubData/test/error.test.js.map +1 -1
  31. package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
  32. package/dist/api/SubComponent/SubInstance/test/normal.test.js.map +1 -1
  33. package/dist/api/SubComponent/SubPageLifetimes/test/normal.test.js.map +1 -1
  34. package/dist/api/SubComponent/SubWatch/test/WatchRootData.test.js.map +1 -1
  35. package/dist/api/SubComponent/index.d.ts +2 -2
  36. package/dist/api/SubComponent/index.js.map +1 -1
  37. package/dist/{utils → behaviors/BComputedAndWatch}/computedUpdater.d.ts +1 -1
  38. package/dist/{utils → behaviors/BComputedAndWatch}/computedUpdater.js +2 -2
  39. package/dist/behaviors/BComputedAndWatch/computedUpdater.js.map +1 -0
  40. package/dist/behaviors/BComputedAndWatch/data-tracer.js +0 -3
  41. package/dist/behaviors/BComputedAndWatch/data-tracer.js.map +1 -1
  42. package/dist/{utils → behaviors/BComputedAndWatch}/getPathsValue.d.ts +1 -1
  43. package/dist/behaviors/BComputedAndWatch/getPathsValue.js.map +1 -0
  44. package/dist/behaviors/BComputedAndWatch/index.js +10 -2
  45. package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
  46. package/dist/behaviors/BComputedAndWatch/initComputed.js +4 -12
  47. package/dist/behaviors/BComputedAndWatch/initComputed.js.map +1 -1
  48. package/dist/behaviors/BComputedAndWatch/isEqual.js.map +1 -1
  49. package/dist/behaviors/BStore.js.map +1 -1
  50. package/dist/behaviors/BbeforeCreated.js +1 -2
  51. package/dist/behaviors/BbeforeCreated.js.map +1 -1
  52. package/dist/types/GetComponentPrefix.js +1 -4
  53. package/dist/types/GetComponentPrefix.js.map +1 -1
  54. package/dist/types/OfficialTypeAlias.d.ts +2 -2
  55. package/dist/types/ReplacePrefix.js +1 -4
  56. package/dist/types/ReplacePrefix.js.map +1 -1
  57. package/package.json +5 -4
  58. package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +2 -1
  59. package/src/api/DefineComponent/ReturnType/test/normalPageDoc.test.ts +2 -1
  60. package/src/api/DefineComponent/collectOptionsForComponent.ts +290 -0
  61. package/src/api/DefineComponent/index.ts +13 -81
  62. package/src/api/RootComponent/Computed/test/normal.test.ts +1 -1
  63. package/src/api/RootComponent/CustomEvents/CustomEventConstraint.ts +3 -1
  64. package/src/api/RootComponent/Data/DataConstraint.ts +1 -0
  65. package/src/api/RootComponent/IsPage/IsPageOption.ts +6 -1
  66. package/src/api/RootComponent/Lifetimes/LifetimesConstraint.ts +8 -7
  67. package/src/api/RootComponent/Lifetimes/test/error.test.ts +1 -1
  68. package/src/api/RootComponent/Lifetimes/test/normal.test.ts +3 -3
  69. package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +1 -1
  70. package/src/api/RootComponent/Properties/test/normalOptional.test.ts +20 -0
  71. package/src/api/RootComponent/Watch/test/WatchComputed.test.ts +1 -1
  72. package/src/api/RootComponent/Watch/test/WatchData.test.ts +1 -1
  73. package/src/api/RootComponent/Watch/test/WatchProperties.test.ts +8 -2
  74. package/src/api/RootComponent/index.ts +19 -3
  75. package/src/api/SubComponent/SubComputed/test/normal.test.ts +2 -1
  76. package/src/api/SubComponent/SubData/test/error.test.ts +2 -1
  77. package/src/api/SubComponent/SubData/test/normal.test.ts +2 -1
  78. package/src/api/SubComponent/SubInstance/test/normal.test.ts +2 -1
  79. package/src/api/SubComponent/SubPageLifetimes/test/normal.test.ts +2 -1
  80. package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +2 -1
  81. package/src/api/SubComponent/SubWatch/test/error.test.ts +1 -1
  82. package/src/api/SubComponent/index.ts +11 -4
  83. package/src/{utils → behaviors/BComputedAndWatch}/computedUpdater.ts +5 -4
  84. package/src/behaviors/BComputedAndWatch/data-tracer.ts +0 -3
  85. package/src/{utils → behaviors/BComputedAndWatch}/getPathsValue.ts +1 -1
  86. package/src/behaviors/BComputedAndWatch/index.ts +21 -8
  87. package/src/behaviors/BComputedAndWatch/initComputed.ts +26 -19
  88. package/src/behaviors/BComputedAndWatch/isEqual.ts +1 -0
  89. package/src/behaviors/BStore.ts +5 -3
  90. package/src/behaviors/BbeforeCreated.ts +4 -2
  91. package/src/types/GetComponentPrefix.ts +11 -11
  92. package/src/types/OfficialTypeAlias.ts +2 -2
  93. package/src/types/ReplacePrefix.ts +9 -10
  94. package/src/types/SpecificType.ts +0 -4
  95. package/tsconfig.json +6 -15
  96. package/dist/api/RootComponent/Data/expected/error.js +0 -10
  97. package/dist/api/RootComponent/Data/expected/error.js.map +0 -1
  98. package/dist/api/RootComponent/Data/expected/normal.d.ts +0 -1
  99. package/dist/api/RootComponent/Data/expected/normal.js +0 -33
  100. package/dist/api/RootComponent/Data/expected/normal.js.map +0 -1
  101. package/dist/api/RootComponent/Properties/expected/error.d.ts +0 -1
  102. package/dist/api/RootComponent/Properties/expected/error.js +0 -38
  103. package/dist/api/RootComponent/Properties/expected/error.js.map +0 -1
  104. package/dist/api/RootComponent/Properties/expected/normalEmpty.d.ts +0 -1
  105. package/dist/api/RootComponent/Properties/expected/normalEmpty.js.map +0 -1
  106. package/dist/api/RootComponent/Properties/expected/normalOptional.d.ts +0 -1
  107. package/dist/api/RootComponent/Properties/expected/normalOptional.js +0 -80
  108. package/dist/api/RootComponent/Properties/expected/normalOptional.js.map +0 -1
  109. package/dist/api/RootComponent/Properties/expected/normalRequired.d.ts +0 -69
  110. package/dist/api/RootComponent/Properties/expected/normalRequired.js +0 -44
  111. package/dist/api/RootComponent/Properties/expected/normalRequired.js.map +0 -1
  112. package/dist/api/RootComponent/Properties/test/normalEmpty.test..d.ts +0 -1
  113. package/dist/api/RootComponent/Properties/test/normalEmpty.test..js +0 -20
  114. package/dist/api/RootComponent/Properties/test/normalEmpty.test..js.map +0 -1
  115. package/dist/types/RestorePropTypeOfList.d.ts +0 -2
  116. package/dist/types/RestorePropTypeOfList.js +0 -3
  117. package/dist/types/RestorePropTypeOfList.js.map +0 -1
  118. package/dist/utils/computedUpdater.js.map +0 -1
  119. package/dist/utils/getPathsValue.js.map +0 -1
  120. package/dist/utils/initWatchOldValue.d.ts +0 -2
  121. package/dist/utils/initWatchOldValue.js +0 -10
  122. package/dist/utils/initWatchOldValue.js.map +0 -1
  123. package/dist/utils/preprocessingOptions.d.ts +0 -18
  124. package/dist/utils/preprocessingOptions.js +0 -184
  125. package/dist/utils/preprocessingOptions.js.map +0 -1
  126. package/src/api/RootComponent/Data/expected/error.ts +0 -14
  127. package/src/api/RootComponent/Data/expected/normal.ts +0 -68
  128. package/src/api/RootComponent/Properties/expected/error.ts +0 -49
  129. package/src/api/RootComponent/Properties/expected/normalEmpty.ts +0 -33
  130. package/src/api/RootComponent/Properties/expected/normalOptional.ts +0 -136
  131. package/src/api/RootComponent/Properties/expected/normalRequired.ts +0 -100
  132. package/src/types/RestorePropTypeOfList.ts +0 -20
  133. package/src/utils/initWatchOldValue.ts +0 -12
  134. package/src/utils/preprocessingOptions.ts +0 -334
  135. /package/dist/api/RootComponent/{Data/expected/error.d.ts → Properties/test/normalEmpty.test.d.ts} +0 -0
  136. /package/dist/{utils → behaviors/BComputedAndWatch}/getPathsValue.js +0 -0
  137. /package/src/api/RootComponent/Properties/test/{normalEmpty.test..ts → normalEmpty.test.ts} +0 -0
@@ -1,19 +1,7 @@
1
1
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
2
  import type { Func } from "hry-types/src/Misc/Func";
3
- import { BBeforeCreate } from "../../behaviors/BbeforeCreated";
4
- import { BComputedAndWatch } from "../../behaviors/BComputedAndWatch";
5
- import { initComputed } from "../../behaviors/BComputedAndWatch/initComputed";
6
- import { BStore } from "../../behaviors/BStore";
7
3
  import type { WMComponent, WMCompPageLifetimes, WMPageLifetimes } from "../../types/OfficialTypeAlias";
8
- import { isEmptyObject } from "../../utils/isEmptyObject";
9
- import {
10
- excludeFields,
11
- funcConfigHandle,
12
- onLoadHijack,
13
- onLoadReceivedDataHandle,
14
- rootComponentFieldHandle,
15
- subComponentsHandle,
16
- } from "../../utils/preprocessingOptions";
4
+
17
5
  import type { LifetimesConstraint } from "../RootComponent/Lifetimes/LifetimesConstraint";
18
6
  import type { RootComponentDoc } from "../RootComponent/RootComponentDoc";
19
7
  import type { SubComponentDoc } from "../SubComponent/SubComponentDoc";
@@ -23,6 +11,11 @@ import type { CreatePageDoc } from "./ReturnType/CreatePageDoc";
23
11
  import type { RootComponentOption } from "./RootComponent/RootComponentOption";
24
12
  import type { SubComponentsOption } from "./SubComponents/SubComponentsOption";
25
13
 
14
+ import type { RootComponentTrueOptions } from "../RootComponent";
15
+ import { collectOptionsForComponent } from "./collectOptionsForComponent";
16
+
17
+ type Path = `/${string}`;
18
+
26
19
  type RootOptions<
27
20
  TRootComponentDoc extends RootComponentDoc,
28
21
  TSubComponentTuple extends SubComponentDoc[],
@@ -56,19 +49,15 @@ interface DefineComponentConstructor {
56
49
  * 临时的函数配置项
57
50
  * 把根组件与子组件中配置类型为函数的相同字段配置收集在一起(数组)
58
51
  */
59
- export type FuncConfig = {
60
- pageLifetimes?: Record<string, Func[]>;
61
- lifetimes?: Record<string, Func[]>;
62
- watch?: Record<string, Func[]>;
63
- };
52
+ export type FuncOptions = Record<"pageLifetimes" | "lifetimes" | "watch", Record<string, Func[]>>;
64
53
 
65
54
  /**
66
- * 传入原生Component的配置项
55
+ * 最终传入原生Component的配置项
67
56
  */
68
- export type ComponentOptions = {
57
+ export type FinalOptionsForComponent = {
69
58
  isPage?: boolean;
70
59
  options?: WMComponent.Options;
71
- properties?: object;
60
+ properties?: Record<string, any>;
72
61
  data?: object;
73
62
  store?: object;
74
63
  computed?: Record<string, Func>;
@@ -80,65 +69,8 @@ export type ComponentOptions = {
80
69
  pageLifetimes?: Partial<WMCompPageLifetimes & { load: Func } & WMPageLifetimes>;
81
70
  };
82
71
 
83
- export type Path = `/${string}`;
84
-
85
- export type DefineComponentOptions = {
86
- path?: Path;
87
- name?: string;
88
- rootComponent?: RootComponentDoc;
89
- subComponents?: SubComponentDoc[];
90
- };
91
-
92
72
  export const DefineComponent: DefineComponentConstructor = function(options): any {
93
- // console.log("------------------------------------------------分割线------------------------------------------------");
94
-
95
- // 最终的配置
96
- const componentOptions: ComponentOptions = {
97
- options: {
98
- // addGlobalClass: true,
99
- multipleSlots: true,
100
- pureDataPattern: /^_/,
101
- virtualHost: true,
102
- },
103
- // default behaviors
104
- behaviors: [BStore, BComputedAndWatch],
105
- };
106
- /**
107
- * 有些选项配置是函数,且可能分布在根组件和子组件中,tempConfig 用于收集这些配置,最终再一起整合进componentOptions配置。rootComponentHandle和subComponentsHandle都会收集配置,funcConfigHandle整理配置。
108
- */
109
- const funcConfig: FuncConfig = {};
110
-
111
- if (options.rootComponent && !isEmptyObject(options.rootComponent)) {
112
- rootComponentFieldHandle(options.rootComponent, componentOptions, funcConfig);
113
- }
114
-
115
- if (options.subComponents && !isEmptyObject(options.subComponents)) {
116
- subComponentsHandle(componentOptions, options.subComponents, funcConfig);
117
- }
118
- if (!isEmptyObject(funcConfig)) {
119
- funcConfigHandle(componentOptions, options.rootComponent?.isPage, funcConfig);
120
- }
121
-
122
- componentOptions.methods && excludeFields(componentOptions.methods, ["disposer", "applySetData"]);
123
-
124
- componentOptions.behaviors!.push(BBeforeCreate);
125
-
126
- onLoadHijack(componentOptions, [onLoadReceivedDataHandle, initComputed], []);
127
-
128
- if (componentOptions.isPage) {
129
- Reflect.deleteProperty(componentOptions.options!, "virtualHost");
130
- }
131
- Component(componentOptions as any);
132
- };
133
-
134
- export type PageOptions = {
135
- path: Path;
136
- rootComponent: RootComponentDoc & { isPage: true };
137
- subComponents: SubComponentDoc[];
138
- };
139
-
140
- export type CompOptions = {
141
- name: string;
142
- rootComponent: RootComponentDoc & { isPage: undefined };
143
- subComponents: SubComponentDoc[];
73
+ Component(
74
+ collectOptionsForComponent(options.rootComponent as RootComponentTrueOptions | undefined, options.subComponents),
75
+ );
144
76
  };
@@ -2,7 +2,7 @@ import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { SpecificType } from "../../../../types/SpecificType";
4
4
  import { RootComponent } from "../..";
5
- import type { Mock_User } from "../../Properties/expected/normalRequired";
5
+ import type { Mock_User } from "../../Properties/test/normalRequired.test";
6
6
 
7
7
  /**
8
8
  * computed字段约束为 [ComputedConstraint](../ComputedConstraint.ts)
@@ -47,4 +47,6 @@ export type FullCustomEvents = {
47
47
  options: OptionsFieldsConfigOfCustomEvents;
48
48
  };
49
49
 
50
- export type CustomEventConstraint = Record<string, FullCustomEvents | ShortCustomeEvents>;
50
+ export type CustomEvents = FullCustomEvents | ShortCustomeEvents;
51
+
52
+ export type CustomEventConstraint = Record<string, CustomEvents>;
@@ -0,0 +1 @@
1
+ export type DataConstraint = Record<string, any>;
@@ -1 +1,6 @@
1
- export type IsPageOption<TIsPage extends boolean> = { isPage?: TIsPage };
1
+ export type IsPageOption<TIsPage extends boolean> = {
2
+ /**
3
+ * 表示组件是否为页面,可选,默认false
4
+ */
5
+ isPage?: TIsPage;
6
+ };
@@ -1,10 +1,11 @@
1
1
  import type { WMCompLifetimes } from "../../../types/OfficialTypeAlias";
2
+ import type { FinalOptionsForComponent } from "../../DefineComponent";
2
3
 
3
4
  export type LifetimesConstraint = // 官方组件生命周期
4
- WMCompLifetimes["lifetimes"];
5
- // & {
6
- // /**
7
- // * 建立组件时的真正配置对象
8
- // */
9
- // beforeCreate?: (options: WMTrivialOption<any, any, any, any, false>) => void;
10
- // };
5
+ & WMCompLifetimes["lifetimes"]
6
+ & {
7
+ /**
8
+ * 建立组件时的真正配置对象
9
+ */
10
+ beforeCreate?: (options: FinalOptionsForComponent) => void;
11
+ };
@@ -4,7 +4,7 @@ import { RootComponent } from "../..";
4
4
  */
5
5
  RootComponent()({
6
6
  lifetimes: {
7
- // beforeCreate() {},
7
+ beforeCreate() {},
8
8
 
9
9
  created() {},
10
10
 
@@ -6,9 +6,9 @@ import { RootComponent } from "../../../..";
6
6
  RootComponent()({
7
7
  lifetimes: {
8
8
  // 新增声明周期用于查看实例初始化之前的配置文件
9
- // beforeCreate(opitons) {
10
- // opitons;
11
- // },
9
+ beforeCreate(opitons) {
10
+ opitons;
11
+ },
12
12
  created() {
13
13
  },
14
14
  attached() {
@@ -2,7 +2,7 @@ import { Checking, type Test } from "hry-types";
2
2
  import { RootComponent, type SpecificType } from "../../../..";
3
3
 
4
4
  import type { RemoveNullOfRequired } from "../../../../types/RemoveNullOfRequired";
5
- import type { Mock_User } from "../../Properties/expected/normalRequired";
5
+ import type { Mock_User } from "../../Properties/test/normalRequired.test";
6
6
 
7
7
  /**
8
8
  * 组件时
@@ -73,3 +73,23 @@ type OptionalDocExpected = {
73
73
  };
74
74
 
75
75
  Checking<typeof OptionalDoc, OptionalDocExpected, Test.Pass>;
76
+
77
+ // properties 使用SpecificType时,接受interface类型
78
+ interface Foo {
79
+ name: string;
80
+ }
81
+
82
+ RootComponent()({
83
+ properties: {
84
+ xxx: Object as SpecificType<{ dd: Foo }>,
85
+ user: {
86
+ type: Object as SpecificType<Foo>,
87
+ value: { name: "zhao" },
88
+ },
89
+ },
90
+ computed: {
91
+ ddd() {
92
+ this.data.user?.name;
93
+ },
94
+ },
95
+ });
@@ -2,7 +2,7 @@ import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { SpecificType } from "../../../../types/SpecificType";
4
4
  import { RootComponent } from "../..";
5
- import { type Mock_User } from "../../Properties/expected/normalRequired";
5
+ import type { Mock_User } from "../../Properties/test/normalRequired.test";
6
6
 
7
7
  /**
8
8
  * 1 computed字段时需要手写类型,可悬停鼠标到key查看类型,深度只读
@@ -3,7 +3,7 @@ import { Checking, type Test } from "hry-types";
3
3
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
4
  import { observable } from "mobx";
5
5
  import { RootComponent } from "../..";
6
- import type { Mock_User } from "../../Properties/expected/normalRequired";
6
+ import type { Mock_User } from "../../Properties/test/normalRequired.test";
7
7
 
8
8
  const obj = observable({
9
9
  gender: <"male" | "female"> "male",
@@ -4,13 +4,19 @@ import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
4
  import { RootComponent } from "../..";
5
5
 
6
6
  import type { SpecificType } from "../../../..";
7
+ // import {
8
+ // type Mock_Cart,
9
+ // mock_requiredTypes,
10
+ // mock_requiredUnion,
11
+ // type Mock_User,
12
+ // } from "../../Properties/expected/normalRequired";
13
+ import type { OptionalType } from "../../Properties/PropertiesConstraint";
7
14
  import {
8
15
  type Mock_Cart,
9
16
  mock_requiredTypes,
10
17
  mock_requiredUnion,
11
18
  type Mock_User,
12
- } from "../../Properties/expected/normalRequired";
13
- import type { OptionalType } from "../../Properties/PropertiesConstraint";
19
+ } from "../../Properties/test/normalRequired.test";
14
20
  const mock_optional = {
15
21
  optional_num: {
16
22
  type: Number,
@@ -3,7 +3,7 @@ import type { NoInfer } from "hry-types/src/Generic/NoInfer";
3
3
  import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
4
4
  import type { Func } from "hry-types/src/Misc/Func";
5
5
  import type { ComputeIntersectionDeep } from "hry-types/src/Object/_api";
6
- import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
6
+ import type { WMCompOtherOption, WMCompPageLifetimes, WMPageLifetimes } from "../../types/OfficialTypeAlias";
7
7
  import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
8
8
  import type { ComputedConstraint } from "./Computed/ComputedConstraint";
9
9
  import type { ComputedOption } from "./Computed/ComputedOption";
@@ -11,11 +11,13 @@ import type { GetComputedDoc } from "./Computed/GetComputedDoc";
11
11
  import type { CustomEventConstraint } from "./CustomEvents/CustomEventConstraint";
12
12
  import type { CustomEventsOption } from "./CustomEvents/CustomEventsOption";
13
13
  import type { GetCustomEventDoc } from "./CustomEvents/GetCustomEventDoc";
14
+ import type { DataConstraint } from "./Data/DataConstraint";
14
15
  import type { DataOption } from "./Data/DataOption";
15
16
  import type { EventsConstraint } from "./Events/EventsConstraint";
16
17
  import type { EventsOption } from "./Events/EventsOption";
17
18
  import type { RootComponentInstance } from "./Instance/RootComponentInstance";
18
19
  import type { IsPageOption } from "./IsPage/IsPageOption";
20
+ import type { LifetimesConstraint } from "./Lifetimes/LifetimesConstraint";
19
21
  import type { LifetimesOption } from "./Lifetimes/LifetimesOption";
20
22
  import type { MethodsConstraint } from "./Methods/MethodsConstraint";
21
23
  import type { MethodsOption } from "./Methods/MethodsOption";
@@ -81,7 +83,7 @@ type RootComponentConstructor<TReceivedComponentDoc extends ComponentDoc[] | Com
81
83
  | boolean
82
84
  | null
83
85
  | Literal[]
84
- | Record<string, Literal>,
86
+ | object,
85
87
  // TEvents 不能有默认值 {} 会引起事件参数类型(e)失效
86
88
  TEvents extends EventsConstraint<TReceivedComponentDoc>,
87
89
  TIsPage extends boolean = false,
@@ -135,5 +137,19 @@ export function RootComponent<
135
137
  >(): RootComponentConstructor<
136
138
  TReceivedComponentDoc
137
139
  > {
138
- return (options: any) => options;
140
+ return ((options: any) => options as RootComponentTrueOptions) as any;
139
141
  }
142
+
143
+ export type RootComponentTrueOptions = {
144
+ isPage?: boolean;
145
+ properties?: PropertiesConstraint;
146
+ data?: DataConstraint;
147
+ computed?: ComputedConstraint;
148
+ customEvents?: CustomEventConstraint;
149
+ methods?: MethodsConstraint;
150
+ events?: EventsConstraint;
151
+ store?: StoreConstraint;
152
+ watch?: Record<string, Func>;
153
+ lifetimes?: LifetimesConstraint;
154
+ pageLifetimes?: Partial<WMCompPageLifetimes & { load: Func } & WMPageLifetimes>;
155
+ };
@@ -1,7 +1,8 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
4
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
4
+
5
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
5
6
  import { SubComponent } from "../..";
6
7
 
7
8
  type OnlyCustomCompDoc = ComponentDoc<{
@@ -1,5 +1,6 @@
1
1
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
2
+
3
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
3
4
  import { SubComponent } from "../..";
4
5
 
5
6
  type OnlyCustomCompDoc = ComponentDoc<{
@@ -3,7 +3,8 @@ import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { Wm } from "../../../../thirdLib";
4
4
  import type { CompDocExtends } from "../../../../types/CompDocExtends";
5
5
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
6
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
6
+
7
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
7
8
  import { SubComponent } from "../..";
8
9
 
9
10
  type CompDoc = ComponentDoc<{
@@ -1,7 +1,8 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
4
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
4
+
5
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
5
6
  import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
6
7
  import { SubComponent } from "../..";
7
8
 
@@ -1,5 +1,6 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
2
+
3
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
3
4
  import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
4
5
  import { SubComponent } from "../..";
5
6
 
@@ -2,7 +2,8 @@ import { Checking, type Test } from "hry-types";
2
2
 
3
3
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
4
  import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
5
- import type { Mock_User } from "../../../RootComponent/Properties/expected/normalRequired";
5
+
6
+ import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
6
7
  import { SubComponent } from "../..";
7
8
 
8
9
  type TestObj = {
@@ -1,4 +1,4 @@
1
- import type { Wm } from "../../../../thirdLib";
1
+ import type { Wm } from "../../../..";
2
2
  import { SubComponent } from "../..";
3
3
 
4
4
  // 测试1
@@ -153,7 +153,15 @@ type SubComponentConstructor<
153
153
  & InheritDoc
154
154
  & SubDataDoc
155
155
  & SubStoreDoc
156
- & SubComputedDoc
156
+ // 改用SubComputedDoc是会报错的
157
+ & IfExtends<
158
+ SubComputedConstraint<
159
+ Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>
160
+ >,
161
+ TSubComputed,
162
+ {},
163
+ GetSubComputedDoc<TSubComputed>
164
+ >
157
165
  )
158
166
  >,
159
167
  >(
@@ -188,11 +196,10 @@ export function SubComponent<
188
196
  CompDoc extends ComponentDoc,
189
197
  Prefix extends string = "",
190
198
  >(): IfExtends<EmptyObject, CompDoc, (opt: EmptyObject) => never, SubComponentConstructor<RootDoc, CompDoc, Prefix>> {
191
- return ((options: any) => options) as any;
199
+ return ((options: any) => options as SubComponentTrueOptions) as any;
192
200
  }
193
201
 
194
- // 相比与 export type TrivialOption = Options<{},...>,更直观字段和类型,但断耦合,注意类型是否正确.这是为最终生成官方Component API 的options参数而生。
195
- export type SubComponentOptions = {
202
+ export type SubComponentTrueOptions = {
196
203
  inhrit?: string;
197
204
  data?: Record<string, unknown>;
198
205
  computed?: Record<string, Func>;
@@ -1,9 +1,10 @@
1
- import { deepProxy, unwrap } from "../behaviors/BComputedAndWatch/data-tracer";
2
- import type { ComputedDependence } from "../behaviors/BComputedAndWatch/initComputed";
3
- import { isEqual } from "../behaviors/BComputedAndWatch/isEqual";
4
- import type { Instance } from "../behaviors/BComputedAndWatch/types";
1
+ import { deepProxy, unwrap } from "./data-tracer";
5
2
  import { getPathsValue } from "./getPathsValue";
6
3
 
4
+ import type { ComputedDependence } from "./initComputed";
5
+ import { isEqual } from "./isEqual";
6
+ import type { Instance } from "./types";
7
+
7
8
  export function computedUpdater(this: Instance, isUpdated = false): boolean {
8
9
  // console.log("computedUpdater开始");
9
10
 
@@ -6,9 +6,6 @@ export function deepProxy(
6
6
  basePath: string[] = [],
7
7
  ): object {
8
8
  const handler = {
9
- set() {
10
- throw Error("计算属性中不可以改变data对象的值");
11
- },
12
9
  get(target: object, prop: string) {
13
10
  // // 得到原始的对象 在unwrap时使用
14
11
  // console.log(target, prop);
@@ -1,4 +1,4 @@
1
- import type { Instance } from "../behaviors/BComputedAndWatch/types";
1
+ import type { Instance } from "./types";
2
2
 
3
3
  export function getPathsValue(this: Instance, paths: string[]) {
4
4
  return paths.reduce((pre: any, path) => {
@@ -1,13 +1,22 @@
1
1
  import type { Func } from "hry-types/src/Misc/Func";
2
- import type { ComponentOptions } from "../../api/DefineComponent";
2
+ import type { FinalOptionsForComponent } from "../../api/DefineComponent";
3
3
  import { deepClone } from "../../utils/deepClone";
4
4
  import { deleteProtoField } from "../../utils/deleteProtoField";
5
- import { initWatchOldValue } from "../../utils/initWatchOldValue";
5
+
6
6
  import { isEmptyObject } from "../../utils/isEmptyObject";
7
+ import { getPathsValue } from "./getPathsValue";
7
8
  import { initComputed } from "./initComputed";
8
9
  import { isEqual } from "./isEqual";
9
10
  import { isPage } from "./IsPage";
10
- import type { Instance } from "./types";
11
+ import type { Instance, WatchOldValue } from "./types";
12
+ function initWatchOldValue(this: Instance, watchConfig: object): WatchOldValue {
13
+ const watchOldValue = {};
14
+ for (const key in watchConfig) {
15
+ watchOldValue[key] = deepClone(getPathsValue.call(this, key.split(".")));
16
+ }
17
+
18
+ return watchOldValue;
19
+ }
11
20
  /**
12
21
  * 实现
13
22
  * 1. 计算属性初始化在attached之后(前版本在beforeCreate)
@@ -23,12 +32,15 @@ import type { Instance } from "./types";
23
32
  */
24
33
 
25
34
  export const BComputedAndWatch = Behavior({
26
- definitionFilter(options: ComponentOptions) {
35
+ definitionFilter(options: FinalOptionsForComponent) {
27
36
  const computedConfig = options.computed;
28
37
 
29
38
  // computed handle
30
39
  if (computedConfig && !isEmptyObject(computedConfig)) {
31
- const methodsConfig = options.methods ||= {};
40
+ /* istanbul ignore next */
41
+ options.methods ||= {};
42
+
43
+ const methodsConfig = options.methods;
32
44
 
33
45
  // 把计算属性配置保留在methods的__computedConfig__字段下带入到组件实例中。
34
46
  methodsConfig.__computedConfig__ = () => computedConfig;
@@ -42,7 +54,7 @@ export const BComputedAndWatch = Behavior({
42
54
  switch (computedStatus) {
43
55
  case undefined:
44
56
  // 1 触发来自attach时或没有计算属性时
45
- originalFunc && originalFunc.call(this);
57
+ originalFunc && /* istanbul ignore next */ originalFunc.call(this);
46
58
 
47
59
  break;
48
60
  case "初始化中":
@@ -58,7 +70,7 @@ export const BComputedAndWatch = Behavior({
58
70
  this.__computedStatus__ = "更新完毕";
59
71
  } else {
60
72
  // 无需更新计算属性
61
- originalFunc && originalFunc.call(this);
73
+ originalFunc && /* istanbul ignore next */ originalFunc.call(this);
62
74
  }
63
75
  }
64
76
  break;
@@ -68,7 +80,7 @@ export const BComputedAndWatch = Behavior({
68
80
  // console.log("来自计算属性更新后的自身回调");
69
81
  this.__computedStatus__ = "待更新";
70
82
 
71
- originalFunc && originalFunc.call(this);
83
+ originalFunc && /* istanbul ignore next */ originalFunc.call(this);
72
84
  }
73
85
  break;
74
86
  }
@@ -78,6 +90,7 @@ export const BComputedAndWatch = Behavior({
78
90
  // watch handle
79
91
  const watchConfig = options.watch;
80
92
  if (watchConfig && !isEmptyObject(watchConfig)) {
93
+ /* istanbul ignore next */
81
94
  const methodsConfig = options.methods ||= {};
82
95
 
83
96
  // 把watch配置保留在methods的__watchConfig__字段下带入到组件实例中。
@@ -2,8 +2,8 @@
2
2
  // import type { IsDependOnOthers } from "./data-tracer";
3
3
 
4
4
  import type { Func } from "hry-types/src/Misc/Func";
5
- import { computedUpdater } from "../../utils/computedUpdater";
6
5
  import { deleteProtoField } from "../../utils/deleteProtoField";
6
+ import { computedUpdater } from "./computedUpdater";
7
7
  import { deepProxy, unwrap } from "./data-tracer";
8
8
  import type { ComputedCache, Instance } from "./types";
9
9
  export type ComputedDependence = { paths: string[]; val: unknown };
@@ -37,19 +37,21 @@ export function getComputedInfo(
37
37
  // 建立当前计算字段的依赖
38
38
  const dependences: ComputedDependence[] = [];
39
39
  let initValue: unknown;
40
- try {
41
- initValue = computedFunc.call({
42
- data: deepProxy(this.data, dependences),
43
- });
44
- } catch (error) {
45
- // 为js开发考虑使用了 this.data.xxx.age 当xxx为undefined时
46
- if (!isValidDependences(dependences, computedKeys)) {
47
- // 情况2 依赖了未初始化的计算属性的子属性(会报错) 见computed测试文件
48
- return false;
49
- }
50
- // 其他错误正常报错
51
- throw error;
52
- }
40
+ // try {
41
+ initValue = computedFunc.call({
42
+ data: deepProxy(this.data, dependences),
43
+ });
44
+ // } catch (error) {
45
+ // // 为js开发考虑使用了 this.data.xxx.age 当xxx为undefined时
46
+ // if (!isValidDependences(dependences, computedKeys)) {
47
+ // console.log(222);
48
+
49
+ // // 情形2 依赖了未初始化的计算属性的子属性(会报错) 对应测试文件[NoOptionalProperties.ts](../../../jest/computed/NoOptionalProperties/NoOptionalProperties.test.ts)的age字段
50
+ // return false;
51
+ // }
52
+ // // 其他错误正常报错
53
+ // throw error;
54
+ // }
53
55
  if (isValidDependences(dependences, computedKeys)) {
54
56
  // 有效的依赖
55
57
  initValue = unwrap(initValue);
@@ -60,7 +62,9 @@ export function getComputedInfo(
60
62
 
61
63
  return { dependences, value: initValue };
62
64
  } else {
63
- // 情况1 依赖了其他未初始化的计算属性(不报错) 见computed测试文件
65
+ /**
66
+ * 情形1 依赖了其他未初始化的计算属性(不报错) 对应测试文件[NoOptionalProperties.ts](../../../jest/computed/NoOptionalProperties/NoOptionalProperties.test.ts)的copyPropUser字段
67
+ */
64
68
  return false;
65
69
  }
66
70
  }
@@ -76,6 +80,7 @@ export function getComputedInfo(
76
80
  */
77
81
  function uniqueDependences(dependences: ComputedDependence[]): ComputedDependence[] {
78
82
  if (dependences.length === 1) return dependences;
83
+ // console.log(dependences);
79
84
 
80
85
  for (let f = 0; f < dependences.length; f++) {
81
86
  const firstPath = dependences[f].paths.join(".") + ".";
@@ -83,15 +88,17 @@ function uniqueDependences(dependences: ComputedDependence[]): ComputedDependenc
83
88
  const curPath = dependences[i].paths.join(".") + ".";
84
89
  // console.log(firstPath,curPath)
85
90
  if (firstPath.startsWith(curPath)) {
86
- // console.log('删除:',f)
87
- // 例如 path[0] = 'a.b.c',curPath = 'a.b'
91
+ // console.log("删除:", curPath, f);
92
+
93
+ // 例如 path[0] = 'a.b.c.',curPath = 'a.b.'
88
94
  dependences.splice(f, 1);
89
95
 
90
96
  return uniqueDependences(dependences);
91
97
  }
92
98
  if (curPath.startsWith(firstPath)) {
93
- // console.log('删除:',i)
94
- // 例如 curPath = 'a.b.c' path[0] = 'a.b',
99
+ // console.log("删除:", firstPath, i);
100
+
101
+ // 例如 curPath = 'a.b.' path[0] = 'a.b.c.',
95
102
  dependences.splice(i, 1);
96
103
 
97
104
  return uniqueDependences(dependences);
@@ -12,6 +12,7 @@ export function isEqual(value: unknown, other: unknown) {
12
12
  const keys1 = Object.keys(value);
13
13
  const keys2 = Object.keys(other);
14
14
  // 对象类型长度不等,一定不相等
15
+ /* istanbul ignore next */
15
16
  if (keys1.length !== keys2.length) {
16
17
  return false;
17
18
  }