annil 1.6.2 → 1.6.3
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/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js +4 -4
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.d.ts +3 -0
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js +16 -8
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/index.js +2 -2
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/index.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.d.ts +12 -0
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/{initComputed.js → initComputedAndGetCache.js} +17 -26
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js.map +1 -0
- package/dist/api/DefineComponent/assignOptions/index.d.ts +1 -1
- package/package.json +1 -1
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.ts +5 -4
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.ts +20 -16
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/index.ts +9 -5
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/{initComputed.ts → initComputedAndGetCache.ts} +38 -57
- package/src/api/DefineComponent/assignOptions/index.ts +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputed.d.ts +0 -12
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputed.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
* 解决DetailedType不接收接口类型的错误 ([ae8acbf](https://github.com/missannil/annil/commit/ae8acbfc2e62f99db565c448ad9253aa549e78bb))
|
|
6
6
|
|
|
7
|
+
## [1.6.3](https://github.com/missannil/annil/compare/v1.6.2...v1.6.3) (2024-02-05)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* 计算属性优化 ([2479d08](https://github.com/missannil/annil/commit/2479d08720b2e69782c063b5fde394f0fa35d28a))
|
|
13
|
+
|
|
7
14
|
## [1.6.2](https://github.com/missannil/annil/compare/v1.6.1...v1.6.2) (2024-02-03)
|
|
8
15
|
|
|
9
16
|
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { deepProxy } from "./data-tracer";
|
|
1
|
+
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
3
2
|
import { getPathsValue } from "./getPathsValue";
|
|
4
3
|
import { isEqual } from "./isEqual";
|
|
5
4
|
export function computedUpdater(isUpdated = false) {
|
|
@@ -15,9 +14,10 @@ export function computedUpdater(isUpdated = false) {
|
|
|
15
14
|
}
|
|
16
15
|
if (changed) {
|
|
17
16
|
const newDependences = [];
|
|
18
|
-
|
|
17
|
+
let newValue = itemCache.method.call({ data: deepProxy(this.data, newDependences) });
|
|
18
|
+
newValue = getProxyOriginalValue(newValue);
|
|
19
19
|
this.setData({
|
|
20
|
-
[key]:
|
|
20
|
+
[key]: newValue,
|
|
21
21
|
});
|
|
22
22
|
isUpdated = true;
|
|
23
23
|
this.data.__computedCache__[key].dependences = newDependences;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"computedUpdater.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"computedUpdater.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,eAAe,C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QAC/C,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { ComputedDependence } from "./computedUpdater";
|
|
2
2
|
export declare function deepProxy(data: object, dependences: ComputedDependence[], basePath?: string[]): object;
|
|
3
|
+
export declare function getProxyOriginalValue<T extends {
|
|
4
|
+
__original__?: string;
|
|
5
|
+
}>(value: T): unknown;
|
|
@@ -2,18 +2,18 @@ import { deepClone } from "../../../../utils/deepClone";
|
|
|
2
2
|
export function deepProxy(data, dependences, basePath = []) {
|
|
3
3
|
const handler = {
|
|
4
4
|
get(target, prop) {
|
|
5
|
+
if (prop === "__original__") {
|
|
6
|
+
return target;
|
|
7
|
+
}
|
|
5
8
|
const val = target[prop];
|
|
9
|
+
if ((val !== undefined) && (!Object.prototype.hasOwnProperty.call(target, prop) || typeof val === "function")) {
|
|
10
|
+
return val.bind(target);
|
|
11
|
+
}
|
|
6
12
|
if (basePath.length !== 0) {
|
|
7
|
-
|
|
8
|
-
if (lastDependences.paths.toString() === basePath.toString()) {
|
|
9
|
-
dependences.pop();
|
|
10
|
-
}
|
|
13
|
+
dependences.pop();
|
|
11
14
|
}
|
|
12
15
|
const curPath = basePath.concat(prop);
|
|
13
|
-
dependences.push({ paths: curPath, val
|
|
14
|
-
if (!Object.prototype.hasOwnProperty.call(target, prop) || typeof val === "function") {
|
|
15
|
-
return typeof val === "function" ? val.bind(target) : val;
|
|
16
|
-
}
|
|
16
|
+
dependences.push({ paths: curPath, val });
|
|
17
17
|
if (typeof val !== "object" || val === null)
|
|
18
18
|
return val;
|
|
19
19
|
return deepProxy(val, dependences, curPath);
|
|
@@ -24,4 +24,12 @@ export function deepProxy(data, dependences, basePath = []) {
|
|
|
24
24
|
};
|
|
25
25
|
return new Proxy(data, handler);
|
|
26
26
|
}
|
|
27
|
+
export function getProxyOriginalValue(value) {
|
|
28
|
+
if (typeof value !== "object" || value === null || !value.__original__) {
|
|
29
|
+
return value;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
return deepClone(value.__original__);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
27
35
|
//# sourceMappingURL=data-tracer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-tracer.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAGxD,MAAM,UAAU,SAAS,CACvB,IAAY,EACZ,WAAiC,EACjC,WAAqB,EAAE;IAEvB,MAAM,OAAO,GAAG;QACd,GAAG,CAAmB,MAAS,EAAE,IAAsB;YACrD,
|
|
1
|
+
{"version":3,"file":"data-tracer.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAGxD,MAAM,UAAU,SAAS,CACvB,IAAY,EACZ,WAAiC,EACjC,WAAqB,EAAE;IAEvB,MAAM,OAAO,GAAG;QACd,GAAG,CAAmB,MAAS,EAAE,IAAsB;YACrD,IAAI,IAAI,KAAK,cAAc,EAAE,CAAC;gBAC5B,OAAO,MAAM,CAAC;YAChB,CAAC;YACD,MAAM,GAAG,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC;YAGzB,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,OAAO,GAAG,KAAK,UAAU,CAAC,EAAE,CAAC;gBAE9G,OAAQ,GAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACxC,CAAC;YAED,IAAI,QAAQ,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;gBAC1B,WAAW,CAAC,GAAG,EAAE,CAAC;YACpB,CAAC;YACD,MAAM,OAAO,GAAG,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;YAEtC,WAAW,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,GAAG,EAAE,CAAC,CAAC;YAG1C,IAAI,OAAO,GAAG,KAAK,QAAQ,IAAI,GAAG,KAAK,IAAI;gBAAE,OAAO,GAAG,CAAC;YAExD,OAAO,SAAS,CAAC,GAAG,EAAE,WAAW,EAAE,OAAO,CAAC,CAAC;QAC9C,CAAC;QACD,GAAG,CAAC,OAAe,EAAE,IAAY;YAC/B,MAAM,KAAK,CAAC,GAAG,IAAI,QAAQ,CAAC,CAAC;QAC/B,CAAC;KACF,CAAC;IAEF,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAsC,KAAQ;IACjF,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,CAAC,KAAK,CAAC,YAAY,EAAE,CAAC;QACvE,OAAO,KAAK,CAAC;IACf,CAAC;SAAM,CAAC;QACN,OAAO,SAAS,CAAC,KAAK,CAAC,YAAY,CAAC,CAAC;IACvC,CAAC;AACH,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { computedUpdater } from "./computedUpdater";
|
|
2
2
|
import { getPathsValue } from "./getPathsValue";
|
|
3
3
|
import { getPropertiesValue } from "./getPropertiesValue";
|
|
4
|
-
import {
|
|
4
|
+
import { initComputedAndGetCache } from "./initComputedAndGetCache";
|
|
5
5
|
import { isEqual } from "./isEqual";
|
|
6
6
|
import { deepClone } from "../../../../utils/deepClone";
|
|
7
7
|
import { isEmptyObject } from "../../../../utils/isEmptyObject";
|
|
@@ -16,7 +16,7 @@ export function computedWatchHandle(options) {
|
|
|
16
16
|
const computedConfig = options.computed;
|
|
17
17
|
const rawPropertiesValue = getPropertiesValue(options.properties);
|
|
18
18
|
if (computedConfig && !isEmptyObject(computedConfig)) {
|
|
19
|
-
const __computedInitCache__ =
|
|
19
|
+
const __computedInitCache__ = initComputedAndGetCache(options, computedConfig, Object.assign(Object.assign({}, options.data), rawPropertiesValue));
|
|
20
20
|
options.data.__computedCache__ = __computedInitCache__;
|
|
21
21
|
options.methods.__computedUpdater__ = computedUpdater;
|
|
22
22
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AACpE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAEpC,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AACxD,OAAO,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AAKhE,SAAS,iBAAiB,CAAC,IAAqC,EAAE,WAAmB;IACnF,MAAM,aAAa,GAAG,EAAE,CAAC;IACzB,KAAK,MAAM,GAAG,IAAI,WAAW,EAAE,CAAC;QAM9B,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,aAAa,CAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC;IAC3D,CAAC;IAED,OAA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AGvE,eAAe,CAAC,GAAG,CAAC,GAAG,UAAyB,GAAG,QAAmB;gBACpE,qBAAqB,IAAI,qBAAqB,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,QAAQ,CAAC,CAAC;gBAEvE,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAkB,CAAC;gBACnD,MAAM,QAAQ,GAAG,aAAa,CAAC,GAAG,CAAC,CAAC;gBAEpC,IAAI,OAAO,CAAC,QAAQ,EAAE,QAAQ,CAAC;oBAAE,OAAO;gBACxC,aAAa,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;gBAEzC,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,QAAQ,EAAE,GAAG,QAAQ,CAAC,CAAC;YAClD,CAAC,CAAC;QACJ,CAAC;IACH,CAAC;AACH,CAAC"}
|
package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.d.ts
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Func } from "hry-types/src/Misc/Func";
|
|
2
|
+
import type { FinalOptionsOfComponent } from "..";
|
|
3
|
+
import type { ComputedDependence } from "./computedUpdater";
|
|
4
|
+
type ItemCache = {
|
|
5
|
+
dependences: ComputedDependence[];
|
|
6
|
+
method: Func;
|
|
7
|
+
value: unknown;
|
|
8
|
+
};
|
|
9
|
+
type ComputedId = string;
|
|
10
|
+
export type ComputedCache = Record<ComputedId, ItemCache>;
|
|
11
|
+
export declare function initComputedAndGetCache(options: FinalOptionsOfComponent, computedConfig: Record<string, Func>, initAllData: Record<string, unknown>, uninitedkeys?: string[], computedCache?: ComputedCache): ComputedCache;
|
|
12
|
+
export {};
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { deepProxy } from "./data-tracer";
|
|
1
|
+
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
3
2
|
function isValidDependences(dependences, computedKeys) {
|
|
4
3
|
for (const { paths: path, val } of dependences) {
|
|
5
4
|
if ((val === undefined) && computedKeys.includes(path[0])) {
|
|
@@ -8,20 +7,6 @@ function isValidDependences(dependences, computedKeys) {
|
|
|
8
7
|
}
|
|
9
8
|
return true;
|
|
10
9
|
}
|
|
11
|
-
export function getItemCache(initAllData, computedKeys, computedFunc) {
|
|
12
|
-
const dependences = [];
|
|
13
|
-
const initValue = computedFunc.call({ data: deepProxy(initAllData, dependences) });
|
|
14
|
-
if (isValidDependences(dependences, computedKeys)) {
|
|
15
|
-
return {
|
|
16
|
-
dependences: uniqueDependences(dependences),
|
|
17
|
-
method: computedFunc,
|
|
18
|
-
value: deepClone(initValue),
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
else {
|
|
22
|
-
return false;
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
10
|
function uniqueDependences(dependences) {
|
|
26
11
|
if (dependences.length === 1)
|
|
27
12
|
return dependences;
|
|
@@ -41,23 +26,29 @@ function uniqueDependences(dependences) {
|
|
|
41
26
|
}
|
|
42
27
|
return dependences;
|
|
43
28
|
}
|
|
44
|
-
export function
|
|
29
|
+
export function initComputedAndGetCache(options, computedConfig, initAllData, uninitedkeys = Object.keys(computedConfig), computedCache = {}) {
|
|
45
30
|
for (const key of uninitedkeys) {
|
|
46
|
-
const
|
|
31
|
+
const computedFunc = computedConfig[key];
|
|
32
|
+
const dependences = [];
|
|
33
|
+
let initValue = computedFunc.call({ data: deepProxy(initAllData, dependences) });
|
|
47
34
|
uninitedkeys = uninitedkeys.filter(ele => ele !== key);
|
|
48
|
-
if (
|
|
49
|
-
|
|
35
|
+
if (isValidDependences(dependences, uninitedkeys)) {
|
|
36
|
+
initValue = getProxyOriginalValue(initValue);
|
|
37
|
+
options.data[key] = initValue;
|
|
38
|
+
initAllData[key] = initValue;
|
|
39
|
+
computedCache[key] = {
|
|
40
|
+
dependences: uniqueDependences(dependences),
|
|
41
|
+
method: computedFunc,
|
|
42
|
+
value: initValue,
|
|
43
|
+
};
|
|
50
44
|
}
|
|
51
45
|
else {
|
|
52
|
-
|
|
53
|
-
dataOpt[key] = itemCache.value;
|
|
54
|
-
initAllData[key] = itemCache.value;
|
|
55
|
-
computedCache[key] = itemCache;
|
|
46
|
+
uninitedkeys.push(key);
|
|
56
47
|
}
|
|
57
48
|
}
|
|
58
49
|
if (uninitedkeys.length === 0) {
|
|
59
50
|
return computedCache;
|
|
60
51
|
}
|
|
61
|
-
return
|
|
52
|
+
return initComputedAndGetCache(options, computedConfig, initAllData, uninitedkeys, computedCache);
|
|
62
53
|
}
|
|
63
|
-
//# sourceMappingURL=
|
|
54
|
+
//# sourceMappingURL=initComputedAndGetCache.js.map
|
package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"initComputedAndGetCache.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,SAAS,EAAE,qBAAqB,EAAE,MAAM,eAAe,CAAC;AAejE,SAAS,kBAAkB,CAAC,WAAiC,EAAE,YAAsB;IACnF,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,WAAW,EAAE,CAAC;QAC/C,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAGD,OAAO,IAAI,CAAC;AACd,CAAC;AAWD,SAAS,iBAAiB,CAAC,WAAiC;IAC1D,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC;IACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAA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C;QAGvD,IAAI,kBAAkB,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,CAAC;YAClD,SAAS,GAAG,qBAAqB,CAAC,SAAS,CAAC,CAAC;YAG7C,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;YAG9B,WAAW,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;YAE7B,aAAa,CAAC,GAAG,CAAC,GAAG;gBACnB,WAAW,EAAE,iBAAiB,CAAC,WAAW,CAAC;gBAC3C,MAAM,EAAE,YAAY;gBACpB,KAAK,EAAE,SAAS;aACjB,CAAC;QACJ,CAAC;aAAM,CAAC;YAEN,YAAY,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACzB,CAAC;IACH,CAAC;IAED,IAAI,YAAY,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;QAC9B,OAAO,aAAa,CAAC;IACvB,CAAC;IAGD,OAAO,uBAAuB,CAAC,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,YAAY,EAAE,aAAa,CAAC,CAAC;AACpG,CAAC"}
|
|
@@ -9,7 +9,7 @@ import type { PageLifetimesOption } from "../../RootComponent/PageLifetimes/Page
|
|
|
9
9
|
import type { PropertiesConstraint } from "../../RootComponent/Properties/PropertiesConstraint";
|
|
10
10
|
import type { StoreConstraint } from "../../RootComponent/Store/StoreConstraint";
|
|
11
11
|
import type { DefineComponentOption } from "..";
|
|
12
|
-
import type { ComputedCache } from "./computedWatchHandle/
|
|
12
|
+
import type { ComputedCache } from "./computedWatchHandle/initComputedAndGetCache";
|
|
13
13
|
type InstanceInnerFields = {
|
|
14
14
|
data: OptionsInnerFields["data"];
|
|
15
15
|
disposer: Record<string, Func>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { deepClone } from "../../../../utils/deepClone";
|
|
2
1
|
import type { Instance } from "..";
|
|
3
|
-
import { deepProxy } from "./data-tracer";
|
|
2
|
+
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
4
3
|
import { getPathsValue } from "./getPathsValue";
|
|
5
4
|
|
|
6
5
|
import { isEqual } from "./isEqual";
|
|
@@ -23,11 +22,13 @@ export function computedUpdater(this: Instance, isUpdated = false): boolean {
|
|
|
23
22
|
}
|
|
24
23
|
if (changed) {
|
|
25
24
|
const newDependences: ComputedDependence[] = [];
|
|
26
|
-
|
|
25
|
+
let newValue = itemCache.method.call({ data: deepProxy(this.data, newDependences) });
|
|
27
26
|
|
|
28
27
|
// 更新值不会立即再次进入**函数,而是当前**函数运行完毕后触发**函数,
|
|
28
|
+
newValue = getProxyOriginalValue(newValue);
|
|
29
|
+
|
|
29
30
|
this.setData({
|
|
30
|
-
[key]:
|
|
31
|
+
[key]: newValue,
|
|
31
32
|
});
|
|
32
33
|
|
|
33
34
|
isUpdated = true;
|
|
@@ -8,28 +8,24 @@ export function deepProxy(
|
|
|
8
8
|
): object {
|
|
9
9
|
const handler = {
|
|
10
10
|
get<T extends object>(target: T, prop: keyof T & string) {
|
|
11
|
+
if (prop === "__original__") {
|
|
12
|
+
return target;
|
|
13
|
+
}
|
|
11
14
|
const val = target[prop];
|
|
12
|
-
|
|
15
|
+
|
|
16
|
+
// val不为undefined(依赖还为初始化的其他计算属性)且非自身属性或函数不再返回代理。 (如 this.data.arr.slice(),slice不属于自身属性,小程序允许data子字段为函数的情况,也不代理)
|
|
17
|
+
if ((val !== undefined) && (!Object.prototype.hasOwnProperty.call(target, prop) || typeof val === "function")) {
|
|
18
|
+
// val有不是函数的情况么?
|
|
19
|
+
return (val as Function).bind(target);
|
|
20
|
+
}
|
|
21
|
+
// 依赖长度不为0时径依赖去重(只留最后一个路径),比如 return this.data.obj.user.name 去重得到的是最后1个路径 ['obj','user','name'] , 不去重则3个依赖路径了 ['obj'], ['obj','user'],['obj','user','name'],在这里去重效率高些,外部去重时还要再次遍历
|
|
13
22
|
if (basePath.length !== 0) {
|
|
14
|
-
|
|
15
|
-
const lastDependences = dependences[dependences.length - 1]; // 倒数第一个是当前依赖。2022 at(-1)
|
|
16
|
-
// 只留最后一个路径。比如 return this.data.obj.user.name 得到的是最后1个路径 ['obj','user','name'] 减少无效依赖,提高性能。 而非3个 ['obj'], ['obj','user'],['obj','user','name']
|
|
17
|
-
if (lastDependences.paths.toString() === basePath.toString()) {
|
|
18
|
-
// console.log('删除', lastDependences)
|
|
19
|
-
dependences.pop();
|
|
20
|
-
}
|
|
23
|
+
dependences.pop();
|
|
21
24
|
}
|
|
22
25
|
const curPath = basePath.concat(prop);
|
|
23
26
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
dependences.push({ paths: curPath, val: deepClone(val) });
|
|
27
|
+
dependences.push({ paths: curPath, val });
|
|
27
28
|
|
|
28
|
-
// 自身方法或原型属性不代理
|
|
29
|
-
if (!Object.prototype.hasOwnProperty.call(target, prop) || typeof val === "function") {
|
|
30
|
-
// 原型链上的属性不代理,函数加bind。如 this.data.arr.slice() this.data.arr.forEach(...)
|
|
31
|
-
return typeof val === "function" ? val.bind(target) : val;
|
|
32
|
-
}
|
|
33
29
|
// 非对象不代理
|
|
34
30
|
if (typeof val !== "object" || val === null) return val;
|
|
35
31
|
|
|
@@ -42,3 +38,11 @@ export function deepProxy(
|
|
|
42
38
|
|
|
43
39
|
return new Proxy(data, handler);
|
|
44
40
|
}
|
|
41
|
+
|
|
42
|
+
export function getProxyOriginalValue<T extends { __original__?: string }>(value: T): unknown {
|
|
43
|
+
if (typeof value !== "object" || value === null || !value.__original__) {
|
|
44
|
+
return value;
|
|
45
|
+
} else {
|
|
46
|
+
return deepClone(value.__original__);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
@@ -2,7 +2,7 @@ import type { Func } from "hry-types/src/Misc/Func";
|
|
|
2
2
|
import { computedUpdater } from "./computedUpdater";
|
|
3
3
|
import { getPathsValue } from "./getPathsValue";
|
|
4
4
|
import { getPropertiesValue } from "./getPropertiesValue";
|
|
5
|
-
import {
|
|
5
|
+
import { initComputedAndGetCache } from "./initComputedAndGetCache";
|
|
6
6
|
import { isEqual } from "./isEqual";
|
|
7
7
|
|
|
8
8
|
import { deepClone } from "../../../../utils/deepClone";
|
|
@@ -25,25 +25,29 @@ function initWatchOldValue(data: FinalOptionsOfComponent["data"], watchConfig: o
|
|
|
25
25
|
return watchOldValue;
|
|
26
26
|
}
|
|
27
27
|
export function computedWatchHandle(options: FinalOptionsOfComponent) {
|
|
28
|
-
//
|
|
28
|
+
// 计算属性初始化和首次依赖收集
|
|
29
29
|
const computedConfig = options.computed;
|
|
30
30
|
const rawPropertiesValue = getPropertiesValue(options.properties);
|
|
31
31
|
if (computedConfig && !isEmptyObject(computedConfig)) {
|
|
32
32
|
// 此时store已经初始化数据到data了
|
|
33
33
|
|
|
34
|
-
const __computedInitCache__ =
|
|
34
|
+
const __computedInitCache__ = initComputedAndGetCache(options, computedConfig, {
|
|
35
|
+
...options.data,
|
|
36
|
+
...rawPropertiesValue,
|
|
37
|
+
});
|
|
35
38
|
|
|
39
|
+
// 缓存放入data中
|
|
36
40
|
options.data.__computedCache__ = __computedInitCache__;
|
|
37
41
|
|
|
42
|
+
// 计算属性更新函数放入methods中 要做冲突判断,避免用户定义了同名methods字段
|
|
38
43
|
options.methods.__computedUpdater__ = computedUpdater;
|
|
39
|
-
// // 把计算属性缓存从方法中带入到实例中,在created周期加入实例后删除
|
|
40
|
-
// methodOpt.__computedInitCache__ = () => computedCache;
|
|
41
44
|
}
|
|
42
45
|
const observersConfig = options.observers;
|
|
43
46
|
// 通过observers加入`**`字段来触发计算属性更新
|
|
44
47
|
const originalFunc = observersConfig["**"] as Func | undefined;
|
|
45
48
|
|
|
46
49
|
observersConfig["**"] = function(this: Instance): undefined {
|
|
50
|
+
// 任何setData都会触发计算属性更新(可能依赖数据并没变化)
|
|
47
51
|
this.__computedUpdater__?.();
|
|
48
52
|
|
|
49
53
|
originalFunc && originalFunc.call(this);
|
|
@@ -1,9 +1,8 @@
|
|
|
1
1
|
import type { Func } from "hry-types/src/Misc/Func";
|
|
2
2
|
import type { FinalOptionsOfComponent } from "..";
|
|
3
3
|
|
|
4
|
-
import { deepClone } from "../../../../utils/deepClone";
|
|
5
4
|
import type { ComputedDependence } from "./computedUpdater";
|
|
6
|
-
import { deepProxy } from "./data-tracer";
|
|
5
|
+
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
7
6
|
|
|
8
7
|
type ItemCache = {
|
|
9
8
|
dependences: ComputedDependence[];
|
|
@@ -11,45 +10,22 @@ type ItemCache = {
|
|
|
11
10
|
value: unknown;
|
|
12
11
|
};
|
|
13
12
|
|
|
14
|
-
|
|
13
|
+
type ComputedId = string;
|
|
14
|
+
|
|
15
|
+
export type ComputedCache = Record<ComputedId, ItemCache>;
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
|
-
* 如果依赖列表某项的首个字段值为undefined并且字段为其他计算属性字段 返回false(即被依赖的计算字段写在了依赖他的计算字段后面), 否则返回
|
|
18
|
+
* 如果依赖列表某项的首个字段值为undefined并且字段为其他计算属性字段 返回false(即被依赖的计算字段写在了依赖他的计算字段后面), 否则返回true表示依赖有效。
|
|
18
19
|
*/
|
|
19
20
|
function isValidDependences(dependences: ComputedDependence[], computedKeys: string[]): boolean {
|
|
20
21
|
for (const { paths: path, val } of dependences) {
|
|
21
|
-
// 引用值为undefined时
|
|
22
|
-
// console.log(path[0]);
|
|
23
22
|
if ((val === undefined) && computedKeys.includes(path[0])) {
|
|
24
23
|
return false;
|
|
25
24
|
}
|
|
26
25
|
}
|
|
27
26
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
export function getItemCache(
|
|
32
|
-
initAllData: object,
|
|
33
|
-
computedKeys: string[],
|
|
34
|
-
computedFunc: Func,
|
|
35
|
-
): false | ItemCache {
|
|
36
|
-
// 当前计算字段的依赖列表
|
|
37
|
-
const dependences: ComputedDependence[] = [];
|
|
38
|
-
const initValue = computedFunc.call({ data: deepProxy(initAllData, dependences) });
|
|
39
|
-
|
|
40
|
-
if (isValidDependences(dependences, computedKeys)) {
|
|
41
|
-
return {
|
|
42
|
-
// 去重 避免 如: ` age(){ return this.data.xxx.num + this.data.xxx.str + this.data.xxx} ` 造成的多个依赖相同情况。应就要一个 xxx
|
|
43
|
-
dependences: uniqueDependences(dependences),
|
|
44
|
-
method: computedFunc,
|
|
45
|
-
value: deepClone(initValue),
|
|
46
|
-
};
|
|
47
|
-
} else {
|
|
48
|
-
/**
|
|
49
|
-
* 情形1 依赖了其他未初始化的计算属性(不报错) 对应测试文件[NoOptionalProperties.ts](../../../jest/computed/NoOptionalProperties/NoOptionalProperties.test.ts)的copyPropUser字段
|
|
50
|
-
*/
|
|
51
|
-
return false;
|
|
52
|
-
}
|
|
27
|
+
// 依赖有效
|
|
28
|
+
return true;
|
|
53
29
|
}
|
|
54
30
|
|
|
55
31
|
/**
|
|
@@ -63,24 +39,17 @@ export function getItemCache(
|
|
|
63
39
|
*/
|
|
64
40
|
function uniqueDependences(dependences: ComputedDependence[]): ComputedDependence[] {
|
|
65
41
|
if (dependences.length === 1) return dependences;
|
|
66
|
-
// console.log(dependences);
|
|
67
|
-
|
|
68
42
|
for (let f = 0; f < dependences.length; f++) {
|
|
69
43
|
const firstPath = dependences[f].paths.join(".") + ".";
|
|
70
44
|
for (let i = f + 1; i < dependences.length; i++) {
|
|
71
45
|
const curPath = dependences[i].paths.join(".") + ".";
|
|
72
|
-
// console.log(firstPath,curPath)
|
|
73
46
|
if (firstPath.startsWith(curPath)) {
|
|
74
|
-
// console.log("删除:", curPath, f);
|
|
75
|
-
|
|
76
47
|
// 例如 path[0] = 'a.b.c.',curPath = 'a.b.'
|
|
77
48
|
dependences.splice(f, 1);
|
|
78
49
|
|
|
79
50
|
return uniqueDependences(dependences);
|
|
80
51
|
}
|
|
81
52
|
if (curPath.startsWith(firstPath)) {
|
|
82
|
-
// console.log("删除:", firstPath, i);
|
|
83
|
-
|
|
84
53
|
// 例如 curPath = 'a.b.' path[0] = 'a.b.c.',
|
|
85
54
|
dependences.splice(i, 1);
|
|
86
55
|
|
|
@@ -93,43 +62,55 @@ function uniqueDependences(dependences: ComputedDependence[]): ComputedDependenc
|
|
|
93
62
|
}
|
|
94
63
|
|
|
95
64
|
/**
|
|
96
|
-
* 把计算属性初始值加入到options.data
|
|
65
|
+
* 把计算属性初始值加入到options.data中并返回缓存(递归函数)
|
|
66
|
+
* @param options - 配置选项
|
|
67
|
+
* @param computedConfig - 计算字段配置
|
|
68
|
+
* @param initAllData - 初始化时全部的data包含(properties,data,和已经初始化后的computed字段)
|
|
69
|
+
* @param uninitedkeys - 未初始化的key (默认为所有computedConfig的key)
|
|
70
|
+
* @param computedCache - 返回的所有计算字段缓存(默认为空对象)
|
|
71
|
+
* @returns `computedCache` 计算字段缓存
|
|
97
72
|
*/
|
|
98
|
-
export function
|
|
73
|
+
export function initComputedAndGetCache(
|
|
99
74
|
options: FinalOptionsOfComponent,
|
|
100
75
|
computedConfig: Record<string, Func>,
|
|
101
|
-
initAllData:
|
|
76
|
+
initAllData: Record<string, unknown>,
|
|
102
77
|
uninitedkeys: string[] = Object.keys(computedConfig),
|
|
103
78
|
computedCache: ComputedCache = {},
|
|
104
79
|
): ComputedCache {
|
|
105
|
-
// 收集依赖 uninitedkeys不受内部2处重新赋值的影响
|
|
106
|
-
|
|
107
80
|
for (const key of uninitedkeys) {
|
|
108
|
-
|
|
109
|
-
const
|
|
81
|
+
const computedFunc = computedConfig[key];
|
|
82
|
+
const dependences: ComputedDependence[] = [];
|
|
83
|
+
// 通过代理data获取计算字段的初始值和依赖
|
|
84
|
+
let initValue = computedFunc.call({ data: deepProxy(initAllData, dependences) });
|
|
110
85
|
|
|
111
|
-
//
|
|
86
|
+
// 去除当前已初始的计算属性key
|
|
112
87
|
uninitedkeys = uninitedkeys.filter(ele => ele !== key);
|
|
113
88
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
} else {
|
|
118
|
-
const dataOpt = options.data;
|
|
89
|
+
// 验证依赖是否有效
|
|
90
|
+
if (isValidDependences(dependences, uninitedkeys)) {
|
|
91
|
+
initValue = getProxyOriginalValue(initValue);
|
|
119
92
|
|
|
120
|
-
|
|
93
|
+
// 把计算属性初始值加入到options.data中
|
|
94
|
+
options.data[key] = initValue;
|
|
121
95
|
|
|
122
|
-
//
|
|
123
|
-
initAllData[key] =
|
|
96
|
+
// 把计算属性初始值加入到initAllData中,后续其他计算属性依赖时会可能会用到
|
|
97
|
+
initAllData[key] = initValue;
|
|
124
98
|
|
|
125
|
-
computedCache[key] =
|
|
99
|
+
computedCache[key] = {
|
|
100
|
+
dependences: uniqueDependences(dependences),
|
|
101
|
+
method: computedFunc,
|
|
102
|
+
value: initValue,
|
|
103
|
+
};
|
|
104
|
+
} else {
|
|
105
|
+
// 把当前依赖不正确的key放到后面去
|
|
106
|
+
uninitedkeys.push(key);
|
|
126
107
|
}
|
|
127
108
|
}
|
|
128
|
-
// 看uninitedkey
|
|
109
|
+
// 看uninitedkey是否未空,空表示所有依赖收集完毕直接返回
|
|
129
110
|
if (uninitedkeys.length === 0) {
|
|
130
111
|
return computedCache;
|
|
131
112
|
}
|
|
132
113
|
|
|
133
114
|
// uninitedkey不为空,递归
|
|
134
|
-
return
|
|
115
|
+
return initComputedAndGetCache(options, computedConfig, initAllData, uninitedkeys, computedCache);
|
|
135
116
|
}
|
|
@@ -27,7 +27,7 @@ import type { DefineComponentOption } from "..";
|
|
|
27
27
|
import { BStore } from "../../../behaviors/BStore";
|
|
28
28
|
import { computedWatchHandle } from "./computedWatchHandle";
|
|
29
29
|
|
|
30
|
-
import type { ComputedCache } from "./computedWatchHandle/
|
|
30
|
+
import type { ComputedCache } from "./computedWatchHandle/initComputedAndGetCache";
|
|
31
31
|
import { initStore } from "./initStore";
|
|
32
32
|
|
|
33
33
|
type InstanceInnerFields = {
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import type { Func } from "hry-types/src/Misc/Func";
|
|
2
|
-
import type { FinalOptionsOfComponent } from "..";
|
|
3
|
-
import type { ComputedDependence } from "./computedUpdater";
|
|
4
|
-
type ItemCache = {
|
|
5
|
-
dependences: ComputedDependence[];
|
|
6
|
-
method: Func;
|
|
7
|
-
value: unknown;
|
|
8
|
-
};
|
|
9
|
-
export type ComputedCache = Record<string, ItemCache>;
|
|
10
|
-
export declare function getItemCache(initAllData: object, computedKeys: string[], computedFunc: Func): false | ItemCache;
|
|
11
|
-
export declare function initComputed(options: FinalOptionsOfComponent, computedConfig: Record<string, Func>, initAllData: object, uninitedkeys?: string[], computedCache?: ComputedCache): ComputedCache;
|
|
12
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"initComputed.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/initComputed.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAa1C,SAAS,kBAAkB,CAAC,WAAiC,EAAE,YAAsB;IACnF,KAAK,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,EAAE,IAAI,WAAW,EAAE,CAAC;QAG/C,IAAI,CAAC,GAAG,KAAK,SAAS,CAAC,IAAI,YAAY,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC1D,OAAO,KAAK,CAAC;QACf,CAAC;IACH,CAAC;IAED,OAAO,IAAI,CAAC;AACd,CAAC;AAED,MAAM,UAAU,YAAY,CAC1B,WAAmB,EACnB,YAAsB,EACtB,YAAkB;IAGlB,MAAM,WAAW,GAAyB,EAAE,CAAC;IAC7C,MAAM,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;IAEnF,IAAI,kBAAkB,CAAC,WAAW,EAAE,YAAY,CAAC,EAAE,CAAC;QAClD,OAAO;YAEL,WAAW,EAAE,i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