annil 1.6.4 → 1.6.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/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js +1 -2
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js +3 -4
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js +1 -2
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js.map +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.d.ts +1 -1
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.js +31 -11
- package/dist/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.js.map +1 -1
- package/package.json +1 -1
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.ts +1 -2
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.ts +7 -6
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.ts +1 -2
- package/src/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.ts +87 -23
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.5](https://github.com/missannil/annil/compare/v1.6.4...v1.6.5) (2024-02-13)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Bug Fixes
|
|
11
|
+
|
|
12
|
+
* computed 依赖优化 ([cff7833](https://github.com/missannil/annil/commit/cff7833196fc2df52ae769211a3c5893f67aa2ab))
|
|
13
|
+
|
|
7
14
|
## [1.6.4](https://github.com/missannil/annil/compare/v1.6.3...v1.6.4) (2024-02-12)
|
|
8
15
|
|
|
9
16
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
2
2
|
import { getPathsValue } from "./getPathsValue";
|
|
3
3
|
import { isEqual } from "./isEqual";
|
|
4
|
-
import { uniqueDependences } from "./uniqueDependences";
|
|
5
4
|
export function computedUpdater(isUpdated = false) {
|
|
6
5
|
for (const key in this.data.__computedCache__) {
|
|
7
6
|
const itemCache = this.data.__computedCache__[key];
|
|
@@ -21,7 +20,7 @@ export function computedUpdater(isUpdated = false) {
|
|
|
21
20
|
[key]: newValue,
|
|
22
21
|
});
|
|
23
22
|
isUpdated = true;
|
|
24
|
-
this.data.__computedCache__[key].dependences =
|
|
23
|
+
this.data.__computedCache__[key].dependences = newDependences;
|
|
25
24
|
return computedUpdater.call(this, isUpdated);
|
|
26
25
|
}
|
|
27
26
|
}
|
|
@@ -1 +1 @@
|
|
|
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,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;
|
|
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,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAEhD,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAGpC,MAAM,UAAU,eAAe,CAAiB,SAAS,GAAG,KAAK;IAC/D,KAAK,MAAM,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,iBAAiB,EAAE,CAAC;QAC9C,MAAM,SAAS,GAAG,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC;QACnD,IAAI,OAAO,GAAG,KAAK,CAAC;QACpB,KAAK,MAAM,GAAG,IAAI,SAAS,CAAC,WAAW,EAAE,CAAC;YAExC,MAAM,MAAM,GAAG,aAAa,CAAC,IAAI,CAAC,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAGhE,IAAI,CAAC,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC;gBAC9B,OAAO,GAAG,IAAI,CAAC;gBAEf,MAAM;YACR,CAAC;QACH,CAAC;QACD,IAAI,OAAO,EAAE,CAAC;YACZ,MAAM,cAAc,GAAyB,EAAE,CAAC;YAChD,IAAI,QAAQ,GAAG,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,IAAI,CAAC,IAAI,EAAE,cAAc,CAAC,EAAE,CAAC,CAAC;YAGrF,QAAQ,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC;YAE3C,IAAI,CAAC,OAAO,CAAC;gBACX,CAAC,GAAG,CAAC,EAAE,QAAQ;aAChB,CAAC,CAAC;YAEH,SAAS,GAAG,IAAI,CAAC;YAGjB,IAAI,CAAC,IAAI,CAAC,iBAAiB,CAAC,GAAG,CAAC,CAAC,WAAW,GAAG,cAAc,CAAC;YAG9D,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { deepClone } from "../../../../utils/deepClone";
|
|
2
|
+
import { uniqueDependences } from "./uniqueDependences";
|
|
2
3
|
export function deepProxy(data, dependences, basePath = []) {
|
|
3
4
|
const handler = {
|
|
4
5
|
get(target, prop) {
|
|
@@ -6,12 +7,10 @@ export function deepProxy(data, dependences, basePath = []) {
|
|
|
6
7
|
return target;
|
|
7
8
|
}
|
|
8
9
|
const val = target[prop];
|
|
9
|
-
if (
|
|
10
|
+
if (typeof val === "function" && (!Object.prototype.hasOwnProperty.call(target, prop))) {
|
|
10
11
|
return val.bind(target);
|
|
11
12
|
}
|
|
12
|
-
|
|
13
|
-
dependences.pop();
|
|
14
|
-
}
|
|
13
|
+
dependences = uniqueDependences(dependences, basePath, prop);
|
|
15
14
|
const curPath = basePath.concat(prop);
|
|
16
15
|
dependences.push({ paths: curPath, val });
|
|
17
16
|
if (typeof val !== "object" || val === null)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-tracer.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"data-tracer.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,6BAA6B,CAAC;AAExD,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAExD,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,OAAO,GAAG,KAAK,UAAU,IAAI,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC,EAAE,CAAC;gBAEvF,OAAQ,GAAgB,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;YACxC,CAAC;YAED,WAAW,GAAG,iBAAiB,CAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;YAE7D,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"}
|
package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
2
|
-
import { uniqueDependences } from "./uniqueDependences";
|
|
3
2
|
function isValidDependences(dependences, computedKeys) {
|
|
4
3
|
for (const { paths: path, val } of dependences) {
|
|
5
4
|
if ((val === undefined) && computedKeys.includes(path[0])) {
|
|
@@ -19,7 +18,7 @@ export function initComputedAndGetCache(options, computedConfig, initAllData, un
|
|
|
19
18
|
options.data[key] = initValue;
|
|
20
19
|
initAllData[key] = initValue;
|
|
21
20
|
computedCache[key] = {
|
|
22
|
-
dependences
|
|
21
|
+
dependences,
|
|
23
22
|
method: computedFunc,
|
|
24
23
|
value: initValue,
|
|
25
24
|
};
|
package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js.map
CHANGED
|
@@ -1 +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;
|
|
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,MAAM,UAAU,uBAAuB,CACrC,OAAgC,EAChC,cAAoC,EACpC,WAAoC,EACpC,eAAyB,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC,EACpD,gBAA+B,EAAE;IAEjC,KAAK,MAAM,GAAG,IAAI,YAAY,EAAE,CAAC;QAC/B,MAAM,YAAY,GAAG,cAAc,CAAC,GAAG,CAAC,CAAC;QACzC,MAAM,WAAW,GAAyB,EAAE,CAAC;QAE7C,IAAI,SAAS,GAAG,YAAY,CAAC,IAAI,CAAC,EAAE,IAAI,EAAE,SAAS,CAAC,WAAW,EAAE,WAAW,CAAC,EAAE,CAAC,CAAC;QAGjF,YAAY,GAAG,YAAY,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC;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;gBACX,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"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { ComputedDependence } from "./computedUpdater";
|
|
2
|
-
export declare function uniqueDependences(dependences: ComputedDependence[]): ComputedDependence[];
|
|
2
|
+
export declare function uniqueDependences(dependences: ComputedDependence[], basePath: string[], prop: string): ComputedDependence[];
|
|
@@ -1,20 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
if (dependences.length === 1)
|
|
3
|
-
return dependences;
|
|
1
|
+
function sameDependences(dependences) {
|
|
4
2
|
for (let f = 0; f < dependences.length; f++) {
|
|
5
|
-
const firstPath = dependences[f].paths.
|
|
3
|
+
const firstPath = dependences[f].paths.toString();
|
|
6
4
|
for (let i = f + 1; i < dependences.length; i++) {
|
|
7
|
-
const curPath = dependences[i].paths.
|
|
8
|
-
if (firstPath
|
|
5
|
+
const curPath = dependences[i].paths.toString();
|
|
6
|
+
if (firstPath === curPath) {
|
|
9
7
|
dependences.splice(f, 1);
|
|
10
|
-
return
|
|
11
|
-
}
|
|
12
|
-
if (curPath.startsWith(firstPath)) {
|
|
13
|
-
dependences.splice(i, 1);
|
|
14
|
-
return uniqueDependences(dependences);
|
|
8
|
+
return sameDependences(dependences);
|
|
15
9
|
}
|
|
16
10
|
}
|
|
17
11
|
}
|
|
18
12
|
return dependences;
|
|
19
13
|
}
|
|
14
|
+
function serialDependences(dependences, basePath) {
|
|
15
|
+
const lastDependence = dependences[dependences.length - 1];
|
|
16
|
+
if (lastDependence.paths.toString() === basePath.toString()) {
|
|
17
|
+
dependences.pop();
|
|
18
|
+
}
|
|
19
|
+
return dependences;
|
|
20
|
+
}
|
|
21
|
+
function separatedDependences(dependences, basePath, prop) {
|
|
22
|
+
const lastDependence = dependences[dependences.length - 1].val;
|
|
23
|
+
if (typeof lastDependence === "string"
|
|
24
|
+
&& dependences[dependences.length - 2].paths.concat(lastDependence).toString()
|
|
25
|
+
=== basePath.concat(prop).toString()) {
|
|
26
|
+
dependences.splice(dependences.length - 2, 1);
|
|
27
|
+
}
|
|
28
|
+
return dependences;
|
|
29
|
+
}
|
|
30
|
+
export function uniqueDependences(dependences, basePath, prop) {
|
|
31
|
+
if (dependences.length === 0)
|
|
32
|
+
return dependences;
|
|
33
|
+
dependences = sameDependences(dependences);
|
|
34
|
+
dependences = serialDependences(dependences, basePath);
|
|
35
|
+
if (dependences.length >= 2) {
|
|
36
|
+
dependences = separatedDependences(dependences, basePath, prop);
|
|
37
|
+
}
|
|
38
|
+
return dependences;
|
|
39
|
+
}
|
|
20
40
|
//# sourceMappingURL=uniqueDependences.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"uniqueDependences.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.ts"],"names":[],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"uniqueDependences.js","sourceRoot":"","sources":["../../../../../src/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.ts"],"names":[],"mappings":"AAEA,SAAS,eAAe,CAAC,WAAiC;IACxD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QAC5C,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;QAClD,KAAK,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,WAAW,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YAChD,MAAM,OAAO,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;YAChD,IAAI,SAAS,KAAK,OAAO,EAAE,CAAC;gBAC1B,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAEzB,OAAO,eAAe,CAAC,WAAW,CAAC,CAAC;YACtC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,iBAAiB,CAAC,WAAiC,EAAE,QAAkB;IAC9E,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IAC3D,IAAI,cAAc,CAAC,KAAK,CAAC,QAAQ,EAAE,KAAK,QAAQ,CAAC,QAAQ,EAAE,EAAE,CAAC;QAC5D,WAAW,CAAC,GAAG,EAAE,CAAC;IACpB,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAED,SAAS,oBAAoB,CAAC,WAAiC,EAAE,QAAkB,EAAE,IAAY;IAC/F,MAAM,cAAc,GAAG,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,GAAG,CAAC;IAC/D,IACE,OAAO,cAAc,KAAK,QAAQ;WAC/B,WAAW,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,EAAE;gBACxE,QAAQ,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,QAAQ,EAAE,EACtC,CAAC;QACD,WAAW,CAAC,MAAM,CAAC,WAAW,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,CAAC,CAAC;IAChD,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC;AAKD,MAAM,UAAU,iBAAiB,CAC/B,WAAiC,EACjC,QAAkB,EAClB,IAAY;IAEZ,IAAI,WAAW,CAAC,MAAM,KAAK,CAAC;QAAE,OAAO,WAAW,CAAC;IAEjD,WAAW,GAAG,eAAe,CAAC,WAAW,CAAC,CAAC;IAG3C,WAAW,GAAG,iBAAiB,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;IAGvD,IAAI,WAAW,CAAC,MAAM,IAAI,CAAC,EAAE,CAAC;QAC5B,WAAW,GAAG,oBAAoB,CAAC,WAAW,EAAE,QAAQ,EAAE,IAAI,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
|
package/package.json
CHANGED
|
@@ -3,7 +3,6 @@ import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
|
3
3
|
import { getPathsValue } from "./getPathsValue";
|
|
4
4
|
|
|
5
5
|
import { isEqual } from "./isEqual";
|
|
6
|
-
import { uniqueDependences } from "./uniqueDependences";
|
|
7
6
|
export type ComputedDependence = { paths: string[]; val: unknown };
|
|
8
7
|
|
|
9
8
|
export function computedUpdater(this: Instance, isUpdated = false): boolean {
|
|
@@ -35,7 +34,7 @@ export function computedUpdater(this: Instance, isUpdated = false): boolean {
|
|
|
35
34
|
isUpdated = true;
|
|
36
35
|
|
|
37
36
|
// 更新依赖,去重
|
|
38
|
-
this.data.__computedCache__[key].dependences =
|
|
37
|
+
this.data.__computedCache__[key].dependences = newDependences;
|
|
39
38
|
|
|
40
39
|
// 有一个计算属性更新就重新更新所有计算互相,避免后置依赖导致前置依赖错误
|
|
41
40
|
return computedUpdater.call(this, isUpdated);
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
/* eslint-disable complexity */
|
|
1
2
|
import { deepClone } from "../../../../utils/deepClone";
|
|
2
3
|
import type { ComputedDependence } from "./computedUpdater";
|
|
4
|
+
import { uniqueDependences } from "./uniqueDependences";
|
|
3
5
|
|
|
4
6
|
export function deepProxy(
|
|
5
7
|
data: object,
|
|
@@ -13,15 +15,14 @@ export function deepProxy(
|
|
|
13
15
|
}
|
|
14
16
|
const val = target[prop];
|
|
15
17
|
|
|
16
|
-
//
|
|
17
|
-
if (
|
|
18
|
+
// 如 this.data.arr.slice(),`slice`不属于自身属性不代理,不加入依赖。但不包含小程序data子字段为函数的情况)
|
|
19
|
+
if (typeof val === "function" && (!Object.prototype.hasOwnProperty.call(target, prop))) {
|
|
18
20
|
// val有不是函数的情况么?
|
|
19
21
|
return (val as Function).bind(target);
|
|
20
22
|
}
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
}
|
|
23
|
+
|
|
24
|
+
dependences = uniqueDependences(dependences, basePath, prop);
|
|
25
|
+
|
|
25
26
|
const curPath = basePath.concat(prop);
|
|
26
27
|
|
|
27
28
|
dependences.push({ paths: curPath, val });
|
package/src/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.ts
CHANGED
|
@@ -3,7 +3,6 @@ import type { FinalOptionsOfComponent } from "..";
|
|
|
3
3
|
|
|
4
4
|
import type { ComputedDependence } from "./computedUpdater";
|
|
5
5
|
import { deepProxy, getProxyOriginalValue } from "./data-tracer";
|
|
6
|
-
import { uniqueDependences } from "./uniqueDependences";
|
|
7
6
|
|
|
8
7
|
type ItemCache = {
|
|
9
8
|
dependences: ComputedDependence[];
|
|
@@ -65,7 +64,7 @@ export function initComputedAndGetCache(
|
|
|
65
64
|
initAllData[key] = initValue;
|
|
66
65
|
|
|
67
66
|
computedCache[key] = {
|
|
68
|
-
dependences
|
|
67
|
+
dependences,
|
|
69
68
|
method: computedFunc,
|
|
70
69
|
value: initValue,
|
|
71
70
|
};
|
|
@@ -1,34 +1,98 @@
|
|
|
1
1
|
import type { ComputedDependence } from "./computedUpdater";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
* 依赖去重
|
|
5
|
-
* @example
|
|
6
|
-
* ```ts
|
|
7
|
-
* const dependences = [{path:['a','b']}, {path:['a','b','c']}, {path:['d','e']}, {path:['d']}]
|
|
8
|
-
* const result = uniqueDependences(dependences)
|
|
9
|
-
* // result = [{path:['a','b'] } ,{ path:['d'] }]
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
function uniqueDependences(dependences: ComputedDependence[]): ComputedDependence[] {
|
|
13
|
-
if (dependences.length === 1) return dependences;
|
|
2
|
+
// 相同依赖去重
|
|
3
|
+
function sameDependences(dependences: ComputedDependence[]) {
|
|
14
4
|
for (let f = 0; f < dependences.length; f++) {
|
|
15
|
-
const firstPath = dependences[f].paths.
|
|
5
|
+
const firstPath = dependences[f].paths.toString();
|
|
16
6
|
for (let i = f + 1; i < dependences.length; i++) {
|
|
17
|
-
const curPath = dependences[i].paths.
|
|
18
|
-
if (firstPath
|
|
19
|
-
// 例如 path[0] = 'a.b.c.',curPath = 'a.b.'
|
|
7
|
+
const curPath = dependences[i].paths.toString();
|
|
8
|
+
if (firstPath === curPath) {
|
|
20
9
|
dependences.splice(f, 1);
|
|
21
10
|
|
|
22
|
-
return
|
|
23
|
-
}
|
|
24
|
-
if (curPath.startsWith(firstPath)) {
|
|
25
|
-
// 例如 curPath = 'a.b.' path[0] = 'a.b.c.',
|
|
26
|
-
dependences.splice(i, 1);
|
|
27
|
-
|
|
28
|
-
return uniqueDependences(dependences);
|
|
11
|
+
return sameDependences(dependences);
|
|
29
12
|
}
|
|
30
13
|
}
|
|
31
14
|
}
|
|
32
15
|
|
|
33
16
|
return dependences;
|
|
34
17
|
}
|
|
18
|
+
// 当前依赖是上一个依赖的子依赖时,去除上一个依赖
|
|
19
|
+
function serialDependences(dependences: ComputedDependence[], basePath: string[]) {
|
|
20
|
+
const lastDependence = dependences[dependences.length - 1];
|
|
21
|
+
if (lastDependence.paths.toString() === basePath.toString()) {
|
|
22
|
+
dependences.pop();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return dependences;
|
|
26
|
+
}
|
|
27
|
+
// -2依赖 + -1val === 当前依赖 去除-2依赖
|
|
28
|
+
function separatedDependences(dependences: ComputedDependence[], basePath: string[], prop: string) {
|
|
29
|
+
const lastDependence = dependences[dependences.length - 1].val;
|
|
30
|
+
if (
|
|
31
|
+
typeof lastDependence === "string"
|
|
32
|
+
&& dependences[dependences.length - 2].paths.concat(lastDependence).toString()
|
|
33
|
+
=== basePath.concat(prop).toString()
|
|
34
|
+
) {
|
|
35
|
+
dependences.splice(dependences.length - 2, 1);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return dependences;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* 依赖去重
|
|
43
|
+
*/
|
|
44
|
+
export function uniqueDependences(
|
|
45
|
+
dependences: ComputedDependence[],
|
|
46
|
+
basePath: string[],
|
|
47
|
+
prop: string,
|
|
48
|
+
): ComputedDependence[] {
|
|
49
|
+
if (dependences.length === 0) return dependences;
|
|
50
|
+
// 相同依赖去重 例如 [{path:['a','b']}, {path:['a','b']}] => [{path:['a','b'] }]
|
|
51
|
+
dependences = sameDependences(dependences);
|
|
52
|
+
|
|
53
|
+
// 连续依赖去除 当前依赖是上一个依赖的子依赖时,去除上一个依赖
|
|
54
|
+
dependences = serialDependences(dependences, basePath);
|
|
55
|
+
|
|
56
|
+
// -2依赖 + -1依赖 === 当前依赖 去除-2依赖
|
|
57
|
+
if (dependences.length >= 2) {
|
|
58
|
+
dependences = separatedDependences(dependences, basePath, prop);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return dependences;
|
|
62
|
+
}
|
|
63
|
+
// import type { ComputedDependence } from "./computedUpdater";
|
|
64
|
+
// export /**
|
|
65
|
+
// * 依赖去重
|
|
66
|
+
// * @example
|
|
67
|
+
// * ```ts
|
|
68
|
+
// * const dependences = [{path:['a','b']}, {path:['a','b','c']}, {path:['d','e']}, {path:['d']}]
|
|
69
|
+
// * const result = uniqueDependences(dependences)
|
|
70
|
+
// * // result = [{path:['a','b'] } ,{ path:['d'] }]
|
|
71
|
+
// * ```
|
|
72
|
+
// */
|
|
73
|
+
// function uniqueDependences(dependences: ComputedDependence[]): ComputedDependence[] {
|
|
74
|
+
// if (dependences.length === 1) return dependences;
|
|
75
|
+
// console.log("外部去重前", dependences);
|
|
76
|
+
|
|
77
|
+
// for (let f = 0; f < dependences.length; f++) {
|
|
78
|
+
// const firstPath = dependences[f].paths.join(".") + ".";
|
|
79
|
+
// for (let i = f + 1; i < dependences.length; i++) {
|
|
80
|
+
// const curPath = dependences[i].paths.join(".") + ".";
|
|
81
|
+
// if (firstPath.startsWith(curPath)) {
|
|
82
|
+
// // 例如 path[0] = 'a.b.c.',curPath = 'a.b.'
|
|
83
|
+
// dependences.splice(f, 1);
|
|
84
|
+
|
|
85
|
+
// return uniqueDependences(dependences);
|
|
86
|
+
// }
|
|
87
|
+
// if (curPath.startsWith(firstPath)) {
|
|
88
|
+
// // 例如 curPath = 'a.b.' path[0] = 'a.b.c.',
|
|
89
|
+
// dependences.splice(i, 1);
|
|
90
|
+
|
|
91
|
+
// return uniqueDependences(dependences);
|
|
92
|
+
// }
|
|
93
|
+
// }
|
|
94
|
+
// }
|
|
95
|
+
// console.log("外部去重后", dependences);
|
|
96
|
+
|
|
97
|
+
// return dependences;
|
|
98
|
+
// }
|