annil 1.3.0 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/CHANGELOG.md +31 -0
  2. package/README.md +28 -16
  3. package/dist/api/DefineComponent/collectOptionsForComponent.js +30 -11
  4. package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -1
  5. package/dist/api/DefineComponent/index.js.map +1 -1
  6. package/dist/api/InstanceInject/instanceConfig.d.ts +23 -0
  7. package/dist/api/InstanceInject/instanceConfig.js +13 -0
  8. package/dist/api/InstanceInject/instanceConfig.js.map +1 -0
  9. package/dist/api/InstanceInject/test/normal.test.d.ts +1 -0
  10. package/dist/api/InstanceInject/test/normal.test.js +30 -0
  11. package/dist/api/InstanceInject/test/normal.test.js.map +1 -0
  12. package/dist/api/RootComponent/Computed/test/normal.test.js.map +1 -1
  13. package/dist/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.js +0 -1
  14. package/dist/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.js.map +1 -1
  15. package/dist/api/RootComponent/CustomEvents/test/GetFullEventDoc.test.js +0 -1
  16. package/dist/api/RootComponent/CustomEvents/test/GetFullEventDoc.test.js.map +1 -1
  17. package/dist/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.js +0 -1
  18. package/dist/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.js.map +1 -1
  19. package/dist/api/RootComponent/Data/test/normal.test.js.map +1 -1
  20. package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +4 -4
  21. package/dist/api/RootComponent/Instance/test/properties/mormal.test.js.map +1 -1
  22. package/dist/api/RootComponent/Instance/test/setData/error.test.js +0 -8
  23. package/dist/api/RootComponent/Instance/test/setData/error.test.js.map +1 -1
  24. package/dist/api/RootComponent/Instance/test/setData/normal.test.js +0 -1
  25. package/dist/api/RootComponent/Instance/test/setData/normal.test.js.map +1 -1
  26. package/dist/api/RootComponent/Lifetimes/test/error.test.js +1 -1
  27. package/dist/api/RootComponent/Lifetimes/test/error.test.js.map +1 -1
  28. package/dist/api/RootComponent/Lifetimes/test/normal.test.js +1 -1
  29. package/dist/api/RootComponent/Lifetimes/test/normal.test.js.map +1 -1
  30. package/dist/api/RootComponent/Properties/test/normalEmpty.test.js.map +1 -1
  31. package/dist/api/RootComponent/Properties/test/normalOptional.test.js.map +1 -1
  32. package/dist/api/RootComponent/Properties/test/normalRequired.test.js.map +1 -1
  33. package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
  34. package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
  35. package/dist/api/SubComponent/SubInstance/test/normal.test.js.map +1 -1
  36. package/dist/api/navigateTo.js.map +1 -1
  37. package/dist/behaviors/BComputedAndWatch/data-tracer.js +3 -0
  38. package/dist/behaviors/BComputedAndWatch/data-tracer.js.map +1 -1
  39. package/dist/behaviors/BComputedAndWatch/getPropertiesValue.js.map +1 -1
  40. package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
  41. package/dist/behaviors/BComputedAndWatch/initComputed.js.map +1 -1
  42. package/dist/behaviors/BComputedAndWatch/isEqual.js.map +1 -1
  43. package/dist/behaviors/BComputedAndWatch/types.d.ts +0 -1
  44. package/dist/index.d.ts +2 -1
  45. package/dist/index.js +2 -1
  46. package/dist/index.js.map +1 -1
  47. package/dist/inject.d.ts +18 -0
  48. package/dist/inject.js +20 -0
  49. package/dist/inject.js.map +1 -0
  50. package/dist/thirdLib/index.js +1 -2
  51. package/dist/thirdLib/index.js.map +1 -1
  52. package/dist/types/Assign.d.ts +1 -0
  53. package/dist/types/Assign.js +2 -0
  54. package/dist/types/Assign.js.map +1 -0
  55. package/dist/types/OfficialTypeAlias.d.ts +1 -1
  56. package/package.json +5 -4
  57. package/src/api/DefineComponent/collectOptionsForComponent.ts +55 -11
  58. package/src/api/DefineComponent/index.ts +1 -0
  59. package/src/api/InstanceInject/instanceConfig.ts +39 -0
  60. package/src/api/InstanceInject/test/normal.test.ts +40 -0
  61. package/src/api/RootComponent/Computed/test/normal.test.ts +14 -11
  62. package/src/api/RootComponent/Data/test/normal.test.ts +4 -3
  63. package/src/api/RootComponent/Instance/RootComponentInstance.ts +4 -5
  64. package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +6 -1
  65. package/src/api/RootComponent/Instance/test/setData/error.test.ts +0 -10
  66. package/src/api/RootComponent/Instance/test/setData/normal.test.ts +0 -3
  67. package/src/api/RootComponent/Lifetimes/test/error.test.ts +1 -1
  68. package/src/api/RootComponent/Lifetimes/test/normal.test.ts +1 -1
  69. package/src/api/RootComponent/Properties/test/normalEmpty.test.ts +4 -2
  70. package/src/api/RootComponent/Properties/test/normalOptional.test.ts +11 -8
  71. package/src/api/RootComponent/Properties/test/normalRequired.test.ts +2 -1
  72. package/src/api/SubComponent/SubComputed/test/normal.test.ts +27 -22
  73. package/src/api/SubComponent/SubData/test/normal.test.ts +9 -6
  74. package/src/api/SubComponent/SubInstance/test/normal.test.ts +14 -11
  75. package/src/api/navigateTo.ts +1 -0
  76. package/src/behaviors/BComputedAndWatch/data-tracer.ts +5 -1
  77. package/src/behaviors/BComputedAndWatch/getPropertiesValue.ts +3 -0
  78. package/src/behaviors/BComputedAndWatch/index.ts +1 -0
  79. package/src/behaviors/BComputedAndWatch/initComputed.ts +1 -0
  80. package/src/behaviors/BComputedAndWatch/isEqual.ts +1 -0
  81. package/src/behaviors/BComputedAndWatch/types.ts +0 -1
  82. package/src/index.ts +3 -0
  83. package/src/inject.ts +34 -0
  84. package/src/types/Assign.ts +1 -0
  85. package/src/types/OfficialTypeAlias.ts +1 -1
  86. package/tsconfig.json +26 -0
  87. package/dist/api/InstanceInject/InstanceInject.d.ts +0 -0
  88. package/dist/api/InstanceInject/InstanceInject.js +0 -2
  89. package/dist/api/InstanceInject/InstanceInject.js.map +0 -1
  90. package/dist/api/InstanceInject/test/InjectConfig.d.ts +0 -0
  91. package/dist/api/InstanceInject/test/InjectConfig.js +0 -2
  92. package/dist/api/InstanceInject/test/InjectConfig.js.map +0 -1
  93. package/src/api/InstanceInject/InstanceInject.ts +0 -25
  94. package/src/api/InstanceInject/test/InjectConfig.ts +0 -50
@@ -2,6 +2,7 @@ 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
4
 
5
+ import { IInjectData } from "../../../InstanceInject/instanceConfig";
5
6
  import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
6
7
  import { SubComponent } from "../..";
7
8
 
@@ -80,17 +81,19 @@ SubComponent<Root, OnlyPropsCompDoc>()({
80
81
  // 5 this.data
81
82
  Checking<
82
83
  typeof this.data,
83
- ReadonlyDeep<{
84
- num: number;
85
- user: User | null;
86
- SNum: number;
87
- str: string;
88
- bool: boolean;
89
- aaa_num: number;
90
- aaa_num123: 123;
91
- aaa_str: "a";
92
- aaa_obj: Mock_User;
93
- }>,
84
+ ReadonlyDeep<
85
+ {
86
+ num: number;
87
+ user: User | null;
88
+ SNum: number;
89
+ str: string;
90
+ bool: boolean;
91
+ aaa_num: number;
92
+ aaa_num123: 123;
93
+ aaa_str: "a";
94
+ aaa_obj: Mock_User;
95
+ } & IInjectData
96
+ >,
94
97
  Test.Pass
95
98
  >;
96
99
 
@@ -102,17 +105,19 @@ SubComponent<Root, OnlyPropsCompDoc>()({
102
105
  // 5 this.data 深度只读
103
106
  Checking<
104
107
  typeof this.data,
105
- ReadonlyDeep<{
106
- num: number;
107
- user: User | null;
108
- str: string;
109
- SNum: number;
110
- bool: boolean;
111
- aaa_num: number;
112
- aaa_num123: 123;
113
- aaa_str: "a";
114
- aaa_obj: Mock_User;
115
- }>,
108
+ ReadonlyDeep<
109
+ {
110
+ num: number;
111
+ user: User | null;
112
+ str: string;
113
+ SNum: number;
114
+ bool: boolean;
115
+ aaa_num: number;
116
+ aaa_num123: 123;
117
+ aaa_str: "a";
118
+ aaa_obj: Mock_User;
119
+ } & IInjectData
120
+ >,
116
121
  Test.Pass
117
122
  >;
118
123
  },
@@ -2,6 +2,7 @@ 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
4
 
5
+ import { IInjectData } from "../../../InstanceInject/instanceConfig";
5
6
  import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
6
7
  import { SubComponent } from "../..";
7
8
 
@@ -51,12 +52,14 @@ SubComponent<{}, CompDoc>()({
51
52
  // 4 this.data中的data配置数据
52
53
  Checking<
53
54
  typeof this.data,
54
- ReadonlyDeep<{
55
- aaa_str: "a";
56
- aaa_num: 123;
57
- aaa_obj: null;
58
- _aaa_str: string;
59
- }>,
55
+ ReadonlyDeep<
56
+ {
57
+ aaa_str: "a";
58
+ aaa_num: 123;
59
+ aaa_obj: null;
60
+ _aaa_str: string;
61
+ } & IInjectData
62
+ >,
60
63
  Test.Pass
61
64
  >;
62
65
  },
@@ -2,6 +2,7 @@ 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
4
 
5
+ import { IInjectData } from "../../../InstanceInject/instanceConfig";
5
6
  import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
6
7
  import type { RootComponentDoc } from "../../../RootComponent/RootComponentDoc";
7
8
  import { SubComponent } from "../..";
@@ -57,17 +58,19 @@ SubComponent<RootDoc, CompDoc>()({
57
58
  // this.data
58
59
  Checking<
59
60
  typeof this.data,
60
- ReadonlyDeep<{
61
- // RootData
62
- Pstr: string;
63
- Pobj: Mock_User | null;
64
- PoptionalObj: Mock_User;
65
- Dnum: number;
66
- Cnum: number;
67
- // 自身Data
68
- aaa_str: "str";
69
- _aaa_SubReactive: 123;
70
- }>,
61
+ ReadonlyDeep<
62
+ {
63
+ // RootData
64
+ Pstr: string;
65
+ Pobj: Mock_User | null;
66
+ PoptionalObj: Mock_User;
67
+ Dnum: number;
68
+ Cnum: number;
69
+ // 自身Data
70
+ aaa_str: "str";
71
+ _aaa_SubReactive: 123;
72
+ } & IInjectData
73
+ >,
71
74
  Test.Pass
72
75
  >;
73
76
 
@@ -56,6 +56,7 @@ function _encodeURIComponent(
56
56
  export function navigateTo<TPageDoc extends PageDoc = never>(
57
57
  option: NoInfer<NavigateToOption<TPageDoc>>,
58
58
  ) {
59
+ // @ts-ignore 隐式索引
59
60
  if (!option["data"]) {
60
61
  return wx.navigateTo(option);
61
62
  } else {
@@ -11,7 +11,7 @@ export function deepProxy(
11
11
  // console.log(target, prop);
12
12
 
13
13
  if (prop === "__rawObject__") return target;
14
-
14
+ // @ts-ignore 隐式索引
15
15
  const val = target[prop];
16
16
 
17
17
  // console.log("获取依赖", prop, val);
@@ -42,6 +42,10 @@ export function deepProxy(
42
42
 
43
43
  return deepProxy(val, dependences, curPath);
44
44
  },
45
+ /* istanbul ignore next */
46
+ set(_target: object, prop: string) {
47
+ throw Error(`${prop}字段是只读的`);
48
+ },
45
49
  };
46
50
 
47
51
  return new Proxy(data, handler);
@@ -42,10 +42,13 @@ export function getPropertiesValue(propertiesOpt: PropertiesConstraint | undefin
42
42
  const config = propertiesOpt[key];
43
43
  /* istanbul ignore next */
44
44
  if (IsRequiredSingle(config)) {
45
+ // @ts-ignore 隐式索引
45
46
  result[key] = getRequiredSingleValue(config);
46
47
  } else if (IsRequiredUnion(config)) {
48
+ // @ts-ignore 隐式索引
47
49
  result[key] = getRequiredSingleValue(config.type);
48
50
  } else {
51
+ // @ts-ignore 隐式索引
49
52
  result[key] = config.value;
50
53
  }
51
54
  }
@@ -12,6 +12,7 @@ import type { Instance, WatchOldValue } from "./types";
12
12
  function initWatchOldValue(this: Instance, watchConfig: object): WatchOldValue {
13
13
  const watchOldValue = {};
14
14
  for (const key in watchConfig) {
15
+ // @ts-ignore 隐式索引
15
16
  watchOldValue[key] = deepClone(getPathsValue(this.data, key));
16
17
  }
17
18
 
@@ -113,6 +113,7 @@ export function initComputed(
113
113
 
114
114
  dataOpt[key] = itemCache.value;
115
115
 
116
+ // @ts-ignore 隐式索引
116
117
  initAllData[key] = itemCache.value;
117
118
 
118
119
  computedCache[key] = itemCache;
@@ -18,6 +18,7 @@ export function isEqual(value: unknown, other: unknown) {
18
18
  }
19
19
  // 递归比较存在的相同key是否相等
20
20
  for (const key of keys1) {
21
+ // @ts-ignore 隐式索引
21
22
  if (!keys2.includes(key) || !isEqual(value[key], other[key])) {
22
23
  return false;
23
24
  }
@@ -3,7 +3,6 @@ import type { ComponentInstance, PageInstance } from "../../api/RootComponent/In
3
3
  import type { ComputedDependence } from "./initComputed";
4
4
 
5
5
  export type InstanceCustomFields = {
6
- __pendingSetData__?: object | null;
7
6
  __storeConfig__?: () => Record<string, () => unknown>;
8
7
  __computedStatus__?: "待更新" | "更新完毕";
9
8
  __computedUpdater__: Func;
package/src/index.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import { DefineComponent } from "./api/DefineComponent";
2
+ import { type IInjectInfo, instanceConfig } from "./api/InstanceInject/instanceConfig";
2
3
  import { navigateTo } from "./api/navigateTo";
3
4
  import { RootComponent } from "./api/RootComponent";
4
5
  import { SubComponent } from "./api/SubComponent";
@@ -23,6 +24,8 @@ export {
23
24
  DefineComponent,
24
25
  type DetailedType,
25
26
  type GenerateDoc,
27
+ type IInjectInfo,
28
+ instanceConfig,
26
29
  /* istanbul ignore next */
27
30
  navigateTo,
28
31
  type ParamsEqual,
package/src/inject.ts ADDED
@@ -0,0 +1,34 @@
1
+ import { observable, runInAction } from "mobx";
2
+
3
+ // 注入的响应式数据;
4
+ const themeStore = observable({ theme: wx.getSystemInfoSync().theme });
5
+
6
+ wx.onThemeChange((Res) => {
7
+ runInAction(() => {
8
+ themeStore.theme = Res.theme;
9
+ });
10
+ });
11
+
12
+ // 注入的方法;
13
+ function injectMethod(data: string) {
14
+ return data;
15
+ }
16
+
17
+ const data = {
18
+ injectStr: "injectStr",
19
+ };
20
+ const methods = {
21
+ injectMethod,
22
+ };
23
+ const store = {
24
+ injectTheme: () => themeStore.theme,
25
+ };
26
+
27
+ // 声明注入类型 js开发可以忽略
28
+ declare module "./index" {
29
+ interface IInjectInfo {
30
+ data: typeof data;
31
+ store: typeof store;
32
+ methods: typeof methods;
33
+ }
34
+ }
@@ -0,0 +1 @@
1
+ export type Assign<O1, O2> = Omit<O1, keyof O2> & O2;
@@ -55,7 +55,7 @@ export type CurrentTargetDataset<T extends object> = WMCustomEvent<{}, {}, T>;
55
55
  */
56
56
  export type TargetDataset<TargetDataset extends object> = WMCustomEvent<{}, {}, {}, TargetDataset>;
57
57
 
58
- export type WMComponentOption = WechatMiniprogram.Component.TrivialOption;
58
+ export type WMComponentOption = WechatMiniprogram.Component.ComponentOptions;
59
59
 
60
60
  export type WMNavigateToSuccessCallbackResult = WechatMiniprogram.NavigateToSuccessCallbackResult;
61
61
 
package/tsconfig.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "compilerOptions": {
3
+ "lib": ["ES2022", "DOM"], // jest中用到了DOM类型
4
+ "target": "ES2017",
5
+ "module": "ES2022",
6
+ "strict": true,
7
+ "strictFunctionTypes": false, // e: Dataset<{ id: string }>会报错。
8
+ "exactOptionalPropertyTypes": true, // 带有?标志的属性类型不在包含undefined
9
+ "skipLibCheck": true, // 跳过声明文件的类型检查(.d.ts),除了你引用的, 默认false(不跳过)。
10
+ "moduleResolution": "Bundler", // 模块解析策略 //5.0 新值 bundler
11
+ "noImplicitAny": true, // 不允许隐式的any类型
12
+ "esModuleInterop": true, // 默认false 将 CommonJS/AMD/UMD 模块视为类似于 ES6 模块,jest需要。
13
+ "removeComments": true, // 去除注释
14
+ "noEmit": true,
15
+ "noImplicitReturns": true, // 隐式函数返回
16
+ "forceConsistentCasingInFileNames": true, // 区分文件名的大小写
17
+ // "noUnusedLocals": true, // 报告未使用局部变量的错误
18
+ // "noUnusedParameters": false, // 报告函数中未使用参数的错误
19
+ // "suppressImplicitAnyIndexErrors": true, // 为true关闭隐式索引错误,但很激进,建议使用@ts-ignore
20
+ "isolatedModules": true, // 模块化(.ts文件必须有导入或导出) 默认false
21
+ // "verbatimModuleSyntax": true,不能开启.jset会报错,在vscode中设置代替它要求ts版本>5.3
22
+ // 默认加载所有@types下的包 types指定具体的包,其他拒绝。包含上级目录
23
+ "types": ["hry-types", "mobx", "jest", "miniprogram-api-typings"]
24
+ },
25
+ "include": ["**/*.ts"]
26
+ }
File without changes
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=InstanceInject.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InstanceInject.js","sourceRoot":"","sources":["../../../src/api/InstanceInject/InstanceInject.ts"],"names":[],"mappings":""}
File without changes
@@ -1,2 +0,0 @@
1
- "use strict";
2
- //# sourceMappingURL=InjectConfig.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"InjectConfig.js","sourceRoot":"","sources":["../../../../src/api/InstanceInject/test/InjectConfig.ts"],"names":[],"mappings":""}
@@ -1,25 +0,0 @@
1
- // import type { WMComponentOption } from "../../types/officialAlias";
2
-
3
- // // export type InjectMethodConstraint = Record<string, Func>;
4
-
5
- // // export type InjectDataConstraint = Record<string, unknown>;
6
-
7
- // export abstract class Inject {
8
- // public options?: WMComponentOption;
9
- // // public methods?: InjectMethodConstraint;
10
- // // public data?: InjectDataConstraint;
11
- // }
12
-
13
- // /**
14
- // * 实例注入接口,加入数据到所有实例中(当前仅支持data,methods,options字段),可在this上获取对应数据 响应式需函数返回方式
15
- // * @example
16
- // */
17
- // export class InstanceInject extends Inject {
18
- // private static _injectOption = new InstanceInject();
19
- // public static get InjectOption(): InstanceInject {
20
- // return this._injectOption;
21
- // }
22
- // public static set InjectOption(options: InstanceInject) {
23
- // this._injectOption = options;
24
- // }
25
- // }
@@ -1,50 +0,0 @@
1
- // import { InstanceInject } from "../../..";
2
-
3
- // import { observable } from "mobx";
4
- // import type { InjectDataConstraint, InjectMethodConstraint } from "../InstanceInject";
5
-
6
- // const reactiveUser = observable({
7
- // name: "zhao",
8
- // age: 18,
9
- // });
10
-
11
- // /**
12
- // * @description 注入的data
13
- // */
14
- // const data = {
15
- // // 响应式数据
16
- // reactiveUser: () => reactiveUser,
17
- // // 非响应式数据
18
- // injectStr: "injectStr",
19
- // } satisfies InjectDataConstraint;
20
- // /**
21
- // * @description 注入的方法
22
- // */
23
- // const methods = {
24
- // injectMethod(data: string) {
25
- // console.log(data);
26
- // },
27
- // } satisfies InjectMethodConstraint;
28
- /**
29
- * 注入的配置
30
- */
31
- // const options = {
32
- // addGlobalClass: true,
33
- // multipleSlots: true,
34
- // pureDataPattern: /^_/,
35
- // virtualHost: true,
36
- // };
37
-
38
- // InstanceInject.InjectOption = {
39
- // // data,
40
- // options,
41
- // // methods,
42
- // };
43
-
44
- // 声明注入类型
45
- // declare module "../../.." {
46
- // interface InstanceInject {
47
- // data: typeof data;
48
- // methods: typeof methods;
49
- // }
50
- // }