annil 1.4.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 (68) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +4 -4
  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/Data/test/normal.test.js.map +1 -1
  14. package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +4 -4
  15. package/dist/api/RootComponent/Instance/test/properties/mormal.test.js.map +1 -1
  16. package/dist/api/RootComponent/Instance/test/setData/error.test.js +0 -8
  17. package/dist/api/RootComponent/Instance/test/setData/error.test.js.map +1 -1
  18. package/dist/api/RootComponent/Instance/test/setData/normal.test.js +0 -1
  19. package/dist/api/RootComponent/Instance/test/setData/normal.test.js.map +1 -1
  20. package/dist/api/RootComponent/Properties/test/normalEmpty.test.js.map +1 -1
  21. package/dist/api/RootComponent/Properties/test/normalOptional.test.js.map +1 -1
  22. package/dist/api/RootComponent/Properties/test/normalRequired.test.js.map +1 -1
  23. package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
  24. package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
  25. package/dist/api/SubComponent/SubInstance/test/normal.test.js.map +1 -1
  26. package/dist/behaviors/BComputedAndWatch/data-tracer.js.map +1 -1
  27. package/dist/behaviors/BComputedAndWatch/types.d.ts +0 -1
  28. package/dist/index.d.ts +2 -1
  29. package/dist/index.js +2 -1
  30. package/dist/index.js.map +1 -1
  31. package/dist/inject.d.ts +18 -0
  32. package/dist/inject.js +20 -0
  33. package/dist/inject.js.map +1 -0
  34. package/dist/types/Assign.d.ts +1 -0
  35. package/dist/types/Assign.js +2 -0
  36. package/dist/types/Assign.js.map +1 -0
  37. package/dist/types/OfficialTypeAlias.d.ts +1 -1
  38. package/package.json +2 -4
  39. package/src/api/DefineComponent/collectOptionsForComponent.ts +47 -11
  40. package/src/api/DefineComponent/index.ts +1 -0
  41. package/src/api/InstanceInject/instanceConfig.ts +39 -0
  42. package/src/api/InstanceInject/test/normal.test.ts +40 -0
  43. package/src/api/RootComponent/Computed/test/normal.test.ts +14 -11
  44. package/src/api/RootComponent/Data/test/normal.test.ts +4 -3
  45. package/src/api/RootComponent/Instance/RootComponentInstance.ts +4 -5
  46. package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +6 -1
  47. package/src/api/RootComponent/Instance/test/setData/error.test.ts +0 -10
  48. package/src/api/RootComponent/Instance/test/setData/normal.test.ts +0 -3
  49. package/src/api/RootComponent/Properties/test/normalEmpty.test.ts +4 -2
  50. package/src/api/RootComponent/Properties/test/normalOptional.test.ts +11 -8
  51. package/src/api/RootComponent/Properties/test/normalRequired.test.ts +2 -1
  52. package/src/api/SubComponent/SubComputed/test/normal.test.ts +27 -22
  53. package/src/api/SubComponent/SubData/test/normal.test.ts +9 -6
  54. package/src/api/SubComponent/SubInstance/test/normal.test.ts +14 -11
  55. package/src/behaviors/BComputedAndWatch/data-tracer.ts +1 -0
  56. package/src/behaviors/BComputedAndWatch/types.ts +0 -1
  57. package/src/index.ts +3 -0
  58. package/src/inject.ts +34 -0
  59. package/src/types/Assign.ts +1 -0
  60. package/src/types/OfficialTypeAlias.ts +1 -1
  61. package/dist/api/InstanceInject/InstanceInject.d.ts +0 -0
  62. package/dist/api/InstanceInject/InstanceInject.js +0 -2
  63. package/dist/api/InstanceInject/InstanceInject.js.map +0 -1
  64. package/dist/api/InstanceInject/test/InjectConfig.d.ts +0 -0
  65. package/dist/api/InstanceInject/test/InjectConfig.js +0 -2
  66. package/dist/api/InstanceInject/test/InjectConfig.js.map +0 -1
  67. package/src/api/InstanceInject/InstanceInject.ts +0 -25
  68. package/src/api/InstanceInject/test/InjectConfig.ts +0 -50
@@ -0,0 +1,39 @@
1
+ /* eslint-disable @typescript-eslint/explicit-member-accessibility */
2
+
3
+ import { ReturnTypeInObject } from "hry-types/src/Object/ReturnTypeInObject";
4
+ import { WMComponentOption } from "../../types/OfficialTypeAlias";
5
+ import { DataConstraint } from "../RootComponent/Data/DataConstraint";
6
+ import { MethodsConstraint } from "../RootComponent/Methods/MethodsConstraint";
7
+ import { StoreConstraint } from "../RootComponent/Store/StoreConstraint";
8
+
9
+ // 利用继承的多态性 使得IInjectInfo类型可由使用者外部定义
10
+ interface BaseInjectInfo {
11
+ options?: WMComponentOption;
12
+ methods?: MethodsConstraint;
13
+ data?: DataConstraint;
14
+ store?: StoreConstraint;
15
+ behaviors?: string[];
16
+ }
17
+
18
+ // eslint-disable-next-line @typescript-eslint/no-empty-interface
19
+ export interface IInjectInfo extends BaseInjectInfo {
20
+ }
21
+
22
+ export type IInjectData = IInjectInfo["data"] & ReturnTypeInObject<IInjectInfo["store"]>;
23
+
24
+ export type IInjectMethods = IInjectInfo["methods"];
25
+
26
+ /**
27
+ * 实例配置接口
28
+ */
29
+ class InstanceConfig {
30
+ private info: { injectInfo?: IInjectInfo } = {};
31
+ public get injectInfo() {
32
+ return this.info.injectInfo;
33
+ }
34
+ public setInjectInfo(info: IInjectInfo | undefined) {
35
+ info && (this.info.injectInfo = info);
36
+ }
37
+ }
38
+
39
+ export const instanceConfig = new InstanceConfig();
@@ -0,0 +1,40 @@
1
+ import { Checking, Test } from "hry-types";
2
+ import { RootComponent } from "../../RootComponent";
3
+
4
+ // 1. 注入字段无重复时
5
+ RootComponent()({
6
+ methods: {
7
+ testInjectTypes() {
8
+ Checking<typeof this.data.injectStr, string, Test.Pass>;
9
+
10
+ Checking<typeof this.data.injectTheme, "dark" | "light" | undefined, Test.Pass>;
11
+
12
+ Checking<typeof this.injectMethod, (data: string) => string, Test.Pass>;
13
+ },
14
+ },
15
+ });
16
+
17
+ // 2. 注入字段重复时,自身覆盖注入类型
18
+ RootComponent()({
19
+ data: {
20
+ // 覆盖注入的数据类型
21
+ injectStr: 123,
22
+ },
23
+ store: {
24
+ // 覆盖注入的数据类型
25
+ injectTheme: (() => "aaa") as () => "aaa",
26
+ },
27
+ methods: {
28
+ // 覆盖注入的方法类型
29
+ injectMethod() {
30
+ return 123;
31
+ },
32
+ testInjectTypes() {
33
+ Checking<typeof this.data.injectStr, number, Test.Pass>;
34
+
35
+ Checking<typeof this.data.injectTheme, "aaa", Test.Pass>;
36
+
37
+ Checking<typeof this.injectMethod, () => 123, Test.Pass>;
38
+ },
39
+ },
40
+ });
@@ -1,5 +1,6 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
+ import { IInjectData } from "../../../InstanceInject/instanceConfig";
3
4
  import { RootComponent } from "../..";
4
5
  import type { Mock_User } from "../../Properties/test/normalRequired.test";
5
6
 
@@ -29,15 +30,17 @@ const RootDoc = RootComponent()({
29
30
  // 3 this.data 类型是深度只读的
30
31
  Checking<
31
32
  typeof this.data,
32
- ReadonlyDeep<{
33
- firstName: string;
34
- lastName: string;
35
- fullName: string;
36
- user: Mock_User;
37
- prefix: string;
38
- id_fullName: string;
39
- readOnly: "str";
40
- }>,
33
+ ReadonlyDeep<
34
+ {
35
+ firstName: string;
36
+ lastName: string;
37
+ fullName: string;
38
+ user: Mock_User;
39
+ prefix: string;
40
+ id_fullName: string;
41
+ readOnly: "str";
42
+ } & IInjectData
43
+ >,
41
44
  Test.Pass
42
45
  >;
43
46
 
@@ -66,7 +69,7 @@ const noComputedFieldDoc = RootComponent()({
66
69
  methods: {
67
70
  M1() {
68
71
  // 5.1 无computed,this.data中为{}
69
- Checking<typeof this.data, {}, Test.Pass>;
72
+ Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
70
73
  },
71
74
  },
72
75
  });
@@ -81,7 +84,7 @@ const EmptyComputedFieldDoc = RootComponent()({
81
84
  methods: {
82
85
  M1() {
83
86
  // 6.1 computed为{},this.data中为{}
84
- Checking<typeof this.data, {}, Test.Pass>;
87
+ Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
85
88
  },
86
89
  },
87
90
  });
@@ -1,6 +1,7 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
 
3
3
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
4
+ import { IInjectData } from "../../../InstanceInject/instanceConfig";
4
5
  import { RootComponent } from "../..";
5
6
 
6
7
  type Gender = "male" | "female";
@@ -15,7 +16,7 @@ const RootDoc = RootComponent()({
15
16
  foo() {
16
17
  Checking<
17
18
  typeof this.data,
18
- ReadonlyDeep<{ gender: Gender; num: number; _innernalFields: number }>,
19
+ ReadonlyDeep<{ gender: Gender; num: number; _innernalFields: number } & IInjectData>,
19
20
  Test.Pass
20
21
  >;
21
22
  },
@@ -36,7 +37,7 @@ const EmptyDataRootDoc = RootComponent()({
36
37
  methods: {
37
38
  M1() {
38
39
  // 3.1 data为空对象时 this.data为{}类型
39
- Checking<typeof this.data, {}, Test.Pass>;
40
+ Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
40
41
  },
41
42
  },
42
43
  });
@@ -51,7 +52,7 @@ const noDataRootDoc = RootComponent()({
51
52
  methods: {
52
53
  M1() {
53
54
  // 4.1 data为空对象时 this.data为{}类型
54
- Checking<typeof this.data, {}, Test.Pass>;
55
+ Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
55
56
  },
56
57
  },
57
58
  });
@@ -1,10 +1,11 @@
1
1
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
2
2
  import type { IfExtends } from "hry-types/src/Any/IfExtends";
3
- import type { Func } from "hry-types/src/Misc/Func";
4
3
  import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
5
4
  import type { IReactionDisposer } from "mobx";
6
5
 
6
+ import { Assign } from "../../../types/Assign";
7
7
  import type { WMComponentInstance, WMInstanceMethods, WMPageInstance } from "../../../types/OfficialTypeAlias";
8
+ import { IInjectData, IInjectMethods } from "../../InstanceInject/instanceConfig";
8
9
  import type { CustomEventMethods } from "./CustomEventMethods";
9
10
  import type { CustomSetData } from "./CustomSetData";
10
11
  export type RootComponentInstance<
@@ -23,11 +24,9 @@ export type RootComponentInstance<
23
24
  & CustomSetData<TData>
24
25
  & IfExtends<{}, StoreDoc, unknown, {
25
26
  disposer?: { [k in keyof StoreDoc]: IReactionDisposer };
26
- applySetData: Func;
27
27
  }>
28
- & TMethods
29
- & CustomEventMethods<CustomEventsDoc>
30
- & { data: ReadonlyDeep<ComputeIntersection<AllData>> };
28
+ & Assign<IInjectMethods, TMethods & CustomEventMethods<CustomEventsDoc>>
29
+ & { data: ReadonlyDeep<Assign<IInjectData, ComputeIntersection<AllData>>> };
31
30
 
32
31
  export type ComponentInstance = RootComponentInstance<false, {}, {}, {}, {}, {}>;
33
32
 
@@ -1,6 +1,7 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/ReadonlyDeep";
3
3
  import { type DetailedType, RootComponent } from "../../../../..";
4
+ import { IInjectData } from "../../../../InstanceInject/instanceConfig";
4
5
 
5
6
  // 组件时
6
7
  RootComponent()({
@@ -14,7 +15,11 @@ RootComponent()({
14
15
  lifetimes: {
15
16
  attached() {
16
17
  // 组件实例对象格外添加null类型
17
- Checking<typeof this.data, ReadonlyDeep<{ optionalObj: { name: string } | null; obj: object | null }>, Test.Pass>;
18
+ Checking<
19
+ typeof this.data,
20
+ ReadonlyDeep<{ optionalObj: { name: string } | null; obj: object | null } & IInjectData>,
21
+ Test.Pass
22
+ >;
18
23
  },
19
24
  },
20
25
  });
@@ -63,13 +63,3 @@ RootComponent()({
63
63
  },
64
64
  },
65
65
  });
66
-
67
- RootComponent()({
68
- store: {},
69
- lifetimes: {
70
- attached() {
71
- // @ts-expect-error 没有store字段时不可以调用applySetData
72
- this.applySetData();
73
- },
74
- },
75
- });
@@ -46,9 +46,6 @@ RootComponent()({
46
46
  runInAction(() => {
47
47
  store.name = "liil";
48
48
  });
49
-
50
- // 有store字段时可以调用applySetData
51
- this.applySetData();
52
49
  },
53
50
  },
54
51
  });
@@ -1,4 +1,6 @@
1
1
  import { Checking, type Test } from "hry-types";
2
+ import { ReadonlyDeep } from "hry-types/src/Any/_api";
3
+ import { IInjectData } from "../../../InstanceInject/instanceConfig";
2
4
  import { RootComponent } from "../..";
3
5
 
4
6
  /**
@@ -9,7 +11,7 @@ const emptyObj = RootComponent()({
9
11
  methods: {
10
12
  foo() {
11
13
  // 1 this.data 为空对象类型
12
- Checking<typeof this.data, {}, Test.Pass>;
14
+ Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
13
15
  },
14
16
  },
15
17
  });
@@ -28,7 +30,7 @@ const noProperties = RootComponent()({
28
30
  methods: {
29
31
  foo() {
30
32
  // 3 this.data 为空对象类型
31
- Checking<typeof this.data, {}, Test.Pass>;
33
+ Checking<typeof this.data, ReadonlyDeep<IInjectData>, Test.Pass>;
32
34
  },
33
35
  },
34
36
  });
@@ -1,6 +1,7 @@
1
1
  import { Checking, type Test } from "hry-types";
2
2
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
3
3
  import type { DetailedType } from "../../../../types/DetailedType";
4
+ import { IInjectData } from "../../../InstanceInject/instanceConfig";
4
5
  import { RootComponent } from "../..";
5
6
  import { type Mock_User } from "./normalRequired.test";
6
7
 
@@ -43,14 +44,16 @@ const OptionalDoc = RootComponent()({
43
44
  // 1. 内部this.data中的类型(去除可选)
44
45
  Checking<
45
46
  typeof this.data,
46
- ReadonlyDeep<{
47
- optional_num: number;
48
- optional_gender: "male" | "female";
49
- optional_tuple: [number, string, boolean];
50
- optional_obj: Mock_User | null;
51
- optional_objOrNull: Mock_User | null;
52
- optional_union: string | number;
53
- }>,
47
+ ReadonlyDeep<
48
+ {
49
+ optional_num: number;
50
+ optional_gender: "male" | "female";
51
+ optional_tuple: [number, string, boolean];
52
+ optional_obj: Mock_User | null;
53
+ optional_objOrNull: Mock_User | null;
54
+ optional_union: string | number;
55
+ } & IInjectData
56
+ >,
54
57
  Test.Pass
55
58
  >;
56
59
  },
@@ -2,6 +2,7 @@ import { Checking, type Test } from "hry-types";
2
2
  import type { DetailedType } from "../../../../types/DetailedType";
3
3
 
4
4
  import type { ReadonlyDeep } from "hry-types/src/Any/_api";
5
+ import { IInjectData } from "../../../InstanceInject/instanceConfig";
5
6
  import { RootComponent } from "../..";
6
7
  import type { RequiredSingle, RequiredType, RequiredUnion } from "../PropertiesConstraint";
7
8
 
@@ -91,7 +92,7 @@ const RequiredDoc = RootComponent()({
91
92
  methods: {
92
93
  foo() {
93
94
  // 1 this.data中的类型(对象类型加null)
94
- Checking<typeof this.data, ReadonlyDeep<RequiredTypeExpected>, Test.Pass>;
95
+ Checking<typeof this.data, ReadonlyDeep<RequiredTypeExpected & IInjectData>, Test.Pass>;
95
96
  },
96
97
  },
97
98
  });
@@ -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
 
@@ -42,6 +42,7 @@ export function deepProxy(
42
42
 
43
43
  return deepProxy(val, dependences, curPath);
44
44
  },
45
+ /* istanbul ignore next */
45
46
  set(_target: object, prop: string) {
46
47
  throw Error(`${prop}字段是只读的`);
47
48
  },
@@ -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
 
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
- // }