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.
- package/CHANGELOG.md +31 -0
- package/README.md +28 -16
- package/dist/api/DefineComponent/collectOptionsForComponent.js +30 -11
- package/dist/api/DefineComponent/collectOptionsForComponent.js.map +1 -1
- package/dist/api/DefineComponent/index.js.map +1 -1
- package/dist/api/InstanceInject/instanceConfig.d.ts +23 -0
- package/dist/api/InstanceInject/instanceConfig.js +13 -0
- package/dist/api/InstanceInject/instanceConfig.js.map +1 -0
- package/dist/api/InstanceInject/test/normal.test.d.ts +1 -0
- package/dist/api/InstanceInject/test/normal.test.js +30 -0
- package/dist/api/InstanceInject/test/normal.test.js.map +1 -0
- package/dist/api/RootComponent/Computed/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.js +0 -1
- package/dist/api/RootComponent/CustomEvents/test/GetCustomEventDoc.test.js.map +1 -1
- package/dist/api/RootComponent/CustomEvents/test/GetFullEventDoc.test.js +0 -1
- package/dist/api/RootComponent/CustomEvents/test/GetFullEventDoc.test.js.map +1 -1
- package/dist/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.js +0 -1
- package/dist/api/RootComponent/CustomEvents/test/GetShortEventDoc.test.js.map +1 -1
- package/dist/api/RootComponent/Data/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/RootComponentInstance.d.ts +4 -4
- package/dist/api/RootComponent/Instance/test/properties/mormal.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/test/setData/error.test.js +0 -8
- package/dist/api/RootComponent/Instance/test/setData/error.test.js.map +1 -1
- package/dist/api/RootComponent/Instance/test/setData/normal.test.js +0 -1
- package/dist/api/RootComponent/Instance/test/setData/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Lifetimes/test/error.test.js +1 -1
- package/dist/api/RootComponent/Lifetimes/test/error.test.js.map +1 -1
- package/dist/api/RootComponent/Lifetimes/test/normal.test.js +1 -1
- package/dist/api/RootComponent/Lifetimes/test/normal.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/test/normalEmpty.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/test/normalOptional.test.js.map +1 -1
- package/dist/api/RootComponent/Properties/test/normalRequired.test.js.map +1 -1
- package/dist/api/SubComponent/SubComputed/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubData/test/normal.test.js.map +1 -1
- package/dist/api/SubComponent/SubInstance/test/normal.test.js.map +1 -1
- package/dist/api/navigateTo.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/data-tracer.js +3 -0
- package/dist/behaviors/BComputedAndWatch/data-tracer.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/getPropertiesValue.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/index.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/initComputed.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/isEqual.js.map +1 -1
- package/dist/behaviors/BComputedAndWatch/types.d.ts +0 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/inject.d.ts +18 -0
- package/dist/inject.js +20 -0
- package/dist/inject.js.map +1 -0
- package/dist/thirdLib/index.js +1 -2
- package/dist/thirdLib/index.js.map +1 -1
- package/dist/types/Assign.d.ts +1 -0
- package/dist/types/Assign.js +2 -0
- package/dist/types/Assign.js.map +1 -0
- package/dist/types/OfficialTypeAlias.d.ts +1 -1
- package/package.json +5 -4
- package/src/api/DefineComponent/collectOptionsForComponent.ts +55 -11
- package/src/api/DefineComponent/index.ts +1 -0
- package/src/api/InstanceInject/instanceConfig.ts +39 -0
- package/src/api/InstanceInject/test/normal.test.ts +40 -0
- package/src/api/RootComponent/Computed/test/normal.test.ts +14 -11
- package/src/api/RootComponent/Data/test/normal.test.ts +4 -3
- package/src/api/RootComponent/Instance/RootComponentInstance.ts +4 -5
- package/src/api/RootComponent/Instance/test/properties/mormal.test.ts +6 -1
- package/src/api/RootComponent/Instance/test/setData/error.test.ts +0 -10
- package/src/api/RootComponent/Instance/test/setData/normal.test.ts +0 -3
- package/src/api/RootComponent/Lifetimes/test/error.test.ts +1 -1
- package/src/api/RootComponent/Lifetimes/test/normal.test.ts +1 -1
- package/src/api/RootComponent/Properties/test/normalEmpty.test.ts +4 -2
- package/src/api/RootComponent/Properties/test/normalOptional.test.ts +11 -8
- package/src/api/RootComponent/Properties/test/normalRequired.test.ts +2 -1
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +27 -22
- package/src/api/SubComponent/SubData/test/normal.test.ts +9 -6
- package/src/api/SubComponent/SubInstance/test/normal.test.ts +14 -11
- package/src/api/navigateTo.ts +1 -0
- package/src/behaviors/BComputedAndWatch/data-tracer.ts +5 -1
- package/src/behaviors/BComputedAndWatch/getPropertiesValue.ts +3 -0
- package/src/behaviors/BComputedAndWatch/index.ts +1 -0
- package/src/behaviors/BComputedAndWatch/initComputed.ts +1 -0
- package/src/behaviors/BComputedAndWatch/isEqual.ts +1 -0
- package/src/behaviors/BComputedAndWatch/types.ts +0 -1
- package/src/index.ts +3 -0
- package/src/inject.ts +34 -0
- package/src/types/Assign.ts +1 -0
- package/src/types/OfficialTypeAlias.ts +1 -1
- package/tsconfig.json +26 -0
- package/dist/api/InstanceInject/InstanceInject.d.ts +0 -0
- package/dist/api/InstanceInject/InstanceInject.js +0 -2
- package/dist/api/InstanceInject/InstanceInject.js.map +0 -1
- package/dist/api/InstanceInject/test/InjectConfig.d.ts +0 -0
- package/dist/api/InstanceInject/test/InjectConfig.js +0 -2
- package/dist/api/InstanceInject/test/InjectConfig.js.map +0 -1
- package/src/api/InstanceInject/InstanceInject.ts +0 -25
- package/src/api/InstanceInject/test/InjectConfig.ts +0 -50
|
@@ -2,7 +2,6 @@ import type { Func } from "hry-types/src/Misc/Func";
|
|
|
2
2
|
import type { ComponentInstance, PageInstance } from "../../api/RootComponent/Instance/RootComponentInstance";
|
|
3
3
|
import type { ComputedDependence } from "./initComputed";
|
|
4
4
|
export type InstanceCustomFields = {
|
|
5
|
-
__pendingSetData__?: object | null;
|
|
6
5
|
__storeConfig__?: () => Record<string, () => unknown>;
|
|
7
6
|
__computedStatus__?: "待更新" | "更新完毕";
|
|
8
7
|
__computedUpdater__: Func;
|
package/dist/index.d.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";
|
|
@@ -8,4 +9,4 @@ import type { GenerateDoc } from "./types/GenerateDoc";
|
|
|
8
9
|
import type { ParamsEqual } from "./types/TwoParamsEqual";
|
|
9
10
|
export type { Vant, Wm } from "./thirdLib";
|
|
10
11
|
export type { CurrentTargetDataset, Dataset, Detail, Mark, TargetDataset, WMBaseEvent, WMCustomEvent, } from "./types/OfficialTypeAlias";
|
|
11
|
-
export { type ComponentDocExtension, DefineComponent, type DetailedType, type GenerateDoc, navigateTo, type ParamsEqual, RootComponent, SubComponent, };
|
|
12
|
+
export { type ComponentDocExtension, DefineComponent, type DetailedType, type GenerateDoc, type IInjectInfo, instanceConfig, navigateTo, type ParamsEqual, RootComponent, SubComponent, };
|
package/dist/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { DefineComponent } from "./api/DefineComponent";
|
|
2
|
+
import { 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";
|
|
5
|
-
export { DefineComponent, navigateTo, RootComponent, SubComponent, };
|
|
6
|
+
export { DefineComponent, instanceConfig, navigateTo, RootComponent, SubComponent, };
|
|
6
7
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAiBlD,OAAO,EAEL,eAAe,EAIf,UAAU,EAEV,aAAa,EACb,YAAY,GACb,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAoB,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACvF,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAiBlD,OAAO,EAEL,eAAe,EAIf,cAAc,EAEd,UAAU,EAEV,aAAa,EACb,YAAY,GACb,CAAC"}
|
package/dist/inject.d.ts
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare function injectMethod(data: string): string;
|
|
2
|
+
declare const data: {
|
|
3
|
+
injectStr: string;
|
|
4
|
+
};
|
|
5
|
+
declare const methods: {
|
|
6
|
+
injectMethod: typeof injectMethod;
|
|
7
|
+
};
|
|
8
|
+
declare const store: {
|
|
9
|
+
injectTheme: () => "dark" | "light" | undefined;
|
|
10
|
+
};
|
|
11
|
+
declare module "./index" {
|
|
12
|
+
interface IInjectInfo {
|
|
13
|
+
data: typeof data;
|
|
14
|
+
store: typeof store;
|
|
15
|
+
methods: typeof methods;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
export {};
|
package/dist/inject.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { observable, runInAction } from "mobx";
|
|
2
|
+
const themeStore = observable({ theme: wx.getSystemInfoSync().theme });
|
|
3
|
+
wx.onThemeChange((Res) => {
|
|
4
|
+
runInAction(() => {
|
|
5
|
+
themeStore.theme = Res.theme;
|
|
6
|
+
});
|
|
7
|
+
});
|
|
8
|
+
function injectMethod(data) {
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
const data = {
|
|
12
|
+
injectStr: "injectStr",
|
|
13
|
+
};
|
|
14
|
+
const methods = {
|
|
15
|
+
injectMethod,
|
|
16
|
+
};
|
|
17
|
+
const store = {
|
|
18
|
+
injectTheme: () => themeStore.theme,
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=inject.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inject.js","sourceRoot":"","sources":["../src/inject.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,MAAM,MAAM,CAAC;AAG/C,MAAM,UAAU,GAAG,UAAU,CAAC,EAAE,KAAK,EAAE,EAAE,CAAC,iBAAiB,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;AAEvE,EAAE,CAAC,aAAa,CAAC,CAAC,GAAG,EAAE,EAAE;IACvB,WAAW,CAAC,GAAG,EAAE;QACf,UAAU,CAAC,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC;IAC/B,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC;AAGH,SAAS,YAAY,CAAC,IAAY;IAChC,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,IAAI,GAAG;IACX,SAAS,EAAE,WAAW;CACvB,CAAC;AACF,MAAM,OAAO,GAAG;IACd,YAAY;CACb,CAAC;AACF,MAAM,KAAK,GAAG;IACZ,WAAW,EAAE,GAAG,EAAE,CAAC,UAAU,CAAC,KAAK;CACpC,CAAC"}
|
package/dist/thirdLib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/thirdLib/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/thirdLib/index.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export type Assign<O1, O2> = Omit<O1, keyof O2> & O2;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Assign.js","sourceRoot":"","sources":["../../src/types/Assign.ts"],"names":[],"mappings":""}
|
|
@@ -10,7 +10,7 @@ export type Mark<TMark extends object> = Required<WechatMiniprogram.CustomEvent<
|
|
|
10
10
|
export type Detail<T> = WMCustomEvent<T>;
|
|
11
11
|
export type CurrentTargetDataset<T extends object> = WMCustomEvent<{}, {}, T>;
|
|
12
12
|
export type TargetDataset<TargetDataset extends object> = WMCustomEvent<{}, {}, {}, TargetDataset>;
|
|
13
|
-
export type WMComponentOption = WechatMiniprogram.Component.
|
|
13
|
+
export type WMComponentOption = WechatMiniprogram.Component.ComponentOptions;
|
|
14
14
|
export type WMNavigateToSuccessCallbackResult = WechatMiniprogram.NavigateToSuccessCallbackResult;
|
|
15
15
|
export type WMCompPageLifetimes = WechatMiniprogram.Component.PageLifetimes;
|
|
16
16
|
export type WMComponentInstance = WechatMiniprogram.Component.InstanceProperties;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "annil",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "微信小程序(原生开发)插件",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -42,7 +42,8 @@
|
|
|
42
42
|
"CHANGELOG.md",
|
|
43
43
|
"README.md",
|
|
44
44
|
"src",
|
|
45
|
-
"dist"
|
|
45
|
+
"dist",
|
|
46
|
+
"tsconfig.json"
|
|
46
47
|
],
|
|
47
48
|
"keywords": [
|
|
48
49
|
"mini",
|
|
@@ -52,8 +53,8 @@
|
|
|
52
53
|
],
|
|
53
54
|
"author": "missannil",
|
|
54
55
|
"license": "MIT",
|
|
55
|
-
"
|
|
56
|
+
"peerDependencies": {
|
|
56
57
|
"hry-types": "^0.17.0",
|
|
57
|
-
"miniprogram-api-typings": "^3.12.
|
|
58
|
+
"miniprogram-api-typings": "^3.12.2"
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { Func } from "hry-types/src/Misc/_api";
|
|
2
|
+
import { instanceConfig } from "../..";
|
|
2
3
|
import { BBeforeCreate } from "../../behaviors/BbeforeCreated";
|
|
3
4
|
import { BComputedAndWatch } from "../../behaviors/BComputedAndWatch";
|
|
4
5
|
import type { ComputedCache, Instance } from "../../behaviors/BComputedAndWatch/types";
|
|
5
6
|
import { BStore } from "../../behaviors/BStore";
|
|
7
|
+
import { Assign } from "../../types/Assign";
|
|
6
8
|
import type { WMComponent } from "../../types/OfficialTypeAlias";
|
|
7
9
|
import { INNERMARKER } from "../../utils/InnerMarker";
|
|
8
10
|
import { isEmptyObject } from "../../utils/isEmptyObject";
|
|
@@ -124,8 +126,10 @@ function loadReceivedDataHandle(
|
|
|
124
126
|
*/
|
|
125
127
|
/* istanbul ignore next: miniprogram-simulate(当前版本 1.6.1) 无法测试页面 */
|
|
126
128
|
function hijack(config: object, field: string, before: Func[] = [], after: Func[] = []) {
|
|
129
|
+
// @ts-ignore 隐式索引
|
|
127
130
|
const originalFunc: Func | undefined = config[field];
|
|
128
131
|
|
|
132
|
+
// @ts-ignore 隐式索引
|
|
129
133
|
config[field] = function(...args: any[]) {
|
|
130
134
|
before.forEach(func => func.call(this, ...args));
|
|
131
135
|
|
|
@@ -155,6 +159,7 @@ function InternalFieldProtection(config: object | undefined, keys: string[]) {
|
|
|
155
159
|
*/
|
|
156
160
|
function _funcOptionsHandle(config: object, configList: Record<string, Func[]>) {
|
|
157
161
|
for (const key in configList) {
|
|
162
|
+
// @ts-ignore 隐式索引
|
|
158
163
|
config[key] = function(...args: unknown[]) {
|
|
159
164
|
configList[key].forEach(ele => ele.call(this, ...args));
|
|
160
165
|
};
|
|
@@ -191,8 +196,11 @@ function funcFieldsCollect(
|
|
|
191
196
|
) {
|
|
192
197
|
for (const key in funcOptions) {
|
|
193
198
|
// key = "pageLifetimes" | "lifetimes" | "watch"
|
|
199
|
+
// @ts-ignore 隐式索引
|
|
194
200
|
if (options[key]) {
|
|
201
|
+
// @ts-ignore 隐式索引
|
|
195
202
|
for (const _key in options[key]) {
|
|
203
|
+
// @ts-ignore 隐式索引
|
|
196
204
|
(funcOptions[key][_key] ||= []).push(options[key][_key]);
|
|
197
205
|
}
|
|
198
206
|
}
|
|
@@ -207,11 +215,13 @@ function otherFieldsHandle(
|
|
|
207
215
|
rootComponentOptions: RootComponentTrueOptions,
|
|
208
216
|
) {
|
|
209
217
|
for (const key in rootComponentOptions) {
|
|
218
|
+
// @ts-ignore 隐式索引
|
|
210
219
|
const config = rootComponentOptions[key];
|
|
211
220
|
if (key === "behaviors") {
|
|
212
221
|
// 是不是只有behaviors是数组
|
|
213
222
|
finalOptions[key].push(...config);
|
|
214
223
|
} else {
|
|
224
|
+
// @ts-ignore 隐式索引
|
|
215
225
|
Object.assign(finalOptions[key] ||= {}, config);
|
|
216
226
|
}
|
|
217
227
|
}
|
|
@@ -284,6 +294,44 @@ function collectRootComponentOption(
|
|
|
284
294
|
otherFieldsHandle(finalOptions, rootComponentOptions);
|
|
285
295
|
}
|
|
286
296
|
|
|
297
|
+
/**
|
|
298
|
+
* 合并 source 对象字段到 target字段
|
|
299
|
+
* @remarks 规则:
|
|
300
|
+
* 1. behaviors字段 源对象在前
|
|
301
|
+
* 2. 对象字段 源覆盖目标
|
|
302
|
+
* @param target - 目标对象
|
|
303
|
+
* @param source - 源对象
|
|
304
|
+
* @returns 按规则合并后的对象
|
|
305
|
+
*/
|
|
306
|
+
function merge<Target extends object, Source extends object>(target: Target, source: Source): Assign<Target, Source> {
|
|
307
|
+
for (const key in source) {
|
|
308
|
+
const sourceVal = source[key];
|
|
309
|
+
if (key in target) {
|
|
310
|
+
// @ts-ignore
|
|
311
|
+
const targetVal = target[key];
|
|
312
|
+
switch (key) {
|
|
313
|
+
case "behaviors":
|
|
314
|
+
{
|
|
315
|
+
// @ts-ignore
|
|
316
|
+
target[key] = [...sourceVal, ...targetVal];
|
|
317
|
+
}
|
|
318
|
+
break;
|
|
319
|
+
|
|
320
|
+
default:
|
|
321
|
+
{
|
|
322
|
+
// @ts-ignore 源覆盖目标
|
|
323
|
+
target[key] = Object.assign(targetVal, sourceVal);
|
|
324
|
+
}
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
} else {
|
|
328
|
+
// @ts-ignore
|
|
329
|
+
target[key] = sourceVal;
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return target as unknown as Assign<Target, Source>;
|
|
334
|
+
}
|
|
287
335
|
/**
|
|
288
336
|
* 返回一个由rootComponentOption和subComponentsList配置整合的对象
|
|
289
337
|
* @param rootComponentOption -
|
|
@@ -295,18 +343,14 @@ export function collectOptionsForComponent(
|
|
|
295
343
|
): FinalOptionsOfComponent {
|
|
296
344
|
const rootComponentOption = defineComponentOption.rootComponent;
|
|
297
345
|
const subComponentsList = defineComponentOption.subComponents;
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
addGlobalClass: true, // "styleIsolation": "apply-shared"
|
|
301
|
-
multipleSlots: true,
|
|
302
|
-
pureDataPattern: /^_/,
|
|
303
|
-
virtualHost: true,
|
|
304
|
-
},
|
|
305
|
-
behaviors: [BStore, BComputedAndWatch],
|
|
306
|
-
methods: {},
|
|
346
|
+
|
|
347
|
+
const finalOptionsForComponent: FinalOptionsOfComponent = merge(instanceConfig.injectInfo || {}, {
|
|
307
348
|
observers: {},
|
|
308
349
|
data: {},
|
|
309
|
-
|
|
350
|
+
methods: {},
|
|
351
|
+
behaviors: [BStore, BComputedAndWatch],
|
|
352
|
+
});
|
|
353
|
+
|
|
310
354
|
/**
|
|
311
355
|
* 有些字段配置同时存在根组件和子组件当中(如pageLifetimes,lifetimes,watch字段), 且key相同值类型为函数。funcConfig对象用于收集这些配置为数组形式,最终再一起整合进finalOptionsForComponent配置中。即funcConfig是一个临时中介对象。
|
|
312
356
|
*/
|
|
@@ -342,7 +386,7 @@ export function collectOptionsForComponent(
|
|
|
342
386
|
/* istanbul ignore next: miniprogram-simulate(当前版本 1.6.1) 无法测试页面 */
|
|
343
387
|
finalOptionsForComponent.isPage
|
|
344
388
|
// 页面时删除预设的虚拟组件字段
|
|
345
|
-
&& Reflect.deleteProperty(finalOptionsForComponent.options
|
|
389
|
+
&& finalOptionsForComponent.options && Reflect.deleteProperty(finalOptionsForComponent.options, "virtualHost");
|
|
346
390
|
|
|
347
391
|
// BBeforeCreate在最后面,让BeforeCreate生命周期运行在最终建立组件时。
|
|
348
392
|
finalOptionsForComponent.behaviors!.push(BBeforeCreate);
|
|
@@ -54,6 +54,7 @@ export type DefineComponentOption = {
|
|
|
54
54
|
*/
|
|
55
55
|
export const DefineComponent: DefineComponentConstructor = function(options): any {
|
|
56
56
|
// console.log("---------------------------");
|
|
57
|
+
|
|
57
58
|
Component(
|
|
58
59
|
collectOptionsForComponent(options as DefineComponentOption) as any,
|
|
59
60
|
);
|
|
@@ -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
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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,
|
|
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,
|
|
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,
|
|
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,
|
|
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
|
-
&
|
|
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<
|
|
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
|
});
|
|
@@ -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,
|
|
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,
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
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
|
});
|