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.
- package/CHANGELOG.md +7 -0
- package/README.md +43 -37
- package/dist/api/DefineComponent/ReturnType/ComponentType.d.ts +18 -0
- package/dist/api/DefineComponent/ReturnType/ComponentType.js +2 -0
- package/dist/api/DefineComponent/ReturnType/ComponentType.js.map +1 -0
- package/dist/api/DefineComponent/ReturnType/CreateComponentDoc.d.ts +3 -3
- package/dist/api/DefineComponent/ReturnType/CreatePageDoc.d.ts +2 -2
- package/dist/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.d.ts +3 -3
- package/dist/api/DefineComponent/RootComponent/RootComponentOption.d.ts +2 -2
- package/dist/api/DefineComponent/SubComponents/SubComponentsOption.d.ts +2 -2
- package/dist/api/DefineComponent/index.d.ts +5 -5
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js +2 -2
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js +2 -2
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/index.js.map +1 -1
- package/dist/api/DefineComponent/normalizeOptions/index.js +1 -1
- package/dist/api/DefineComponent/normalizeOptions/index.js.map +1 -1
- package/dist/api/RootComponent/Events/EventsConstraint.d.ts +4 -4
- package/dist/api/RootComponent/{RootComponentDoc.d.ts → RootComponentType.d.ts} +16 -15
- package/dist/api/RootComponent/RootComponentType.js +2 -0
- package/dist/api/RootComponent/RootComponentType.js.map +1 -0
- package/dist/api/RootComponent/index.d.ts +3 -3
- package/dist/api/SubComponent/{SubComponentDoc.d.ts → SubComponentType.d.ts} +3 -3
- package/dist/api/SubComponent/SubComponentType.js +2 -0
- package/dist/api/SubComponent/SubComponentType.js.map +1 -0
- package/dist/api/SubComponent/SubEvents/SubEventsConstraint.d.ts +2 -2
- package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +2 -2
- package/dist/api/SubComponent/index.d.ts +5 -5
- package/dist/behaviors/BStore.d.ts +1 -1
- package/dist/behaviors/BStore.js +31 -18
- package/dist/behaviors/BStore.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/types/CreateComponentType.d.ts +23 -2
- package/dist/types/ExtendComponentType.d.ts +34 -0
- package/dist/types/ExtendComponentType.js +6 -0
- package/dist/types/ExtendComponentType.js.map +1 -0
- package/dist/types/GetComponentPrefix.d.ts +2 -2
- package/dist/types/ReplacePrefix.d.ts +2 -2
- package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.d.ts → utils/deepEqual.d.ts} +1 -1
- package/dist/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js → utils/deepEqual.js} +3 -3
- package/dist/utils/deepEqual.js.map +1 -0
- package/package.json +2 -3
- package/src/api/DefineComponent/NameOrPage/test/error.test.ts +6 -6
- package/src/api/DefineComponent/ReturnType/{ComponentDoc.ts → ComponentType.ts} +6 -7
- package/src/api/DefineComponent/ReturnType/CreateComponentDoc.ts +4 -4
- package/src/api/DefineComponent/ReturnType/CreatePageDoc.ts +2 -2
- package/src/api/DefineComponent/ReturnType/GetCustomEventDocOfSubDoc.ts +3 -3
- package/src/api/DefineComponent/ReturnType/GetPropertiesDocOfSubDoc.ts +3 -3
- package/src/api/DefineComponent/ReturnType/test/normalComponentDoc.test.ts +5 -5
- package/src/api/DefineComponent/RootComponent/RootComponentOption.ts +2 -2
- package/src/api/DefineComponent/SubComponents/SubComponentsOption.ts +2 -2
- package/src/api/DefineComponent/SubComponents/test/normal.test.ts +3 -3
- package/src/api/DefineComponent/index.ts +7 -7
- package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/computedUpdater.ts +2 -2
- package/src/api/DefineComponent/normalizeOptions/computedWatchHandle/index.ts +2 -2
- package/src/api/DefineComponent/normalizeOptions/index.ts +1 -1
- package/src/api/RootComponent/Events/EventsConstraint.ts +5 -5
- package/src/api/RootComponent/Events/test/normal.test.ts +5 -5
- package/src/api/RootComponent/{RootComponentDoc.ts → RootComponentType.ts} +16 -15
- package/src/api/RootComponent/index.ts +3 -3
- package/src/api/SubComponent/{SubComponentDoc.ts → SubComponentType.ts} +3 -3
- package/src/api/SubComponent/SubComputed/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubComputed/test/normal.test.ts +4 -4
- package/src/api/SubComponent/SubData/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubData/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubEvents/SubEventsConstraint.ts +2 -2
- package/src/api/SubComponent/SubEvents/test/error.test.ts +3 -3
- package/src/api/SubComponent/SubEvents/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +2 -2
- package/src/api/SubComponent/SubInherit/test/error.test.ts +6 -6
- package/src/api/SubComponent/SubInherit/test/normal.test.ts +4 -4
- package/src/api/SubComponent/SubInstance/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubInstance/test/normal.test.ts +4 -4
- package/src/api/SubComponent/SubMethods/test/error.test.ts +4 -4
- package/src/api/SubComponent/SubMethods/test/normarl.test.ts +4 -4
- package/src/api/SubComponent/SubReturnType/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubReturnType/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubStore/test/error.test.ts +2 -2
- package/src/api/SubComponent/SubStore/test/normal.test.ts +2 -2
- package/src/api/SubComponent/SubWatch/test/WatchComputed.test.ts +4 -4
- package/src/api/SubComponent/SubWatch/test/WatchRootData.test.ts +2 -2
- package/src/api/SubComponent/SubWatch/test/WatchSubData.test.ts +2 -2
- package/src/api/SubComponent/index.ts +9 -9
- package/src/behaviors/BStore.ts +35 -23
- package/src/index.ts +2 -2
- package/src/types/CreateComponentType.ts +23 -2
- package/src/types/ExtendComponentType.ts +60 -0
- package/src/types/GetComponentPrefix.ts +2 -2
- package/src/types/GetPropertiesDuplicatedKeys.ts +3 -3
- package/src/types/ReplacePrefix.ts +2 -2
- package/src/{api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.ts → utils/deepEqual.ts} +2 -3
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.d.ts +0 -18
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.js +0 -2
- package/dist/api/DefineComponent/ReturnType/ComponentDoc.js.map +0 -1
- package/dist/api/DefineComponent/normalizeOptions/computedWatchHandle/isEqual.js.map +0 -1
- package/dist/api/RootComponent/RootComponentDoc.js +0 -2
- package/dist/api/RootComponent/RootComponentDoc.js.map +0 -1
- package/dist/api/SubComponent/SubComponentDoc.js +0 -2
- package/dist/api/SubComponent/SubComponentDoc.js.map +0 -1
- package/dist/types/DocAssign.d.ts +0 -10
- package/dist/types/DocAssign.js +0 -6
- package/dist/types/DocAssign.js.map +0 -1
- package/src/types/DocAssign.ts +0 -36
- 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 {
|
|
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 {
|
|
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";
|
|
@@ -36,15 +36,15 @@ import type { CreateSubComponentDoc } from "./SubReturnType/CreateSubComponentDo
|
|
|
36
36
|
import type { SubStoreConstraint } from "./SubStore/SubStoreConstraint";
|
|
37
37
|
import type { SubStoreOption } from "./SubStore/SubStoreOption";
|
|
38
38
|
import type { SubWatchOption } from "./SubWatch/SubWatchOption";
|
|
39
|
-
type Options<RootDoc extends
|
|
40
|
-
type SubComponentConstructor<TRootDoc extends
|
|
39
|
+
type Options<RootDoc extends RootComponentType, IsPage extends boolean, CurrentCompDoc extends ComponentType, Prefix extends string, AllRootDataDoc extends object, TInherit extends object, TSubData extends object, TSubStore extends object, TSubComputed extends object, TEvents extends object, TSubMethods extends SubMethodsConstraint, InheritDoc extends object, SubDataDoc extends object, SubStoreDoc extends object, SubComputedDoc extends object, SubEventsDoc extends object, SubMethodsDoc extends object, CompDocKeys extends PropertyKey = keyof CurrentCompDoc["properties"]> = SubInheritOption<TInherit, CompDocKeys> & SubDataOption<TSubData, Exclude<CompDocKeys, (keyof InheritDoc)> | InnerFields<Prefix>> & SubStoreOption<TSubStore, Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc))> | InnerFields<Prefix>> & SubComputedOption<TSubComputed, Exclude<CompDocKeys, (keyof (InheritDoc & SubDataDoc & SubStoreDoc))> | InnerFields<Prefix>> & SubEventsOption<TEvents, SubEventsDoc, keyof SubEventsConstraint<CurrentCompDoc>> & SubMethodsOption<TSubMethods, Prefix, keyof (CurrentCompDoc["customEvents"] & SubEventsDoc)> & SubPageLifetimesOption<IsPage, NonNullable<RootDoc["properties"]>> & SubLifetimesOption & SubWatchOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & Partial<Omit<WMCompOtherOption, "pageLifetimes" | "definitionFilter" | "export" | "observers" | "relations">> & SubObserversOption<SubComputedDoc & SubDataDoc & AllRootDataDoc & SubStoreDoc & IInjectStore> & ThisType<SubInstance<SubMethodsDoc & RootDoc["methods"], Replace<SubDataDoc, Required<CurrentCompDoc["properties"]>>, AllRootDataDoc & Replace<SubDataDoc & SubComputedDoc & SubStoreDoc, Required<CurrentCompDoc["properties"]>>, NonNullable<RootDoc["customEvents"]>, SubStoreDoc>>;
|
|
40
|
+
type SubComponentConstructor<TRootDoc extends RootComponentType, TOriginalCompDoc extends ComponentType, TSupplementalPrefix extends string = "", IsPage extends boolean = TRootDoc["isPage"] extends true ? true : false, CurrentPrefix extends string = `${GetComponentPrefix<TOriginalCompDoc>}${Capitalize<TSupplementalPrefix>}`, CurrentCompDoc extends ComponentType = IfExtends<TSupplementalPrefix, "", TOriginalCompDoc, ReplacePrefix<TOriginalCompDoc, CurrentPrefix>>, AllRootDataDoc extends object = Required<TRootDoc["properties"]> & TRootDoc["data"] & TRootDoc["computed"] & TRootDoc["store"]> = <TInherit extends InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TSubData extends SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubStore extends SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TEvents extends SubEventsConstraint<CurrentCompDoc>, TSubComputed extends SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubMethods extends SubMethodsConstraint = {}, InheritDoc extends object = IfExtends<InheritConstraint<AllRootDataDoc, CurrentCompDoc>, TInherit, {}, TInherit>, SubDataDoc extends object = IfExtends<SubDataConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof InheritDoc> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubData, {}, TSubData>, SubStoreDoc extends object = IfExtends<SubStoreConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubStore, {}, {
|
|
41
41
|
[k in keyof TSubStore]: ReturnType<NonNullable<TSubStore[k]>>;
|
|
42
42
|
}>, SubComputedDoc extends object = IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)> & Record<InnerFields<CurrentPrefix>, unknown>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>, SubEventsDoc extends object = IfExtends<SubEventsConstraint<CurrentCompDoc>, TEvents, {}, TEvents>, SubMethodsDoc extends object = TSubMethods, MissingRequiredField extends PropertyKey = Exclude<RequiredKeys<NonNullable<CurrentCompDoc["properties"]>>, keyof (InheritDoc & SubDataDoc & SubStoreDoc & IfExtends<SubComputedConstraint<Omit<Required<CurrentCompDoc["properties"]>, keyof (InheritDoc & SubDataDoc & SubStoreDoc)>>, TSubComputed, {}, GetSubComputedDoc<TSubComputed>>)>>(options: Options<TRootDoc, IsPage, CurrentCompDoc, CurrentPrefix, AllRootDataDoc, TInherit, TSubData, TSubStore, TSubComputed, TEvents, TSubMethods, InheritDoc, SubDataDoc, SubStoreDoc, SubComputedDoc, SubEventsDoc, SubMethodsDoc>) => CreateSubComponentDoc<NonNullable<TOriginalCompDoc["customEvents"]>, SubEventsDoc, MissingRequiredField>;
|
|
43
43
|
/**
|
|
44
44
|
* 子组件构建函数
|
|
45
45
|
* @returns `(options:) => SubComponentDoc`
|
|
46
46
|
*/
|
|
47
|
-
export declare function SubComponent<RootDoc extends
|
|
47
|
+
export declare function SubComponent<RootDoc extends RootComponentType, CompDoc extends ComponentType, Prefix extends string = "">(): IfExtends<EmptyObject, CompDoc, (opt: EmptyObject) => never, SubComponentConstructor<RootDoc, CompDoc, Prefix>>;
|
|
48
48
|
export type SubComponentTrueOptions = {
|
|
49
49
|
inhrit?: string;
|
|
50
50
|
data?: DataConstraint;
|
package/dist/behaviors/BStore.js
CHANGED
|
@@ -1,29 +1,42 @@
|
|
|
1
|
+
import { deepEqual } from "../utils/deepEqual";
|
|
2
|
+
import { isEmptyObject } from "../utils/isEmptyObject";
|
|
3
|
+
function reactionRegister(storeConfig) {
|
|
4
|
+
const unequalData = {};
|
|
5
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
6
|
+
const { comparer, reaction, toJS } = require("mobx");
|
|
7
|
+
// 存储reaction的disposer 需要保护内部字段验证
|
|
8
|
+
this.disposer = {};
|
|
9
|
+
for (const key in storeConfig) {
|
|
10
|
+
const currentStoreValue = toJS(storeConfig[key]());
|
|
11
|
+
// @ts-ignore this.data[key]一定存在
|
|
12
|
+
if (!deepEqual(currentStoreValue, this.data[key])) {
|
|
13
|
+
unequalData[key] = currentStoreValue;
|
|
14
|
+
}
|
|
15
|
+
// 添加响应式逻辑
|
|
16
|
+
this.disposer[key] = reaction(storeConfig[key], (value) => {
|
|
17
|
+
this.setData({
|
|
18
|
+
[key]: toJS(value),
|
|
19
|
+
});
|
|
20
|
+
}, {
|
|
21
|
+
equals: comparer.structural,
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
delete this.data.__storeConfig__;
|
|
25
|
+
if (!isEmptyObject(unequalData))
|
|
26
|
+
this.setData(unequalData);
|
|
27
|
+
}
|
|
1
28
|
/**
|
|
2
|
-
* 在created
|
|
29
|
+
* 在attached(1.7.5之前在created中)生命周期中,建立store数据的reaction
|
|
3
30
|
* 在detached生命周期中,清除store数据
|
|
4
31
|
*/
|
|
5
32
|
export const BStore = Behavior({
|
|
6
33
|
lifetimes: {
|
|
7
|
-
|
|
34
|
+
attached() {
|
|
35
|
+
// 此时store数据已初始化到data中(initStore)
|
|
8
36
|
const storeConfig = this.data.__storeConfig__;
|
|
9
37
|
if (!storeConfig)
|
|
10
38
|
return;
|
|
11
|
-
|
|
12
|
-
const { comparer, reaction, toJS } = require("mobx");
|
|
13
|
-
// 存储reaction的disposer 需要冲突字段验证
|
|
14
|
-
this.disposer = {};
|
|
15
|
-
for (const key in storeConfig) {
|
|
16
|
-
// 添加响应式逻辑
|
|
17
|
-
this.disposer[key] = reaction(storeConfig[key], (value) => {
|
|
18
|
-
// 加入到待setData对象中
|
|
19
|
-
this.setData({
|
|
20
|
-
[key]: toJS(value),
|
|
21
|
-
});
|
|
22
|
-
}, {
|
|
23
|
-
equals: comparer.structural,
|
|
24
|
-
});
|
|
25
|
-
}
|
|
26
|
-
delete this.data.__storeConfig__;
|
|
39
|
+
reactionRegister.call(this, storeConfig);
|
|
27
40
|
},
|
|
28
41
|
detached() {
|
|
29
42
|
/* istanbul ignore next 清除store数据 test中模拟了测试,所以忽略 框架(1.6.1)不支持 issue {@link https://github.com/wechat-miniprogram/miniprogram-simulate/issues/110}*/
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BStore.js","sourceRoot":"","sources":["../../src/behaviors/BStore.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"BStore.js","sourceRoot":"","sources":["../../src/behaviors/BStore.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAC/C,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAC;AAEvD,SAAS,gBAAgB,CAAiB,WAA0C;IAClF,MAAM,WAAW,GAA4B,EAAE,CAAC;IAChD,iEAAiE;IACjE,MAAM,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC,MAAM,CAAgB,CAAC;IACpE,iCAAiC;IACjC,IAAI,CAAC,QAAQ,GAAG,EAAE,CAAC;IACnB,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAC9B,MAAM,iBAAiB,GAAG,IAAI,CAAC,WAAW,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;QACnD,gCAAgC;QAChC,IAAI,CAAC,SAAS,CAAC,iBAAiB,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;YAClD,WAAW,CAAC,GAAG,CAAC,GAAG,iBAAiB,CAAC;QACvC,CAAC;QACD,UAAU;QACV,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,GAAG,QAAQ,CAC3B,WAAW,CAAC,GAAG,CAAC,EAChB,CAAC,KAAc,EAAE,EAAE;YACjB,IAAI,CAAC,OAAO,CAAC;gBACX,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC;aACnB,CAAC,CAAC;QACL,CAAC,EACD;YACE,MAAM,EAAE,QAAQ,CAAC,UAAU;SAC5B,CACF,CAAC;IACJ,CAAC;IACD,OAAO,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;IACjC,IAAI,CAAC,aAAa,CAAC,WAAW,CAAC;QAAE,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;AAC7D,CAAC;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,MAAM,GAAG,QAAQ,CAAC;IAC7B,SAAS,EAAE;QACT,QAAQ;YACN,iCAAiC;YACjC,MAAM,WAAW,GAAG,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC;YAC9C,IAAI,CAAC,WAAW;gBAAE,OAAO;YAEzB,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,CAAC;QAC3C,CAAC;QACD,QAAQ;YACN,oJAAoJ;YACpJ,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,QAAQ,EAAE,CAAC;gBAChC,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,EAAE,CAAC;YACvB,CAAC;QACH,CAAC;KACF;CACF,CAAC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ 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 {
|
|
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
|
export type { CurrentTargetDataset, Dataset, Detail, Mark, TargetDataset, WMBaseEvent, WMCustomEvent, } from "./types/OfficialTypeAlias";
|
|
12
|
-
export { type CreateComponentType, DefineComponent, type DetailedType, type
|
|
12
|
+
export { type CreateComponentType, DefineComponent, type DetailedType, type ExtendComponentType, type IInjectInfo, instanceConfig, navigateTo, type ParamsEqual, RootComponent, SubComponent, };
|
|
@@ -1,8 +1,29 @@
|
|
|
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 {
|
|
3
|
+
import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
|
|
4
4
|
import type { AddPrefix } from "./AddPrefix";
|
|
5
|
-
|
|
5
|
+
/**
|
|
6
|
+
* 建立一个组件类型
|
|
7
|
+
* @param TName 组件名称
|
|
8
|
+
* @param T 类型配置
|
|
9
|
+
* @example
|
|
10
|
+
* ```ts
|
|
11
|
+
* type $CustomA = CreateComponentType<"customA", {
|
|
12
|
+
* properties: { num: string };
|
|
13
|
+
* customEvents: { onTap: string }
|
|
14
|
+
* }>;
|
|
15
|
+
*
|
|
16
|
+
* // 等同下面的类型
|
|
17
|
+
* type $CustomA = {
|
|
18
|
+
* properties: {
|
|
19
|
+
* customA_num: string;
|
|
20
|
+
* };
|
|
21
|
+
* customEvents: {
|
|
22
|
+
* customA_onTap: string;
|
|
23
|
+
* };
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type CreateComponentType<TName extends string, T extends ComponentType> = ComputeIntersection<IfExtends<unknown, T["properties"], {}, {
|
|
6
27
|
properties: AddPrefix<T["properties"] & {}, TName>;
|
|
7
28
|
}> & IfExtends<unknown, T["customEvents"], {}, {
|
|
8
29
|
customEvents: AddPrefix<T["customEvents"] & {}, TName>;
|
|
@@ -0,0 +1,34 @@
|
|
|
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
|
+
type Validator<TOriginalComponentType extends ComponentType, TExtensionType extends ComponentType, TOriginalPrefix extends PropertyKey = GetComponentPrefix<TOriginalComponentType>, TExtenstionPrefix extends PropertyKey = GetComponentPrefix<TExtensionType>, DuplicateKeys extends PropertyKey = Extract<keyof TExtensionType["properties"], keyof TOriginalComponentType["properties"]> | Extract<keyof TExtensionType["customEvents"], keyof TOriginalComponentType["customEvents"]>> = IfExtends<TOriginalPrefix, TExtenstionPrefix, IfExtends<DuplicateKeys, never, ComponentType, `${DuplicateKeys & string}字段重复`>, `前缀错误,应为${TOriginalPrefix & string}`>;
|
|
6
|
+
/**
|
|
7
|
+
* 拓展组件类型
|
|
8
|
+
* @param TOriginalComponentType 原始组件类型
|
|
9
|
+
* @param TExtensionType 拓展类型
|
|
10
|
+
* @description 拓展类型必须与原始类型有相同的前缀
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* type $CustomA = ExtendComponentType<
|
|
14
|
+
* { properties: { aaa_num: number };
|
|
15
|
+
* customEvents: { aaa_xxx: string }
|
|
16
|
+
* },
|
|
17
|
+
* { properties: { aaa_str: string };
|
|
18
|
+
* customEvents: { aaa_yyy: string }
|
|
19
|
+
* }>;
|
|
20
|
+
*
|
|
21
|
+
* // 等同下面的类型
|
|
22
|
+
* type $CustomA = {
|
|
23
|
+
* properties: {
|
|
24
|
+
* aaa_num: number;
|
|
25
|
+
* aaa_str: string;
|
|
26
|
+
* };
|
|
27
|
+
* customEvents: {
|
|
28
|
+
* aaa_xxx: string;
|
|
29
|
+
* aaa_yyy: string;
|
|
30
|
+
* };
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
export type ExtendComponentType<TOriginalComponentType extends ComponentType, TExtensionType extends Validator<TOriginalComponentType, TExtensionType>> = ComputeIntersectionDeep<TOriginalComponentType & TExtensionType>;
|
|
34
|
+
export {};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
// type test0 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
3
|
+
// type test1 = ExtendComponentType<{ customEvents: { aaa_xxx: string } }, { customEvents: { aaa_xxx: string } }>; // => "aaa_xxx字段重复"
|
|
4
|
+
// type test2 = ExtendComponentType<{ properties: { aaa_xxx: string } }, { properties: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
|
5
|
+
// type test3 = ExtendComponentType<{ customEvents: { aaa_xxx: string } }, { customEvents: { ddd_xxx: string } }>; // => "前缀错误,应为aaa"
|
|
6
|
+
//# sourceMappingURL=ExtendComponentType.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExtendComponentType.js","sourceRoot":"","sources":["../../src/types/ExtendComponentType.ts"],"names":[],"mappings":";AAqDA,kIAAkI;AAElI,sIAAsI;AAEtI,iIAAiI;AAEjI,qIAAqI"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { EmptyObject } from "hry-types/src/Misc/EmptyObject";
|
|
3
|
-
import type {
|
|
3
|
+
import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
|
|
4
4
|
/**
|
|
5
5
|
* 提取文档前缀名
|
|
6
6
|
*/
|
|
7
|
-
export type GetComponentPrefix<TComponentDoc extends
|
|
7
|
+
export type GetComponentPrefix<TComponentDoc extends ComponentType> = EmptyObject extends TComponentDoc ? never : keyof IfExtends<unknown, TComponentDoc["properties"], TComponentDoc["customEvents"], TComponentDoc["properties"]> extends `${infer P}_${string}` ? P : never;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
|
-
import type {
|
|
2
|
+
import type { ComponentType } from "../api/DefineComponent/ReturnType/ComponentType";
|
|
3
3
|
type _ReplacePrefix<O, TPrefix extends string> = {
|
|
4
4
|
[k in keyof O as k extends `${string}_${infer L}` ? `${TPrefix}_${L}` : k]: O[k];
|
|
5
5
|
};
|
|
@@ -8,7 +8,7 @@ type _ReplacePrefix<O, TPrefix extends string> = {
|
|
|
8
8
|
* @param TComponentDoc - ComponentDoc
|
|
9
9
|
* @returns ComponentDoc
|
|
10
10
|
*/
|
|
11
|
-
export type ReplacePrefix<TComponentDoc extends
|
|
11
|
+
export type ReplacePrefix<TComponentDoc extends ComponentType, TPrefix extends string = ""> = IfExtends<unknown, TComponentDoc["properties"], {}, {
|
|
12
12
|
properties: _ReplacePrefix<TComponentDoc["properties"], TPrefix>;
|
|
13
13
|
}> & IfExtends<unknown, TComponentDoc["customEvents"], {}, {
|
|
14
14
|
customEvents: _ReplacePrefix<TComponentDoc["customEvents"], TPrefix>;
|
|
@@ -25,7 +25,7 @@ function isSamePattern(a, b) {
|
|
|
25
25
|
* 两个函数使用toString()比较
|
|
26
26
|
* 支持Date,RegExp
|
|
27
27
|
*/
|
|
28
|
-
export function
|
|
28
|
+
export function deepEqual(a, b) {
|
|
29
29
|
// 如果两个值是原始类型或null,直接用Object.is比较
|
|
30
30
|
if (a === null || b === null || typeof a !== "object" || typeof b !== "object") {
|
|
31
31
|
if (typeof a !== "function" || typeof b !== "function") {
|
|
@@ -55,7 +55,7 @@ export function isEqual(a, b) {
|
|
|
55
55
|
for (const key of keysA) {
|
|
56
56
|
if (keysB.includes(key)) {
|
|
57
57
|
// @ts-ignore
|
|
58
|
-
if (!
|
|
58
|
+
if (!deepEqual(a[key], b[key])) {
|
|
59
59
|
return false;
|
|
60
60
|
}
|
|
61
61
|
}
|
|
@@ -66,4 +66,4 @@ export function isEqual(a, b) {
|
|
|
66
66
|
// 如果以上的条件都满足,说明两个值是深度相等的
|
|
67
67
|
return true;
|
|
68
68
|
}
|
|
69
|
-
//# sourceMappingURL=
|
|
69
|
+
//# sourceMappingURL=deepEqual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"deepEqual.js","sourceRoot":"","sources":["../../src/utils/deepEqual.ts"],"names":[],"mappings":"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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "annil",
|
|
3
|
-
"version": "1.7.5
|
|
3
|
+
"version": "1.7.5",
|
|
4
4
|
"description": "微信小程序(原生开发)插件",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "src/index.ts",
|
|
@@ -40,8 +40,7 @@
|
|
|
40
40
|
"CHANGELOG.md",
|
|
41
41
|
"README.md",
|
|
42
42
|
"src",
|
|
43
|
-
"dist"
|
|
44
|
-
"tsconfig.json"
|
|
43
|
+
"dist"
|
|
45
44
|
],
|
|
46
45
|
"keywords": [
|
|
47
46
|
"mini",
|
|
@@ -1,32 +1,32 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RootComponentType } from "../../../RootComponent/RootComponentType";
|
|
2
2
|
import { DefineComponent } from "../..";
|
|
3
3
|
|
|
4
4
|
DefineComponent({
|
|
5
5
|
// @ts-expect-error 1 RootComponentDoc中isPage为true时 应该书写page字段
|
|
6
6
|
name: "test",
|
|
7
|
-
rootComponent: { isPage: true } satisfies
|
|
7
|
+
rootComponent: { isPage: true } satisfies RootComponentType,
|
|
8
8
|
});
|
|
9
9
|
|
|
10
10
|
DefineComponent({
|
|
11
11
|
// @ts-expect-error 2 RootComponentDoc中isPage不为true时 应该书写name字段
|
|
12
12
|
path: "/pages/index/index",
|
|
13
|
-
rootComponent: {} satisfies
|
|
13
|
+
rootComponent: {} satisfies RootComponentType,
|
|
14
14
|
});
|
|
15
15
|
|
|
16
16
|
DefineComponent({
|
|
17
17
|
// @ts-expect-error 3 页面路径已'/'开头
|
|
18
18
|
path: "pages/index/index",
|
|
19
|
-
rootComponent: { isPage: true } satisfies
|
|
19
|
+
rootComponent: { isPage: true } satisfies RootComponentType,
|
|
20
20
|
});
|
|
21
21
|
|
|
22
22
|
DefineComponent({
|
|
23
23
|
// @ts-expect-error 4 组件名不可为空
|
|
24
24
|
name: "",
|
|
25
|
-
rootComponent: {} satisfies
|
|
25
|
+
rootComponent: {} satisfies RootComponentType,
|
|
26
26
|
});
|
|
27
27
|
|
|
28
28
|
DefineComponent({
|
|
29
29
|
// @ts-expect-error 5 组件名不可包含下划线 _
|
|
30
30
|
name: "ddd_ddd",
|
|
31
|
-
rootComponent: {} satisfies
|
|
31
|
+
rootComponent: {} satisfies RootComponentType,
|
|
32
32
|
});
|
|
@@ -1,16 +1,15 @@
|
|
|
1
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
1
|
type PrefixKeys = `${string}_${string}`;
|
|
3
2
|
|
|
4
|
-
type
|
|
5
|
-
properties?: Record<PrefixKeys,
|
|
6
|
-
customEvents?: Record<PrefixKeys,
|
|
3
|
+
type _ComponentType = {
|
|
4
|
+
properties?: Record<PrefixKeys, unknown>;
|
|
5
|
+
customEvents?: Record<PrefixKeys, unknown>;
|
|
7
6
|
};
|
|
8
7
|
|
|
9
8
|
type Error = "{ properties?: Record<PrefixKeys, any>; customEvents?: Record<PrefixKeys, any>;}";
|
|
10
9
|
|
|
11
|
-
type _Validator<O> = keyof O extends keyof
|
|
10
|
+
type _Validator<O> = keyof O extends keyof _ComponentType
|
|
12
11
|
// @ts-ignore 要求ComponentDoc有前缀
|
|
13
|
-
? keyof (O["properties"] & O["customEvents"]) extends PrefixKeys ?
|
|
12
|
+
? keyof (O["properties"] & O["customEvents"]) extends PrefixKeys ? _ComponentType
|
|
14
13
|
: Error
|
|
15
14
|
: Error;
|
|
16
15
|
|
|
@@ -23,4 +22,4 @@ type _Validator<O> = keyof O extends keyof _ComponentDoc
|
|
|
23
22
|
* };
|
|
24
23
|
* ```
|
|
25
24
|
*/
|
|
26
|
-
export type
|
|
25
|
+
export type ComponentType<O extends _Validator<O> = _ComponentType> = O;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
3
|
import type { AddNullForObject } from "../../../types/AddNullForObject";
|
|
4
|
-
import type {
|
|
5
|
-
import type {
|
|
4
|
+
import type { RootComponentType } from "../../RootComponent/RootComponentType";
|
|
5
|
+
import type { SubComponentType } from "../../SubComponent/SubComponentType";
|
|
6
6
|
import type { GetCustomEventDocOfSubDoc } from "./GetCustomEventDocOfSubDoc";
|
|
7
7
|
|
|
8
8
|
// 获取RootComponetDoc中events字段类型阻止事件(后最为catch)的key `${ 组件前缀 }_${infer Key}_${ bubbles | capture }_catch`
|
|
9
9
|
type GetStopKeys<O> = { [k in keyof O]: k extends `${string}_${infer Key}_${string}_catch` ? Key : never }[keyof O];
|
|
10
10
|
|
|
11
11
|
export type CreateComponentDoc<
|
|
12
|
-
TRootDoc extends
|
|
12
|
+
TRootDoc extends RootComponentType,
|
|
13
13
|
TName extends string,
|
|
14
|
-
TSubComponentTuple extends
|
|
14
|
+
TSubComponentTuple extends SubComponentType[],
|
|
15
15
|
// 获取RootDoc和SubComponent[]中所有的properties字段类型
|
|
16
16
|
AllPropertiesDoc extends unknown | object = TRootDoc["properties"],
|
|
17
17
|
AllCustomEventsDoc extends unknown | object =
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
3
|
-
import type {
|
|
3
|
+
import type { RootComponentType } from "../../RootComponent/RootComponentType";
|
|
4
4
|
|
|
5
5
|
export type CreatePageDoc<
|
|
6
|
-
TRootDoc extends
|
|
6
|
+
TRootDoc extends RootComponentType,
|
|
7
7
|
TPath extends string,
|
|
8
8
|
> = ComputeIntersection<
|
|
9
9
|
& { path: TPath }
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import type { IsNever, IsUnion } from "hry-types/src/Any/_api";
|
|
2
2
|
import type { UnionTwoObject } from "hry-types/src/Object/UnionTwoObject";
|
|
3
3
|
import type { Last } from "hry-types/src/Union/Last";
|
|
4
|
-
import type {
|
|
4
|
+
import type { SubComponentType } from "../../SubComponent/SubComponentType";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
* 因为子组件文档customEvents字段有可能相同(无前缀),所以使用UnionTwoObject
|
|
8
8
|
* 由于SubComponentDoc为空时返回never而不`{}`,所以`Exclude<U, TLast>`不影响结果。
|
|
9
9
|
*/
|
|
10
|
-
type _GetCustomEventDocOfSubDoc<U extends
|
|
10
|
+
type _GetCustomEventDocOfSubDoc<U extends SubComponentType, Result = {}, TLast = Last<U>> = IsNever<U> extends true
|
|
11
11
|
? Result
|
|
12
12
|
: _GetCustomEventDocOfSubDoc<Exclude<U, TLast>, UnionTwoObject<Result, TLast>>;
|
|
13
13
|
|
|
@@ -15,6 +15,6 @@ type _GetCustomEventDocOfSubDoc<U extends SubComponentDoc, Result = {}, TLast =
|
|
|
15
15
|
* 获取子组件自定义事件文档
|
|
16
16
|
* @remarks U 中 相同字段类型联合,所以使用元组推导不如Last性能好。
|
|
17
17
|
*/
|
|
18
|
-
export type GetCustomEventDocOfSubDoc<UnionSubDoc extends
|
|
18
|
+
export type GetCustomEventDocOfSubDoc<UnionSubDoc extends SubComponentType> = IsUnion<UnionSubDoc> extends true
|
|
19
19
|
? _GetCustomEventDocOfSubDoc<UnionSubDoc>
|
|
20
20
|
: UnionSubDoc;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SubComponentType } from "../../SubComponent/SubComponentType";
|
|
2
2
|
|
|
3
3
|
// 获取元组中所有SubComponentDoc的properties字段类型。这里忽略相同key的情况,结果为各个properties对象交叉类型。因为DefinComopnent API 在获取 SubComponentDoc字段类型时做了相同字段类型报错。
|
|
4
|
-
export type GetPropertiesDocOfSubDoc<Tuple extends
|
|
5
|
-
[infer Head extends
|
|
4
|
+
export type GetPropertiesDocOfSubDoc<Tuple extends SubComponentType[], Result = unknown> = Tuple extends
|
|
5
|
+
[infer Head extends SubComponentType, ...infer Rest extends SubComponentType[]]
|
|
6
6
|
? GetPropertiesDocOfSubDoc<Rest, Result & Head["properties"]>
|
|
7
7
|
: Result;
|
|
@@ -16,8 +16,8 @@ import type {
|
|
|
16
16
|
import type { ComputeIntersection } from "hry-types/src/Object/ComputeIntersection";
|
|
17
17
|
import type { PropertiesConstraint } from "../../../RootComponent/Properties/PropertiesConstraint";
|
|
18
18
|
import type { Mock_User } from "../../../RootComponent/Properties/test/normalRequired.test";
|
|
19
|
-
import type {
|
|
20
|
-
import type {
|
|
19
|
+
import type { RootComponentType } from "../../../RootComponent/RootComponentType";
|
|
20
|
+
import type { SubComponentType } from "../../../SubComponent/SubComponentType";
|
|
21
21
|
import { DefineComponent } from "../..";
|
|
22
22
|
|
|
23
23
|
const properties = {
|
|
@@ -123,7 +123,7 @@ const compDoc = DefineComponent({
|
|
|
123
123
|
|
|
124
124
|
Checking<typeof compDoc, ComputeIntersection<CompOnlyCustomEventsExpected & OnlyPropertiesExpected>, Test.Pass>;
|
|
125
125
|
|
|
126
|
-
type SubA =
|
|
126
|
+
type SubA = SubComponentType<{
|
|
127
127
|
str: string | Bubbles | Composed;
|
|
128
128
|
num: number | Capture | Composed;
|
|
129
129
|
null: null | Bubbles | Capture | Composed;
|
|
@@ -145,7 +145,7 @@ type customEventsRootDocExpect = {
|
|
|
145
145
|
|
|
146
146
|
Checking<typeof customEventsRootDoc, customEventsRootDocExpect, Test.Pass>;
|
|
147
147
|
|
|
148
|
-
type SubB =
|
|
148
|
+
type SubB = SubComponentType<{
|
|
149
149
|
str: number | Bubbles | Composed;
|
|
150
150
|
num: string | Capture | Composed;
|
|
151
151
|
null: boolean | Bubbles | Capture | Composed;
|
|
@@ -168,7 +168,7 @@ type WhenSameKeyOfCustomEventsRootDocExpect = {
|
|
|
168
168
|
|
|
169
169
|
Checking<typeof WhenSameKeyOfCustomEventsRootDoc, WhenSameKeyOfCustomEventsRootDocExpect, Test.Pass>;
|
|
170
170
|
|
|
171
|
-
type RootDocCatch =
|
|
171
|
+
type RootDocCatch = RootComponentType<{
|
|
172
172
|
events: {
|
|
173
173
|
aaa_str_bubbles_catch: () => void;
|
|
174
174
|
};
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RootComponentType } from "../../RootComponent/RootComponentType";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* DefineComponent API`rootComponent`字段配置
|
|
5
5
|
*/
|
|
6
|
-
export type RootComponentOption<TRootComponent extends
|
|
6
|
+
export type RootComponentOption<TRootComponent extends RootComponentType> = {
|
|
7
7
|
/**
|
|
8
8
|
* 根组件配置
|
|
9
9
|
*/
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { SubComponentType } from "../../SubComponent/SubComponentType";
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* RootComponent API 的`subComponents`字段配置
|
|
5
5
|
*/
|
|
6
6
|
export type SubComponentsOption<
|
|
7
|
-
TSubComponentTuple extends
|
|
7
|
+
TSubComponentTuple extends SubComponentType[],
|
|
8
8
|
> = {
|
|
9
9
|
/**
|
|
10
10
|
* 子组件列表
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { Checking, type Test } from "hry-types";
|
|
2
2
|
import type { Bubbles, Composed } from "../../../RootComponent/CustomEvents/CustomEventsTag";
|
|
3
|
-
import type {
|
|
3
|
+
import type { SubComponentType } from "../../../SubComponent/SubComponentType";
|
|
4
4
|
import { DefineComponent } from "../..";
|
|
5
5
|
|
|
6
|
-
const SubDocIsAny = {} as
|
|
6
|
+
const SubDocIsAny = {} as SubComponentType<{
|
|
7
7
|
a: number | Composed;
|
|
8
8
|
}>;
|
|
9
9
|
|
|
10
|
-
const NonEmptyRootDoc = {} as
|
|
10
|
+
const NonEmptyRootDoc = {} as SubComponentType<{
|
|
11
11
|
a: string | Bubbles | Composed;
|
|
12
12
|
}>;
|
|
13
13
|
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IfExtends } from "hry-types/src/Any/IfExtends";
|
|
2
2
|
import type { RootComponentTrueOptions } from "../RootComponent";
|
|
3
|
-
import type {
|
|
4
|
-
import type {
|
|
3
|
+
import type { RootComponentType } from "../RootComponent/RootComponentType";
|
|
4
|
+
import type { SubComponentType } from "../SubComponent/SubComponentType";
|
|
5
5
|
import type { NameOrPathOption } from "./NameOrPage/NameOrPathOption";
|
|
6
6
|
import { normalizeOptions } from "./normalizeOptions";
|
|
7
7
|
import type { CreateComponentDoc } from "./ReturnType/CreateComponentDoc";
|
|
@@ -11,8 +11,8 @@ import type { SubComponentsOption } from "./SubComponents/SubComponentsOption";
|
|
|
11
11
|
export type Path = `/${string}`;
|
|
12
12
|
|
|
13
13
|
type RootOptions<
|
|
14
|
-
TRootComponentDoc extends
|
|
15
|
-
TSubComponentTuple extends
|
|
14
|
+
TRootComponentDoc extends RootComponentType,
|
|
15
|
+
TSubComponentTuple extends SubComponentType[],
|
|
16
16
|
TName extends string,
|
|
17
17
|
TPath extends Path,
|
|
18
18
|
> =
|
|
@@ -21,8 +21,8 @@ type RootOptions<
|
|
|
21
21
|
& SubComponentsOption<TSubComponentTuple>;
|
|
22
22
|
|
|
23
23
|
type DefineComponentConstructor = <
|
|
24
|
-
TRootComponentDoc extends
|
|
25
|
-
TSubComponentTuple extends
|
|
24
|
+
TRootComponentDoc extends RootComponentType = {},
|
|
25
|
+
TSubComponentTuple extends SubComponentType[] = [],
|
|
26
26
|
TName extends string = "",
|
|
27
27
|
TPath extends Path = "/",
|
|
28
28
|
>(
|
|
@@ -41,7 +41,7 @@ export type DefineComponentOption = {
|
|
|
41
41
|
name?: string;
|
|
42
42
|
path?: string;
|
|
43
43
|
rootComponent?: RootComponentTrueOptions;
|
|
44
|
-
subComponents?:
|
|
44
|
+
subComponents?: SubComponentType[];
|
|
45
45
|
};
|
|
46
46
|
|
|
47
47
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { deepEqual } from "../../../../utils/deepEqual";
|
|
1
2
|
import type { Instance } from "../../../RootComponent/Instance/RootComponentInstance";
|
|
2
3
|
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
3
4
|
import { removeSubDependences } from "./dependencesOptimize";
|
|
4
5
|
import { getPathsValue } from "./getPathsValue";
|
|
5
6
|
|
|
6
|
-
import { isEqual } from "./isEqual";
|
|
7
7
|
export type ComputedDependence = { paths: string[]; val: unknown };
|
|
8
8
|
|
|
9
9
|
export function computedUpdater(this: Instance, isUpdated = false): boolean {
|
|
@@ -15,7 +15,7 @@ export function computedUpdater(this: Instance, isUpdated = false): boolean {
|
|
|
15
15
|
const curVal = getPathsValue(this.data, dep.paths.join("."))[0];
|
|
16
16
|
|
|
17
17
|
// 检查依赖是否更新
|
|
18
|
-
if (!
|
|
18
|
+
if (!deepEqual(curVal, dep.val)) {
|
|
19
19
|
changed = true;
|
|
20
20
|
|
|
21
21
|
break;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
2
|
+
import { deepEqual } from "../../../../utils/deepEqual";
|
|
2
3
|
import { computedUpdater } from "./computedUpdater";
|
|
3
4
|
import { getPathsValue } from "./getPathsValue";
|
|
4
5
|
import { getPropertiesValue } from "./getPropertiesValue";
|
|
5
6
|
import { initComputedAndGetCache } from "./initComputedAndGetCache";
|
|
6
|
-
import { isEqual } from "./isEqual";
|
|
7
7
|
|
|
8
8
|
import { assertNonNullable } from "../../../../utils/assertNonNullable";
|
|
9
9
|
import { deepClone } from "../../../../utils/deepClone";
|
|
@@ -71,7 +71,7 @@ export function computedWatchHandle(options: FinalOptionsOfComponent) {
|
|
|
71
71
|
const watchOldValue = assertNonNullable(this.data.__watchOldValue__);
|
|
72
72
|
const oldValue = watchOldValue[key];
|
|
73
73
|
|
|
74
|
-
if (
|
|
74
|
+
if (deepEqual(newValue, oldValue)) return;
|
|
75
75
|
watchOldValue[key] = deepClone(newValue);
|
|
76
76
|
|
|
77
77
|
watchHadle.call(this, ...newValue, ...oldValue);
|