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.
Files changed (130) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/README.md +45 -38
  3. package/dist/api/DefineComponent/ReturnType/ComponentType.d.ts +18 -0
  4. package/dist/api/DefineComponent/ReturnType/ComponentType.js +2 -0
  5. package/dist/api/DefineComponent/ReturnType/ComponentType.js.map +1 -0
  6. package/dist/api/DefineComponent/ReturnType/CreateComponentDoc.d.ts +3 -3
  7. package/dist/api/DefineComponent/ReturnType/CreatePageDoc.d.ts +2 -2
  8. package/dist/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.d.ts +3 -3
  9. package/dist/api/DefineComponent/RootComponent/RootComponentOption.d.ts +2 -2
  10. package/dist/api/DefineComponent/SubComponents/SubComponentsOption.d.ts +2 -2
  11. package/dist/api/DefineComponent/index.d.ts +5 -5
  12. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js +2 -2
  13. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js.map +1 -1
  14. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js +1 -0
  15. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.js.map +1 -1
  16. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js +2 -2
  17. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js.map +1 -1
  18. package/dist/api/DefineComponent/normalizeOptions/index.js +1 -1
  19. package/dist/api/DefineComponent/normalizeOptions/index.js.map +1 -1
  20. package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js +1 -0
  21. package/dist/api/DefineComponent/normalizeOptions/internalFieldProtection.js.map +1 -1
  22. package/dist/api/RootComponent/Events/EventsConstraint.d.ts +4 -4
  23. package/dist/api/RootComponent/PageLifetimes/PageLifetimesOption.d.ts +3 -1
  24. package/dist/api/RootComponent/Properties/GetPropertiesDoc.d.ts +2 -1
  25. package/dist/api/RootComponent/Properties/GetRequiredDoc.d.ts +2 -2
  26. package/dist/api/RootComponent/{RootComponentDoc.d.ts → RootComponentType.d.ts} +16 -15
  27. package/dist/api/RootComponent/RootComponentType.js +2 -0
  28. package/dist/api/RootComponent/RootComponentType.js.map +1 -0
  29. package/dist/api/RootComponent/index.d.ts +5 -4
  30. package/dist/api/RootComponent/index.js.map +1 -1
  31. package/dist/api/SubComponent/{SubComponentDoc.d.ts → SubComponentType.d.ts} +3 -3
  32. package/dist/api/SubComponent/SubComponentType.js +2 -0
  33. package/dist/api/SubComponent/SubComponentType.js.map +1 -0
  34. package/dist/api/SubComponent/SubComputed/SubComputedOption.d.ts +2 -2
  35. package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
  36. package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +2 -2
  37. package/dist/api/SubComponent/index.d.ts +9 -6
  38. package/dist/api/SubComponent/index.js.map +1 -1
  39. package/dist/behaviors/BStore.d.ts +1 -1
  40. package/dist/behaviors/BStore.js +33 -18
  41. package/dist/behaviors/BStore.js.map +1 -1
  42. package/dist/index.d.ts +2 -2
  43. package/dist/types/CreateComponentType.d.ts +23 -2
  44. package/dist/types/ExtendComponentType.d.ts +34 -0
  45. package/dist/types/ExtendComponentType.js +6 -0
  46. package/dist/types/ExtendComponentType.js.map +1 -0
  47. package/dist/types/GetComponentPrefix.d.ts +2 -2
  48. package/dist/types/RemoveNullOfRequired.d.ts +7 -0
  49. package/dist/types/RemoveNullOfRequired.js +2 -0
  50. package/dist/types/RemoveNullOfRequired.js.map +1 -0
  51. package/dist/types/ReplacePrefix.d.ts +2 -2
  52. package/dist/utils/assertNonNullable.js +1 -0
  53. package/dist/utils/assertNonNullable.js.map +1 -1
  54. package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.d.ts → utils/deepEqual.d.ts} +1 -1
  55. package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js → utils/deepEqual.js} +3 -3
  56. package/dist/utils/deepEqual.js.map +1 -0
  57. package/package.json +2 -3
  58. package/src/api/DefineComponent/NameOrPage/test/error.test.ts +6 -6
  59. package/src/api/DefineComponent/ReturnType/{ComponentDoc.ts → ComponentType.ts} +6 -7
  60. package/src/api/DefineComponent/ReturnType/CreateComponentDoc.ts +4 -4
  61. package/src/api/DefineComponent/ReturnType/CreatePageDoc.ts +2 -2
  62. package/src/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.ts +3 -3
  63. package/src/api/DefineComponent/ReturnType/GetPropertiesDocOfSubDoc.ts +3 -3
  64. package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +5 -5
  65. package/src/api/DefineComponent/RootComponent/RootComponentOption.ts +2 -2
  66. package/src/api/DefineComponent/SubComponents/SubComponentsOption.ts +2 -2
  67. package/src/api/DefineComponent/SubComponents/test/normal.test.ts +3 -3
  68. package/src/api/DefineComponent/index.ts +7 -7
  69. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.ts +2 -2
  70. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/getPropertiesValue.ts +1 -0
  71. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/index.ts +2 -2
  72. package/src/api/DefineComponent/normalizeOptions/index.ts +1 -1
  73. package/src/api/DefineComponent/normalizeOptions/internalFieldProtection.ts +1 -0
  74. package/src/api/RootComponent/Computed/test/normal.test.ts +20 -0
  75. package/src/api/RootComponent/Events/EventsConstraint.ts +5 -5
  76. package/src/api/RootComponent/Events/test/normal.test.ts +5 -5
  77. package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +2 -4
  78. package/src/api/RootComponent/PageLifetimes/PageLifetimesOption.ts +4 -1
  79. package/src/api/RootComponent/PageLifetimes/test/normal.test.ts +26 -0
  80. package/src/api/RootComponent/Properties/GetOptionalDoc.ts +4 -4
  81. package/src/api/RootComponent/Properties/GetPropertiesDoc.ts +2 -1
  82. package/src/api/RootComponent/Properties/GetRequiredDoc.ts +9 -23
  83. package/src/api/RootComponent/{RootComponentDoc.ts → RootComponentType.ts} +16 -15
  84. package/src/api/RootComponent/index.ts +10 -4
  85. package/src/api/SubComponent/{SubComponentDoc.ts → SubComponentType.ts} +3 -3
  86. package/src/api/SubComponent/SubComputed/SubComputedOption.ts +2 -0
  87. package/src/api/SubComponent/SubComputed/test/error.test.ts +3 -3
  88. package/src/api/SubComponent/SubComputed/test/normal.test.ts +5 -5
  89. package/src/api/SubComponent/SubData/test/error.test.ts +3 -3
  90. package/src/api/SubComponent/SubData/test/normal.test.ts +2 -2
  91. package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +2 -2
  92. package/src/api/SubComponent/SubEvents/test/error.test.ts +3 -3
  93. package/src/api/SubComponent/SubEvents/test/normal.test.ts +2 -2
  94. package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +2 -2
  95. package/src/api/SubComponent/SubInherit/test/error.test.ts +6 -6
  96. package/src/api/SubComponent/SubInherit/test/normal.test.ts +18 -4
  97. package/src/api/SubComponent/SubInstance/test/error.test.ts +2 -2
  98. package/src/api/SubComponent/SubInstance/test/normal.test.ts +4 -4
  99. package/src/api/SubComponent/SubMethods/test/error.test.ts +4 -4
  100. package/src/api/SubComponent/SubMethods/test/normarl.test.ts +4 -4
  101. package/src/api/SubComponent/SubReturnType/test/error.test.ts +2 -2
  102. package/src/api/SubComponent/SubReturnType/test/normal.test.ts +2 -2
  103. package/src/api/SubComponent/SubStore/test/error.test.ts +2 -2
  104. package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -2
  105. package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +4 -4
  106. package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +2 -2
  107. package/src/api/SubComponent/SubWatch/test/WatchSubData.test.ts +2 -2
  108. package/src/api/SubComponent/index.ts +17 -11
  109. package/src/behaviors/BStore.ts +37 -23
  110. package/src/index.ts +2 -2
  111. package/src/types/CreateComponentType.ts +23 -2
  112. package/src/types/ExtendComponentType.ts +60 -0
  113. package/src/types/GetComponentPrefix.ts +2 -2
  114. package/src/types/GetPropertiesDuplicatedKeys.ts +3 -3
  115. package/src/types/ReplacePrefix.ts +2 -2
  116. package/src/utils/assertNonNullable.ts +1 -0
  117. package/src/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.ts → utils/deepEqual.ts} +2 -3
  118. package/dist/api/DefineComponent/ReturnType/ComponentDoc.d.ts +0 -18
  119. package/dist/api/DefineComponent/ReturnType/ComponentDoc.js +0 -2
  120. package/dist/api/DefineComponent/ReturnType/ComponentDoc.js.map +0 -1
  121. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js.map +0 -1
  122. package/dist/api/RootComponent/RootComponentDoc.js +0 -2
  123. package/dist/api/RootComponent/RootComponentDoc.js.map +0 -1
  124. package/dist/api/SubComponent/SubComponentDoc.js +0 -2
  125. package/dist/api/SubComponent/SubComponentDoc.js.map +0 -1
  126. package/dist/types/DocAssign.d.ts +0 -10
  127. package/dist/types/DocAssign.js +0 -6
  128. package/dist/types/DocAssign.js.map +0 -1
  129. package/src/types/DocAssign.ts +0 -36
  130. package/tsconfig.json +0 -23
@@ -1,14 +1,14 @@
1
1
  import type { Contains } from "hry-types/src/Any/Contains";
2
2
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
3
3
  import type { Detail, WMBaseEvent } from "../../../types/OfficialTypeAlias";
4
- import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
4
+ import type { ComponentType } from "../../DefineComponent/ReturnType/ComponentType";
5
5
  import type { Bubbles, Capture, CustomEventsTags } from "../../RootComponent/CustomEvents/CustomEventsTag";
6
6
 
7
7
  /**
8
8
  * 把组件事件类型转为函数类型,冒泡事件捕获事件会多一个加后缀(_catch)的key,表示阻止事件冒泡和捕获。
9
9
  */
10
10
  export type SubEventsConstraint<
11
- CompDoc extends ComponentDoc,
11
+ CompDoc extends ComponentType,
12
12
  > = {
13
13
  [
14
14
  k in keyof CompDoc["customEvents"] as Contains<CompDoc["customEvents"][k], Bubbles | Capture> extends true
@@ -1,8 +1,8 @@
1
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
1
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
2
2
  import type { Bubbles } from "../../../RootComponent/CustomEvents/CustomEventsTag";
3
3
  import { SubComponent } from "../..";
4
4
 
5
- type CompDoc = ComponentDoc<{
5
+ type CompDoc = ComponentType<{
6
6
  properties: {
7
7
  aaa_str: string;
8
8
  };
@@ -16,7 +16,7 @@ SubComponent<{}, CompDoc>()({
16
16
  },
17
17
  });
18
18
 
19
- type CompDoc1 = ComponentDoc<{
19
+ type CompDoc1 = ComponentType<{
20
20
  customEvents: {
21
21
  aaa_str: string | Bubbles;
22
22
  };
@@ -4,7 +4,7 @@ import { Checking, type Test } from "hry-types";
4
4
  import type { Wm } from "../../../../thirdLib";
5
5
 
6
6
  import type { Detail, Mark, WMBaseEvent } from "../../../..";
7
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
7
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
8
8
  import type {
9
9
  Bubbles,
10
10
  BubblesCapture,
@@ -16,7 +16,7 @@ import type {
16
16
  import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
17
17
  import { SubComponent } from "../..";
18
18
 
19
- type CompDoc = ComponentDoc<{
19
+ type CompDoc = ComponentType<{
20
20
  customEvents: {
21
21
  aaa_str: string;
22
22
  aaa_bubbles: string | Bubbles;
@@ -1,6 +1,6 @@
1
1
  import type { SelectKeys } from "hry-types/src/Object/_api";
2
2
  import type { RemoveInnerData } from "../../../types/RemoveInnerData";
3
- import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
3
+ import type { ComponentType } from "../../DefineComponent/ReturnType/ComponentType";
4
4
 
5
5
  type WXMLSign = "wxml";
6
6
 
@@ -10,7 +10,7 @@ type unionAddList<Keys extends string> = Keys | Keys[];
10
10
  * 子组件inherit字段约束,key为构建组件所需的properties字段,类型为根组件数据的key或key[]或`WXMLSign`。要求根数据类型为子数据类型的子类型。当key的值来自wxml(循环产生的子数据等情况)时用`WXMLSign`表示。
11
11
  * @returns object
12
12
  */
13
- export type InheritConstraint<AllRootData extends object, TComponentDoc extends ComponentDoc> = {
13
+ export type InheritConstraint<AllRootData extends object, TComponentDoc extends ComponentType> = {
14
14
  [k in keyof TComponentDoc["properties"]]?:
15
15
  | unionAddList<RemoveInnerData<SelectKeys<AllRootData, TComponentDoc["properties"][k]> & string>>
16
16
  | WXMLSign;
@@ -1,11 +1,11 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import { DefineComponent } from "../../../DefineComponent";
3
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
4
- import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
3
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
4
+ import type { RootComponentType } from "../../../RootComponent/RootComponentType";
5
5
  import { SubComponent } from "../..";
6
- import type { SubComponentDoc } from "../../SubComponentDoc";
6
+ import type { SubComponentType } from "../../SubComponentType";
7
7
 
8
- type Mock_RootDoc = RootComponentDoc<{
8
+ type Mock_RootDoc = RootComponentType<{
9
9
  properties: {
10
10
  required_num: number;
11
11
  optional_literal_num?: 123 | 456 | 789;
@@ -25,7 +25,7 @@ type Mock_RootDoc = RootComponentDoc<{
25
25
  };
26
26
  }>;
27
27
 
28
- type Mock_CompDoc = ComponentDoc<{
28
+ type Mock_CompDoc = ComponentType<{
29
29
  properties: {
30
30
  aaa_num: number;
31
31
  aaa_literal_num: 123 | 456;
@@ -55,7 +55,7 @@ const subDoc = SubComponent<Mock_RootDoc, Mock_CompDoc>()({
55
55
  },
56
56
  });
57
57
 
58
- void Checking<typeof subDoc, SubComponentDoc, Test.Fail>;
58
+ void Checking<typeof subDoc, SubComponentType, Test.Fail>;
59
59
 
60
60
  DefineComponent({
61
61
  name: "xxx",
@@ -1,11 +1,11 @@
1
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
- import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
1
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
2
+ import type { RootComponentType } from "../../../RootComponent/RootComponentType";
3
3
  import { SubComponent } from "../..";
4
4
 
5
5
  /**
6
6
  * inherit字段最终会在选项中删除,它用ts开发类型检测。
7
7
  */
8
- type Mock_RootDoc = RootComponentDoc<{
8
+ type Mock_RootDoc = RootComponentType<{
9
9
  properties: {
10
10
  required_num: number;
11
11
  optional_literal_num?: 123 | 456 | 789;
@@ -23,7 +23,7 @@ type Mock_RootDoc = RootComponentDoc<{
23
23
  };
24
24
  }>;
25
25
 
26
- type Mock_CompDoc = ComponentDoc<{
26
+ type Mock_CompDoc = ComponentType<{
27
27
  properties: {
28
28
  aaa_num: number;
29
29
  aaa_literal_num: 123 | 456;
@@ -65,3 +65,17 @@ SubComponent<Mock_RootDoc, Mock_CompDoc>()({
65
65
  aaa_obj1: "" as "required_obj" | "optional_obj" | ["required_obj" | "optional_obj"] | "wxml",
66
66
  },
67
67
  });
68
+
69
+ // 4. 实例上没有computed字段。
70
+ SubComponent<{}, Mock_CompDoc>()({
71
+ computed: {
72
+ aaa_num() {
73
+ return 1;
74
+ },
75
+ },
76
+ methods: {
77
+ aaa_meA() {
78
+ console.log(this.data.aaa_num);
79
+ },
80
+ },
81
+ });
@@ -1,8 +1,8 @@
1
1
  import type { View } from "../../../../thirdLib/wm";
2
- import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
2
+ import type { RootComponentType } from "../../../RootComponent/RootComponentType";
3
3
  import { SubComponent } from "../..";
4
4
 
5
- type RootDoc = RootComponentDoc<{
5
+ type RootDoc = RootComponentType<{
6
6
  events: {
7
7
  RootE1: () => string;
8
8
  };
@@ -1,13 +1,13 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
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
- import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
7
+ import type { RootComponentType } from "../../../RootComponent/RootComponentType";
8
8
  import { SubComponent } from "../..";
9
9
 
10
- type RootDoc = RootComponentDoc<{
10
+ type RootDoc = RootComponentType<{
11
11
  properties: {
12
12
  Pstr: string;
13
13
  Pobj: Mock_User | null;
@@ -30,7 +30,7 @@ type RootDoc = RootComponentDoc<{
30
30
  };
31
31
  }>;
32
32
 
33
- type CompDoc = ComponentDoc<{
33
+ type CompDoc = ComponentType<{
34
34
  properties: {
35
35
  aaa_str: string;
36
36
  };
@@ -1,9 +1,9 @@
1
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
1
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
2
2
  import type { Bubbles } from "../../../RootComponent/CustomEvents/CustomEventsTag";
3
- import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
3
+ import type { RootComponentType } from "../../../RootComponent/RootComponentType";
4
4
  import { SubComponent } from "../..";
5
5
 
6
- type RootDoc = RootComponentDoc<{
6
+ type RootDoc = RootComponentType<{
7
7
  methods: {
8
8
  Mstr: () => string;
9
9
  };
@@ -15,7 +15,7 @@ type RootDoc = RootComponentDoc<{
15
15
  };
16
16
  }>;
17
17
 
18
- type CompDoc = ComponentDoc<{
18
+ type CompDoc = ComponentType<{
19
19
  customEvents: {
20
20
  aaa_str: string | Bubbles;
21
21
  };
@@ -1,14 +1,14 @@
1
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
- import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
1
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
2
+ import type { RootComponentType } from "../../../RootComponent/RootComponentType";
3
3
  import { SubComponent } from "../..";
4
4
 
5
- type RootDoc = RootComponentDoc<{
5
+ type RootDoc = RootComponentType<{
6
6
  methods: {
7
7
  Mstr: () => string;
8
8
  };
9
9
  }>;
10
10
 
11
- type CompDoc = ComponentDoc<{
11
+ type CompDoc = ComponentType<{
12
12
  customEvents: {
13
13
  aaa_str: string;
14
14
  };
@@ -1,8 +1,8 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
3
3
  import { SubComponent } from "../..";
4
4
 
5
- type CompDoc = ComponentDoc<{
5
+ type CompDoc = ComponentType<{
6
6
  properties: {
7
7
  aaa_str: string;
8
8
  aaa_bool: boolean;
@@ -1,5 +1,5 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
3
3
  import type {
4
4
  Bubbles,
5
5
  BubblesCaptureComposed,
@@ -9,7 +9,7 @@ import type {
9
9
  } from "../../../RootComponent/CustomEvents/CustomEventsTag";
10
10
  import { SubComponent } from "../..";
11
11
 
12
- type CompDoc = ComponentDoc<{
12
+ type CompDoc = ComponentType<{
13
13
  properties: {
14
14
  aaa_str: string;
15
15
  };
@@ -1,13 +1,13 @@
1
1
  import { observable } from "mobx";
2
2
 
3
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
3
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
4
4
  import { SubComponent } from "../..";
5
5
  const user = observable({
6
6
  name: "zhao",
7
7
  age: 20,
8
8
  });
9
9
 
10
- type DocA = ComponentDoc<{
10
+ type DocA = ComponentType<{
11
11
  properties: {
12
12
  aaa_str: string;
13
13
  aaa_num: number;
@@ -1,13 +1,13 @@
1
1
  import { observable } from "mobx";
2
2
 
3
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
3
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
4
4
  import { SubComponent } from "../..";
5
5
  const user = observable({
6
6
  name: "zhao",
7
7
  age: 20,
8
8
  });
9
9
 
10
- type DocA = ComponentDoc<{
10
+ type DocA = ComponentType<{
11
11
  properties: {
12
12
  aaa_str: string;
13
13
  aaa_num: number;
@@ -1,10 +1,10 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
3
3
  import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
4
- import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
4
+ import type { RootComponentType } from "../../../RootComponent/RootComponentType";
5
5
  import { SubComponent } from "../..";
6
6
 
7
- type RootDoc = RootComponentDoc<{
7
+ type RootDoc = RootComponentType<{
8
8
  properties: {
9
9
  obj: Mock_User | null;
10
10
  };
@@ -16,7 +16,7 @@ type RootDoc = RootComponentDoc<{
16
16
  };
17
17
  }>;
18
18
 
19
- type CompDoc = ComponentDoc<{
19
+ type CompDoc = ComponentType<{
20
20
  properties: {
21
21
  aaa_obj: Mock_User | null;
22
22
  aaa_str: string;
@@ -1,6 +1,6 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
 
3
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
3
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
4
4
 
5
5
  import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
6
6
  import { SubComponent } from "../..";
@@ -9,7 +9,7 @@ interface TestObj {
9
9
  subObj: Mock_User;
10
10
  }
11
11
 
12
- type CompDoc = ComponentDoc<{
12
+ type CompDoc = ComponentType<{
13
13
  properties: {
14
14
  aaa_str: string;
15
15
  aaa_num: number;
@@ -1,8 +1,8 @@
1
1
  import { Checking, type Test } from "hry-types";
2
- import type { ComponentDoc } from "../../../DefineComponent/ReturnType/ComponentDoc";
2
+ import type { ComponentType } from "../../../DefineComponent/ReturnType/ComponentType";
3
3
  import { SubComponent } from "../..";
4
4
 
5
- type CompDoc = ComponentDoc<{
5
+ type CompDoc = ComponentType<{
6
6
  properties: {
7
7
  aaa_str: string;
8
8
  aaa_num: number;
@@ -2,20 +2,21 @@ import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
2
  import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
3
3
  import type { Func } from "hry-types/src/Misc/Func";
4
4
  import type { RequiredKeys } from "hry-types/src/Object/RequiredKeys";
5
+ import type { ComputeObject } from "../../types/ComputeObj";
5
6
  import type { GetComponentPrefix } from "../../types/GetComponentPrefix";
6
7
  import type { InnerFields } from "../../types/InnerData";
7
8
  import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
8
9
  import type { Replace } from "../../types/Replace";
9
10
  import type { ReplacePrefix } from "../../types/ReplacePrefix";
10
- import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
11
- import type { IInjectStore } from "../InstanceInject/instanceConfig";
11
+ import type { ComponentType } from "../DefineComponent/ReturnType/ComponentType";
12
+ import type { IInjectAllData, IInjectStore } from "../InstanceInject/instanceConfig";
12
13
  import type { ComputedConstraint } from "../RootComponent/Computed/ComputedConstraint";
13
14
  import type { DataConstraint } from "../RootComponent/Data/DataConstraint";
14
15
  import type { EventsConstraint } from "../RootComponent/Events/EventsConstraint";
15
16
  import type { LifetimesConstraint } from "../RootComponent/Lifetimes/LifetimesConstraint";
16
17
  import type { MethodsConstraint } from "../RootComponent/Methods/MethodsConstraint";
17
18
  import type { PageLifetimesOption } from "../RootComponent/PageLifetimes/PageLifetimesOption";
18
- import type { RootComponentDoc } from "../RootComponent/RootComponentDoc";
19
+ import type { RootComponentType } from "../RootComponent/RootComponentType";
19
20
  import type { StoreConstraint } from "../RootComponent/Store/StoreConstraint";
20
21
  import type { GetSubComputedDoc } from "./SubComputed/GetSubComputedDoc";
21
22
  import type { SubComputedConstraint } from "./SubComputed/SubComputedConstraint";
@@ -38,9 +39,9 @@ import type { SubStoreOption } from "./SubStore/SubStoreOption";
38
39
  import type { SubWatchOption } from "./SubWatch/SubWatchOption";
39
40
 
40
41
  type Options<
41
- RootDoc extends RootComponentDoc,
42
+ RootDoc extends RootComponentType,
42
43
  IsPage extends boolean,
43
- CurrentCompDoc extends ComponentDoc,
44
+ CurrentCompDoc extends ComponentType,
44
45
  Prefix extends string,
45
46
  AllRootDataDoc extends object,
46
47
  TInherit extends object,
@@ -71,7 +72,12 @@ type Options<
71
72
  & SubComputedOption<
72
73
  TSubComputed,
73
74
  // 合法的配置
74
- Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))> | InnerFields<Prefix>
75
+ Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))> | InnerFields<Prefix>,
76
+ {
77
+ data: ComputeObject<
78
+ AllRootDataDoc & Replace<SubComputedDoc, Required<CurrentCompDoc["properties"]>> & IInjectAllData
79
+ >;
80
+ }
75
81
  >
76
82
  // 无需与根组件的events字段重复检测,因为根组件多了bubbles字段,一定不会重复
77
83
  & SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>>
@@ -104,15 +110,15 @@ type Options<
104
110
  >;
105
111
 
106
112
  type SubComponentConstructor<
107
- TRootDoc extends RootComponentDoc,
108
- TOriginalCompDoc extends ComponentDoc,
113
+ TRootDoc extends RootComponentType,
114
+ TOriginalCompDoc extends ComponentType,
109
115
  // 补充的前缀
110
116
  TSupplementalPrefix extends string = "",
111
117
  IsPage extends boolean = TRootDoc["isPage"] extends true ? true : false,
112
118
  // 重构子组件的前缀
113
119
  CurrentPrefix extends string = `${GetComponentPrefix<TOriginalCompDoc>}${Capitalize<TSupplementalPrefix>}`,
114
120
  // 更新原始文档的前缀为Prefix
115
- CurrentCompDoc extends ComponentDoc = IfExtends<
121
+ CurrentCompDoc extends ComponentType = IfExtends<
116
122
  TSupplementalPrefix,
117
123
  "",
118
124
  TOriginalCompDoc,
@@ -228,8 +234,8 @@ type SubComponentConstructor<
228
234
  * @returns `(options:) => SubComponentDoc`
229
235
  */
230
236
  export function SubComponent<
231
- RootDoc extends RootComponentDoc,
232
- CompDoc extends ComponentDoc,
237
+ RootDoc extends RootComponentType,
238
+ CompDoc extends ComponentType,
233
239
  Prefix extends string = "",
234
240
  >(): IfExtends<EmptyObject, CompDoc, (opt: EmptyObject) => never, SubComponentConstructor<RootDoc, CompDoc, Prefix>> {
235
241
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1,38 +1,52 @@
1
1
  import type mobx from "mobx";
2
2
  import type { Instance } from "../api/RootComponent/Instance/RootComponentInstance";
3
+ import { deepEqual } from "../utils/deepEqual";
4
+ import { isEmptyObject } from "../utils/isEmptyObject";
5
+
6
+ function reactionRegister(this: Instance, storeConfig: Record<string, () => unknown>) {
7
+ const unequalData: Record<string, unknown> = {};
8
+ // eslint-disable-next-line @typescript-eslint/no-require-imports
9
+ const { comparer, reaction, toJS } = require("mobx") as typeof mobx;
10
+ // 存储reaction的disposer 需要保护内部字段验证
11
+ this.disposer = {};
12
+ for (const key in storeConfig) {
13
+ const currentStoreValue = toJS(storeConfig[key]());
14
+ /* istanbul ignore next 没办法测试啊,在打开一个页面后退回,修改store,再打开相同页面是会出现store数据不准确的问题*/
15
+ // @ts-ignore this.data[key]一定存在
16
+ if (!deepEqual(currentStoreValue, this.data[key])) {
17
+ unequalData[key] = currentStoreValue;
18
+ }
19
+ // 添加响应式逻辑
20
+ this.disposer[key] = reaction(
21
+ storeConfig[key],
22
+ (value: unknown) => {
23
+ this.setData({
24
+ [key]: toJS(value),
25
+ });
26
+ },
27
+ {
28
+ equals: comparer.structural,
29
+ },
30
+ );
31
+ }
32
+ delete this.data.__storeConfig__;
33
+ /* istanbul ignore next */
34
+ if (!isEmptyObject(unequalData)) this.setData(unequalData);
35
+ }
3
36
 
4
37
  /**
5
- * 在created生命周期中,初始化 store数据(__storeConfig__)到data中
38
+ * 在attached(1.7.5之前在created中)生命周期中,建立store数据的reaction
6
39
  * 在detached生命周期中,清除store数据
7
40
  */
8
41
  export const BStore = Behavior({
9
42
  lifetimes: {
10
- created(this: Instance) {
43
+ attached(this: Instance) {
44
+ // 此时store数据已初始化到data中(initStore)
11
45
  const storeConfig = this.data.__storeConfig__;
12
46
  if (!storeConfig) return;
13
47
 
14
- // eslint-disable-next-line @typescript-eslint/no-require-imports
15
- const { comparer, reaction, toJS } = require("mobx") as typeof mobx;
16
- // 存储reaction的disposer 需要冲突字段验证
17
- this.disposer = {};
18
- for (const key in storeConfig) {
19
- // 添加响应式逻辑
20
- this.disposer[key] = reaction(
21
- storeConfig[key],
22
- (value: unknown) => {
23
- // 加入到待setData对象中
24
- this.setData({
25
- [key]: toJS(value),
26
- });
27
- },
28
- {
29
- equals: comparer.structural,
30
- },
31
- );
32
- }
33
- delete this.data.__storeConfig__;
48
+ reactionRegister.call(this, storeConfig);
34
49
  },
35
-
36
50
  detached(this: Instance) {
37
51
  /* istanbul ignore next 清除store数据 test中模拟了测试,所以忽略 框架(1.6.1)不支持 issue {@link https://github.com/wechat-miniprogram/miniprogram-simulate/issues/110}*/
38
52
  for (const key in this.disposer) {
package/src/index.ts CHANGED
@@ -5,7 +5,7 @@ import { RootComponent } from "./api/RootComponent";
5
5
  import { SubComponent } from "./api/SubComponent";
6
6
  import type { CreateComponentType } from "./types/CreateComponentType";
7
7
  import type { DetailedType } from "./types/DetailedType";
8
- import type { DocAssign } from "./types/DocAssign";
8
+ import type { ExtendComponentType } from "./types/ExtendComponentType";
9
9
  import type { ParamsEqual } from "./types/TwoParamsEqual";
10
10
  export type { Vant, Wm } from "./thirdLib";
11
11
 
@@ -23,7 +23,7 @@ export {
23
23
  type CreateComponentType,
24
24
  DefineComponent,
25
25
  type DetailedType,
26
- type DocAssign,
26
+ type ExtendComponentType,
27
27
  type IInjectInfo,
28
28
  instanceConfig,
29
29
  navigateTo,
@@ -1,9 +1,30 @@
1
1
  import type { IfExtends } from "hry-types/src/Any/_api";
2
2
  import type { ComputeIntersection } from "hry-types/src/Object/_api";
3
- import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
3
+ import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
4
4
  import type { AddPrefix } from "./AddPrefix";
5
5
 
6
- export type CreateComponentType<TName extends string, T extends ComponentDoc> = ComputeIntersection<
6
+ /**
7
+ * 建立一个组件类型
8
+ * @param TName 组件名称
9
+ * @param T 类型配置
10
+ * @example
11
+ * ```ts
12
+ * type $CustomA = CreateComponentType<"customA", {
13
+ * properties: { num: string };
14
+ * customEvents: { onTap: string }
15
+ * }>;
16
+ *
17
+ * // 等同下面的类型
18
+ * type $CustomA = {
19
+ * properties: {
20
+ * customA_num: string;
21
+ * };
22
+ * customEvents: {
23
+ * customA_onTap: string;
24
+ * };
25
+ * ```
26
+ */
27
+ export type CreateComponentType<TName extends string, T extends ComponentType> = ComputeIntersection<
7
28
  & IfExtends<
8
29
  unknown,
9
30
  T["properties"],
@@ -0,0 +1,60 @@
1
+ import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
+ import type { ComputeIntersectionDeep } from "hry-types/src/Object/ComputeIntersectionDeep";
3
+ import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
4
+ import type { GetComponentPrefix } from "./GetComponentPrefix";
5
+
6
+ type Validator<
7
+ TOriginalComponentType extends ComponentType,
8
+ TExtensionType extends ComponentType,
9
+ TOriginalPrefix extends PropertyKey = GetComponentPrefix<TOriginalComponentType>,
10
+ TExtenstionPrefix extends PropertyKey = GetComponentPrefix<TExtensionType>,
11
+ DuplicateKeys extends PropertyKey =
12
+ | Extract<keyof TExtensionType["properties"], keyof TOriginalComponentType["properties"]>
13
+ | Extract<keyof TExtensionType["customEvents"], keyof TOriginalComponentType["customEvents"]>,
14
+ > = IfExtends<
15
+ TOriginalPrefix,
16
+ TExtenstionPrefix,
17
+ IfExtends<DuplicateKeys, never, ComponentType, `${DuplicateKeys & string}字段重复`>,
18
+ `前缀错误,应为${TOriginalPrefix & string}`
19
+ >;
20
+
21
+ /**
22
+ * 拓展组件类型
23
+ * @param TOriginalComponentType 原始组件类型
24
+ * @param TExtensionType 拓展类型
25
+ * @description 拓展类型必须与原始类型有相同的前缀
26
+ * @example
27
+ * ```ts
28
+ * type $CustomA = ExtendComponentType<
29
+ * { properties: { aaa_num: number };
30
+ * customEvents: { aaa_xxx: string }
31
+ * },
32
+ * { properties: { aaa_str: string };
33
+ * customEvents: { aaa_yyy: string }
34
+ * }>;
35
+ *
36
+ * // 等同下面的类型
37
+ * type $CustomA = {
38
+ * properties: {
39
+ * aaa_num: number;
40
+ * aaa_str: string;
41
+ * };
42
+ * customEvents: {
43
+ * aaa_xxx: string;
44
+ * aaa_yyy: string;
45
+ * };
46
+ * ```
47
+ */
48
+ export type ExtendComponentType<
49
+ TOriginalComponentType extends ComponentType,
50
+ // @ts-ignore
51
+ TExtensionType extends Validator<TOriginalComponentType, TExtensionType>,
52
+ > = ComputeIntersectionDeep<TOriginalComponentType & TExtensionType>;
53
+
54
+ // type test0 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
55
+
56
+ // type test1 = ExtendComponentType<{ customEvents: { aaa_xxx: string } }, { customEvents: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
57
+
58
+ // type test2 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
59
+
60
+ // type test3 = ExtendComponentType<{ customEvents: { aaa_xxx: string } }, { customEvents: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
@@ -1,12 +1,12 @@
1
1
  // import { Checking, type Test } from "hry-types";
2
2
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
3
3
  import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
4
- import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
4
+ import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
5
5
 
6
6
  /**
7
7
  * 提取文档前缀名
8
8
  */
9
- export type GetComponentPrefix<TComponentDoc extends ComponentDoc> = EmptyObject extends TComponentDoc ? never
9
+ export type GetComponentPrefix<TComponentDoc extends ComponentType> = EmptyObject extends TComponentDoc ? never
10
10
  : keyof IfExtends<
11
11
  unknown,
12
12
  TComponentDoc["properties"],
@@ -1,11 +1,11 @@
1
- import type { SubComponentDoc } from "../api/SubComponent/SubComponentDoc";
1
+ import type { SubComponentType } from "../api/SubComponent/SubComponentType";
2
2
 
3
3
  // 获取元组中properties字段的重复keys
4
4
  export type GetPropertiesDuplicatedKeys<
5
- O extends SubComponentDoc[],
5
+ O extends SubComponentType[],
6
6
  Comparekeys extends PropertyKey,
7
7
  Duplicatekey extends string = never,
8
- > = O extends [infer Head extends SubComponentDoc, ...infer Rest extends SubComponentDoc[]]
8
+ > = O extends [infer Head extends SubComponentType, ...infer Rest extends SubComponentType[]]
9
9
  ? GetPropertiesDuplicatedKeys<
10
10
  Rest,
11
11
  Comparekeys | keyof Head["properties"],