annil 1.7.5-beta.4 → 1.7.5

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 (104) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/README.md +43 -37
  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/index.js +2 -2
  15. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js.map +1 -1
  16. package/dist/api/DefineComponent/normalizeOptions/index.js +1 -1
  17. package/dist/api/DefineComponent/normalizeOptions/index.js.map +1 -1
  18. package/dist/api/RootComponent/Events/EventsConstraint.d.ts +4 -4
  19. package/dist/api/RootComponent/{RootComponentDoc.d.ts → RootComponentType.d.ts} +16 -15
  20. package/dist/api/RootComponent/RootComponentType.js +2 -0
  21. package/dist/api/RootComponent/RootComponentType.js.map +1 -0
  22. package/dist/api/RootComponent/index.d.ts +3 -3
  23. package/dist/api/SubComponent/{SubComponentDoc.d.ts → SubComponentType.d.ts} +3 -3
  24. package/dist/api/SubComponent/SubComponentType.js +2 -0
  25. package/dist/api/SubComponent/SubComponentType.js.map +1 -0
  26. package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
  27. package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +2 -2
  28. package/dist/api/SubComponent/index.d.ts +5 -5
  29. package/dist/behaviors/BStore.d.ts +1 -1
  30. package/dist/behaviors/BStore.js +31 -18
  31. package/dist/behaviors/BStore.js.map +1 -1
  32. package/dist/index.d.ts +2 -2
  33. package/dist/types/CreateComponentType.d.ts +23 -2
  34. package/dist/types/ExtendComponentType.d.ts +34 -0
  35. package/dist/types/ExtendComponentType.js +6 -0
  36. package/dist/types/ExtendComponentType.js.map +1 -0
  37. package/dist/types/GetComponentPrefix.d.ts +2 -2
  38. package/dist/types/ReplacePrefix.d.ts +2 -2
  39. package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.d.ts → utils/deepEqual.d.ts} +1 -1
  40. package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js → utils/deepEqual.js} +3 -3
  41. package/dist/utils/deepEqual.js.map +1 -0
  42. package/package.json +2 -3
  43. package/src/api/DefineComponent/NameOrPage/test/error.test.ts +6 -6
  44. package/src/api/DefineComponent/ReturnType/{ComponentDoc.ts → ComponentType.ts} +6 -7
  45. package/src/api/DefineComponent/ReturnType/CreateComponentDoc.ts +4 -4
  46. package/src/api/DefineComponent/ReturnType/CreatePageDoc.ts +2 -2
  47. package/src/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.ts +3 -3
  48. package/src/api/DefineComponent/ReturnType/GetPropertiesDocOfSubDoc.ts +3 -3
  49. package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +5 -5
  50. package/src/api/DefineComponent/RootComponent/RootComponentOption.ts +2 -2
  51. package/src/api/DefineComponent/SubComponents/SubComponentsOption.ts +2 -2
  52. package/src/api/DefineComponent/SubComponents/test/normal.test.ts +3 -3
  53. package/src/api/DefineComponent/index.ts +7 -7
  54. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.ts +2 -2
  55. package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/index.ts +2 -2
  56. package/src/api/DefineComponent/normalizeOptions/index.ts +1 -1
  57. package/src/api/RootComponent/Events/EventsConstraint.ts +5 -5
  58. package/src/api/RootComponent/Events/test/normal.test.ts +5 -5
  59. package/src/api/RootComponent/{RootComponentDoc.ts → RootComponentType.ts} +16 -15
  60. package/src/api/RootComponent/index.ts +3 -3
  61. package/src/api/SubComponent/{SubComponentDoc.ts → SubComponentType.ts} +3 -3
  62. package/src/api/SubComponent/SubComputed/test/error.test.ts +3 -3
  63. package/src/api/SubComponent/SubComputed/test/normal.test.ts +4 -4
  64. package/src/api/SubComponent/SubData/test/error.test.ts +3 -3
  65. package/src/api/SubComponent/SubData/test/normal.test.ts +2 -2
  66. package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +2 -2
  67. package/src/api/SubComponent/SubEvents/test/error.test.ts +3 -3
  68. package/src/api/SubComponent/SubEvents/test/normal.test.ts +2 -2
  69. package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +2 -2
  70. package/src/api/SubComponent/SubInherit/test/error.test.ts +6 -6
  71. package/src/api/SubComponent/SubInherit/test/normal.test.ts +4 -4
  72. package/src/api/SubComponent/SubInstance/test/error.test.ts +2 -2
  73. package/src/api/SubComponent/SubInstance/test/normal.test.ts +4 -4
  74. package/src/api/SubComponent/SubMethods/test/error.test.ts +4 -4
  75. package/src/api/SubComponent/SubMethods/test/normarl.test.ts +4 -4
  76. package/src/api/SubComponent/SubReturnType/test/error.test.ts +2 -2
  77. package/src/api/SubComponent/SubReturnType/test/normal.test.ts +2 -2
  78. package/src/api/SubComponent/SubStore/test/error.test.ts +2 -2
  79. package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -2
  80. package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +4 -4
  81. package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +2 -2
  82. package/src/api/SubComponent/SubWatch/test/WatchSubData.test.ts +2 -2
  83. package/src/api/SubComponent/index.ts +9 -9
  84. package/src/behaviors/BStore.ts +35 -23
  85. package/src/index.ts +2 -2
  86. package/src/types/CreateComponentType.ts +23 -2
  87. package/src/types/ExtendComponentType.ts +60 -0
  88. package/src/types/GetComponentPrefix.ts +2 -2
  89. package/src/types/GetPropertiesDuplicatedKeys.ts +3 -3
  90. package/src/types/ReplacePrefix.ts +2 -2
  91. package/src/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.ts → utils/deepEqual.ts} +2 -3
  92. package/dist/api/DefineComponent/ReturnType/ComponentDoc.d.ts +0 -18
  93. package/dist/api/DefineComponent/ReturnType/ComponentDoc.js +0 -2
  94. package/dist/api/DefineComponent/ReturnType/ComponentDoc.js.map +0 -1
  95. package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js.map +0 -1
  96. package/dist/api/RootComponent/RootComponentDoc.js +0 -2
  97. package/dist/api/RootComponent/RootComponentDoc.js.map +0 -1
  98. package/dist/api/SubComponent/SubComponentDoc.js +0 -2
  99. package/dist/api/SubComponent/SubComponentDoc.js.map +0 -1
  100. package/dist/types/DocAssign.d.ts +0 -10
  101. package/dist/types/DocAssign.js +0 -6
  102. package/dist/types/DocAssign.js.map +0 -1
  103. package/src/types/DocAssign.ts +0 -36
  104. package/tsconfig.json +0 -23
@@ -7,7 +7,7 @@ import type { InnerFields } from "../../types/InnerData";
7
7
  import type { WMCompOtherOption } from "../../types/OfficialTypeAlias";
8
8
  import type { Replace } from "../../types/Replace";
9
9
  import type { ReplacePrefix } from "../../types/ReplacePrefix";
10
- import type { ComponentDoc } from "../DefineComponent/ReturnType/ComponentDoc";
10
+ import type { ComponentType } from "../DefineComponent/ReturnType/ComponentType";
11
11
  import type { IInjectStore } from "../InstanceInject/instanceConfig";
12
12
  import type { ComputedConstraint } from "../RootComponent/Computed/ComputedConstraint";
13
13
  import type { DataConstraint } from "../RootComponent/Data/DataConstraint";
@@ -15,7 +15,7 @@ import type { EventsConstraint } from "../RootComponent/Events/EventsConstraint"
15
15
  import type { LifetimesConstraint } from "../RootComponent/Lifetimes/LifetimesConstraint";
16
16
  import type { MethodsConstraint } from "../RootComponent/Methods/MethodsConstraint";
17
17
  import type { PageLifetimesOption } from "../RootComponent/PageLifetimes/PageLifetimesOption";
18
- import type { RootComponentDoc } from "../RootComponent/RootComponentDoc";
18
+ import type { RootComponentType } from "../RootComponent/RootComponentType";
19
19
  import type { StoreConstraint } from "../RootComponent/Store/StoreConstraint";
20
20
  import type { GetSubComputedDoc } from "./SubComputed/GetSubComputedDoc";
21
21
  import type { SubComputedConstraint } from "./SubComputed/SubComputedConstraint";
@@ -38,9 +38,9 @@ import type { SubStoreOption } from "./SubStore/SubStoreOption";
38
38
  import type { SubWatchOption } from "./SubWatch/SubWatchOption";
39
39
 
40
40
  type Options<
41
- RootDoc extends RootComponentDoc,
41
+ RootDoc extends RootComponentType,
42
42
  IsPage extends boolean,
43
- CurrentCompDoc extends ComponentDoc,
43
+ CurrentCompDoc extends ComponentType,
44
44
  Prefix extends string,
45
45
  AllRootDataDoc extends object,
46
46
  TInherit extends object,
@@ -104,15 +104,15 @@ type Options<
104
104
  >;
105
105
 
106
106
  type SubComponentConstructor<
107
- TRootDoc extends RootComponentDoc,
108
- TOriginalCompDoc extends ComponentDoc,
107
+ TRootDoc extends RootComponentType,
108
+ TOriginalCompDoc extends ComponentType,
109
109
  // 补充的前缀
110
110
  TSupplementalPrefix extends string = "",
111
111
  IsPage extends boolean = TRootDoc["isPage"] extends true ? true : false,
112
112
  // 重构子组件的前缀
113
113
  CurrentPrefix extends string = `${GetComponentPrefix<TOriginalCompDoc>}${Capitalize<TSupplementalPrefix>}`,
114
114
  // 更新原始文档的前缀为Prefix
115
- CurrentCompDoc extends ComponentDoc = IfExtends<
115
+ CurrentCompDoc extends ComponentType = IfExtends<
116
116
  TSupplementalPrefix,
117
117
  "",
118
118
  TOriginalCompDoc,
@@ -228,8 +228,8 @@ type SubComponentConstructor<
228
228
  * @returns `(options:) => SubComponentDoc`
229
229
  */
230
230
  export function SubComponent<
231
- RootDoc extends RootComponentDoc,
232
- CompDoc extends ComponentDoc,
231
+ RootDoc extends RootComponentType,
232
+ CompDoc extends ComponentType,
233
233
  Prefix extends string = "",
234
234
  >(): IfExtends<EmptyObject, CompDoc, (opt: EmptyObject) => never, SubComponentConstructor<RootDoc, CompDoc, Prefix>> {
235
235
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -1,38 +1,50 @@
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
+ // @ts-ignore this.data[key]一定存在
15
+ if (!deepEqual(currentStoreValue, this.data[key])) {
16
+ unequalData[key] = currentStoreValue;
17
+ }
18
+ // 添加响应式逻辑
19
+ this.disposer[key] = reaction(
20
+ storeConfig[key],
21
+ (value: unknown) => {
22
+ this.setData({
23
+ [key]: toJS(value),
24
+ });
25
+ },
26
+ {
27
+ equals: comparer.structural,
28
+ },
29
+ );
30
+ }
31
+ delete this.data.__storeConfig__;
32
+ if (!isEmptyObject(unequalData)) this.setData(unequalData);
33
+ }
3
34
 
4
35
  /**
5
- * 在created生命周期中,初始化 store数据(__storeConfig__)到data中
36
+ * 在attached(1.7.5之前在created中)生命周期中,建立store数据的reaction
6
37
  * 在detached生命周期中,清除store数据
7
38
  */
8
39
  export const BStore = Behavior({
9
40
  lifetimes: {
10
- created(this: Instance) {
41
+ attached(this: Instance) {
42
+ // 此时store数据已初始化到data中(initStore)
11
43
  const storeConfig = this.data.__storeConfig__;
12
44
  if (!storeConfig) return;
13
45
 
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__;
46
+ reactionRegister.call(this, storeConfig);
34
47
  },
35
-
36
48
  detached(this: Instance) {
37
49
  /* istanbul ignore next 清除store数据 test中模拟了测试,所以忽略 框架(1.6.1)不支持 issue {@link https://github.com/wechat-miniprogram/miniprogram-simulate/issues/110}*/
38
50
  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"],
@@ -1,5 +1,5 @@
1
1
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
- import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
2
+ import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
3
3
  // import type { ComponentDoc } from "../api/DefineComponent/CreateDoc/ComponentDoc";
4
4
 
5
5
  type _ReplacePrefix<O, TPrefix extends string> = {
@@ -11,7 +11,7 @@ type _ReplacePrefix<O, TPrefix extends string> = {
11
11
  * @param TComponentDoc - ComponentDoc
12
12
  * @returns ComponentDoc
13
13
  */
14
- export type ReplacePrefix<TComponentDoc extends ComponentDoc, TPrefix extends string = ""> =
14
+ export type ReplacePrefix<TComponentDoc extends ComponentType, TPrefix extends string = ""> =
15
15
  & IfExtends<
16
16
  unknown,
17
17
  TComponentDoc["properties"],
@@ -30,14 +30,13 @@ function isSamePattern(a: RegExp, b: RegExp) {
30
30
  * 两个函数使用toString()比较
31
31
  * 支持Date,RegExp
32
32
  */
33
- export function isEqual(a: unknown, b: unknown) {
33
+ export function deepEqual(a: unknown, b: unknown) {
34
34
  // 如果两个值是原始类型或null,直接用Object.is比较
35
35
  if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
36
36
  if (typeof a !== "function" || typeof b !== "function") {
37
37
  return Object.is(a, b);
38
38
  }
39
39
  }
40
-
41
40
  // 如果两个值是对象类型,先判断它们的类型、构造函数和属性数量是否相同
42
41
  if (!isSameType(a, b) || a.constructor !== b.constructor || !isSameSize(a, b)) {
43
42
  return false;
@@ -67,7 +66,7 @@ export function isEqual(a: unknown, b: unknown) {
67
66
  for (const key of keysA) {
68
67
  if (keysB.includes(key)) {
69
68
  // @ts-ignore
70
- if (!isEqual(a[key], b[key])) {
69
+ if (!deepEqual(a[key], b[key])) {
71
70
  return false;
72
71
  }
73
72
  } else {
@@ -1,18 +0,0 @@
1
- type PrefixKeys = `${string}_${string}`;
2
- type _ComponentDoc = {
3
- properties?: Record<PrefixKeys, any>;
4
- customEvents?: Record<PrefixKeys, any>;
5
- };
6
- type Error = "{ properties?: Record<PrefixKeys, any>; customEvents?: Record<PrefixKeys, any>;}";
7
- type _Validator<O> = keyof O extends keyof _ComponentDoc ? keyof (O["properties"] & O["customEvents"]) extends PrefixKeys ? _ComponentDoc : Error : Error;
8
- /**
9
- * RootComponent Api 返回的类型
10
- * ```ts
11
- * RootComponentDoc = {
12
- * properties?: Record<PrefixKeys, any>;
13
- * customEvents?: Record<PrefixKeys, any>;
14
- * };
15
- * ```
16
- */
17
- export type ComponentDoc<O extends _Validator<O> = _ComponentDoc> = O;
18
- export {};
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=ComponentDoc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"ComponentDoc.js","sourceRoot":"","sources":["../../../../src/api/DefineComponent/ReturnType/ComponentDoc.ts"],"names":[],"mappings":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"isEqual.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.ts"],"names":[],"mappings":"AAAA,SAAS,UAAU,CAAC,CA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CAAC"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=RootComponentDoc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"RootComponentDoc.js","sourceRoot":"","sources":["../../../src/api/RootComponent/RootComponentDoc.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=SubComponentDoc.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SubComponentDoc.js","sourceRoot":"","sources":["../../../src/api/SubComponent/SubComponentDoc.ts"],"names":[],"mappings":""}
@@ -1,10 +0,0 @@
1
- import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
- import type { ComputeIntersectionDeep } from "hry-types/src/Object/ComputeIntersectionDeep";
3
- import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
4
- import type { GetComponentPrefix } from "./GetComponentPrefix";
5
- type Validator<TOriginalComponentDoc extends ComponentDoc, TExtensionDoc extends ComponentDoc, TOriginalPrefix extends PropertyKey = GetComponentPrefix<TOriginalComponentDoc>, TExtenstionPrefix extends PropertyKey = GetComponentPrefix<TExtensionDoc>, DuplicateKeys extends PropertyKey = Extract<keyof TExtensionDoc["properties"], keyof TOriginalComponentDoc["properties"]> | Extract<keyof TExtensionDoc["customEvents"], keyof TOriginalComponentDoc["customEvents"]>> = IfExtends<TOriginalPrefix, TExtenstionPrefix, IfExtends<DuplicateKeys, never, ComponentDoc, `${DuplicateKeys & string}字段重复`>, `前缀错误,应为${TOriginalPrefix & string}`>;
6
- /**
7
- * 有时组件文档内部包含一些slot或基本组件,可通过CompDocExtends泛型拓展组件文档,使得类型更安全
8
- */
9
- export type DocAssign<TOriginalComponentDoc extends ComponentDoc, TExtensionDoc extends Validator<TOriginalComponentDoc, TExtensionDoc>> = ComputeIntersectionDeep<TOriginalComponentDoc & TExtensionDoc>;
10
- export {};
@@ -1,6 +0,0 @@
1
- export {};
2
- // type test0 = DocAssign<{ properties: { aaa_xxx: string } }, { properties: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
3
- // type test1 = DocAssign<{ customEvents: { aaa_xxx: string } }, { customEvents: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
4
- // type test2 = DocAssign<{ properties: { aaa_xxx: string } }, { properties: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
5
- // type test3 = DocAssign<{ customEvents: { aaa_xxx: string } }, { customEvents: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
6
- //# sourceMappingURL=DocAssign.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"DocAssign.js","sourceRoot":"","sources":["../../src/types/DocAssign.ts"],"names":[],"mappings":";AA6BA,wHAAwH;AAExH,4HAA4H;AAE5H,uHAAuH;AAEvH,2HAA2H"}
@@ -1,36 +0,0 @@
1
- import type { IfExtends } from "hry-types/src/Any/IfExtends";
2
- import type { ComputeIntersectionDeep } from "hry-types/src/Object/ComputeIntersectionDeep";
3
- import type { ComponentDoc } from "../api/DefineComponent/ReturnType/ComponentDoc";
4
- import type { GetComponentPrefix } from "./GetComponentPrefix";
5
-
6
- type Validator<
7
- TOriginalComponentDoc extends ComponentDoc,
8
- TExtensionDoc extends ComponentDoc,
9
- TOriginalPrefix extends PropertyKey = GetComponentPrefix<TOriginalComponentDoc>,
10
- TExtenstionPrefix extends PropertyKey = GetComponentPrefix<TExtensionDoc>,
11
- DuplicateKeys extends PropertyKey =
12
- | Extract<keyof TExtensionDoc["properties"], keyof TOriginalComponentDoc["properties"]>
13
- | Extract<keyof TExtensionDoc["customEvents"], keyof TOriginalComponentDoc["customEvents"]>,
14
- > = IfExtends<
15
- TOriginalPrefix,
16
- TExtenstionPrefix,
17
- IfExtends<DuplicateKeys, never, ComponentDoc, `${DuplicateKeys & string}字段重复`>,
18
- `前缀错误,应为${TOriginalPrefix & string}`
19
- >;
20
-
21
- /**
22
- * 有时组件文档内部包含一些slot或基本组件,可通过CompDocExtends泛型拓展组件文档,使得类型更安全
23
- */
24
- export type DocAssign<
25
- TOriginalComponentDoc extends ComponentDoc,
26
- // @ts-ignore
27
- TExtensionDoc extends Validator<TOriginalComponentDoc, TExtensionDoc>,
28
- > = ComputeIntersectionDeep<TOriginalComponentDoc & TExtensionDoc>;
29
-
30
- // type test0 = DocAssign<{ properties: { aaa_xxx: string } }, { properties: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
31
-
32
- // type test1 = DocAssign<{ customEvents: { aaa_xxx: string } }, { customEvents: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
33
-
34
- // type test2 = DocAssign<{ properties: { aaa_xxx: string } }, { properties: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
35
-
36
- // type test3 = DocAssign<{ customEvents: { aaa_xxx: string } }, { customEvents: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
package/tsconfig.json DELETED
@@ -1,23 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "lib": ["ES2022", "DOM"], // jest中用到了DOM类型
4
- "target": "ES2017",
5
- "module": "ES2022",
6
- "moduleResolution": "Node",
7
- "skipLibCheck": true, // 跳过声明文件的类型检查(.d.ts),你引用的依然会检查, 默认false(不跳过)。
8
- "esModuleInterop": true, // 默认false. 兼容非ES模块引用的写法(如 import fs from 'fs').
9
- "allowSyntheticDefaultImports": true, // 默认false. 允许从没有设置默认导出的模块中默认导入。
10
- "strict": true,
11
- "noEmit": true, // 不生成输出文件。
12
- // "resolveJsonModule": true, // 允许导入json模块。
13
- // "experimentalDecorators": true, // 启用装饰器,如@observable 小程序当前还不支持
14
- "strictFunctionTypes": false, // e: Dataset<{ id: string }>会报错。
15
- "forceConsistentCasingInFileNames": true,
16
- "exactOptionalPropertyTypes": true, // 带有?标志的属性类型不在包含undefined类型
17
- "noImplicitReturns": true, // 当启用时,TypeScript会检查函数中的所有代码路径,以确保它们返回值
18
- "isolatedModules": true, // 模块化(.ts文件必须有导入或导出) 默认false
19
- // "verbatimModuleSyntax": true, // 5.0后新增配置,替代preserveValueImports。
20
- "types": ["hry-types", "mobx", "jest", "miniprogram-api-typings"]
21
- },
22
- "include": ["**/*.ts"]
23
- }