annil 1.6.3 → 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 CHANGED
@@ -4,6 +4,20 @@
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
+
14
+ ## [1.6.4](https://github.com/missannil/annil/compare/v1.6.3...v1.6.4) (2024-02-12)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * comouted属性初始化依赖去重bug,并添加更新时去重 ([f228e55](https://github.com/missannil/annil/commit/f228e551dce65d97450b9a1aa3c7b3d3eb3e8199))
20
+
7
21
  ## [1.6.3](https://github.com/missannil/annil/compare/v1.6.2...v1.6.3) (2024-02-05)
8
22
 
9
23
 
@@ -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 ((val !== undefined) && (!Object.prototype.hasOwnProperty.call(target, prop) || typeof val === "function")) {
10
+ if (typeof val === "function" && (!Object.prototype.hasOwnProperty.call(target, prop))) {
10
11
  return val.bind(target);
11
12
  }
12
- if (basePath.length !== 0) {
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":"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
+ {"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"}
@@ -7,25 +7,6 @@ function isValidDependences(dependences, computedKeys) {
7
7
  }
8
8
  return true;
9
9
  }
10
- function uniqueDependences(dependences) {
11
- if (dependences.length === 1)
12
- return dependences;
13
- for (let f = 0; f < dependences.length; f++) {
14
- const firstPath = dependences[f].paths.join(".") + ".";
15
- for (let i = f + 1; i < dependences.length; i++) {
16
- const curPath = dependences[i].paths.join(".") + ".";
17
- if (firstPath.startsWith(curPath)) {
18
- dependences.splice(f, 1);
19
- return uniqueDependences(dependences);
20
- }
21
- if (curPath.startsWith(firstPath)) {
22
- dependences.splice(i, 1);
23
- return uniqueDependences(dependences);
24
- }
25
- }
26
- }
27
- return dependences;
28
- }
29
10
  export function initComputedAndGetCache(options, computedConfig, initAllData, uninitedkeys = Object.keys(computedConfig), computedCache = {}) {
30
11
  for (const key of uninitedkeys) {
31
12
  const computedFunc = computedConfig[key];
@@ -37,7 +18,7 @@ export function initComputedAndGetCache(options, computedConfig, initAllData, un
37
18
  options.data[key] = initValue;
38
19
  initAllData[key] = initValue;
39
20
  computedCache[key] = {
40
- dependences: uniqueDependences(dependences),
21
+ dependences,
41
22
  method: computedFunc,
42
23
  value: initValue,
43
24
  };
@@ -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;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,MAAM,SAAS,GAAG,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;QACvD,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,IAAI,CAAC,GAAG,CAAC,GAAG,GAAG,CAAC;YACrD,IAAI,SAAS,CAAC,UAAU,CAAC,OAAO,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ACjB,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
+ {"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"}
@@ -0,0 +1,2 @@
1
+ import type { ComputedDependence } from "./computedUpdater";
2
+ export declare function uniqueDependences(dependences: ComputedDependence[], basePath: string[], prop: string): ComputedDependence[];
@@ -0,0 +1,40 @@
1
+ function sameDependences(dependences) {
2
+ for (let f = 0; f < dependences.length; f++) {
3
+ const firstPath = dependences[f].paths.toString();
4
+ for (let i = f + 1; i < dependences.length; i++) {
5
+ const curPath = dependences[i].paths.toString();
6
+ if (firstPath === curPath) {
7
+ dependences.splice(f, 1);
8
+ return sameDependences(dependences);
9
+ }
10
+ }
11
+ }
12
+ return dependences;
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
+ }
40
+ //# sourceMappingURL=uniqueDependences.js.map
@@ -0,0 +1 @@
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,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name": "annil",
3
- "version": "1.6.3",
3
+ "version": "1.6.5",
4
4
  "description": "微信小程序(原生开发)插件",
5
5
  "main": "dist/index.js",
6
6
  "types": "src/index.ts",
@@ -33,7 +33,7 @@ export function computedUpdater(this: Instance, isUpdated = false): boolean {
33
33
 
34
34
  isUpdated = true;
35
35
 
36
- // 更新依赖
36
+ // 更新依赖,去重
37
37
  this.data.__computedCache__[key].dependences = newDependences;
38
38
 
39
39
  // 有一个计算属性更新就重新更新所有计算互相,避免后置依赖导致前置依赖错误
@@ -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
- // val不为undefined(依赖还为初始化的其他计算属性)且非自身属性或函数不再返回代理。 (如 this.data.arr.slice(),slice不属于自身属性,小程序允许data子字段为函数的情况,也不代理)
17
- if ((val !== undefined) && (!Object.prototype.hasOwnProperty.call(target, prop) || typeof val === "function")) {
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
- // 依赖长度不为0时径依赖去重(只留最后一个路径),比如 return this.data.obj.user.name 去重得到的是最后1个路径 ['obj','user','name'] , 不去重则3个依赖路径了 ['obj'], ['obj','user'],['obj','user','name'],在这里去重效率高些,外部去重时还要再次遍历
22
- if (basePath.length !== 0) {
23
- dependences.pop();
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 });
@@ -28,39 +28,6 @@ function isValidDependences(dependences: ComputedDependence[], computedKeys: str
28
28
  return true;
29
29
  }
30
30
 
31
- /**
32
- * 依赖去重
33
- * @example
34
- * ```ts
35
- * const dependences = [{path:['a','b']}, {path:['a','b','c']}, {path:['d','e']}, {path:['d']}]
36
- * const result = uniqueDependences(dependences)
37
- * // result = [{path:['a','b'] } ,{ path:['d'] }]
38
- * ```
39
- */
40
- function uniqueDependences(dependences: ComputedDependence[]): ComputedDependence[] {
41
- if (dependences.length === 1) return dependences;
42
- for (let f = 0; f < dependences.length; f++) {
43
- const firstPath = dependences[f].paths.join(".") + ".";
44
- for (let i = f + 1; i < dependences.length; i++) {
45
- const curPath = dependences[i].paths.join(".") + ".";
46
- if (firstPath.startsWith(curPath)) {
47
- // 例如 path[0] = 'a.b.c.',curPath = 'a.b.'
48
- dependences.splice(f, 1);
49
-
50
- return uniqueDependences(dependences);
51
- }
52
- if (curPath.startsWith(firstPath)) {
53
- // 例如 curPath = 'a.b.' path[0] = 'a.b.c.',
54
- dependences.splice(i, 1);
55
-
56
- return uniqueDependences(dependences);
57
- }
58
- }
59
- }
60
-
61
- return dependences;
62
- }
63
-
64
31
  /**
65
32
  * 把计算属性初始值加入到options.data中并返回缓存(递归函数)
66
33
  * @param options - 配置选项
@@ -97,7 +64,7 @@ export function initComputedAndGetCache(
97
64
  initAllData[key] = initValue;
98
65
 
99
66
  computedCache[key] = {
100
- dependences: uniqueDependences(dependences),
67
+ dependences,
101
68
  method: computedFunc,
102
69
  value: initValue,
103
70
  };
@@ -0,0 +1,98 @@
1
+ import type { ComputedDependence } from "./computedUpdater";
2
+ // 相同依赖去重
3
+ function sameDependences(dependences: ComputedDependence[]) {
4
+ for (let f = 0; f < dependences.length; f++) {
5
+ const firstPath = dependences[f].paths.toString();
6
+ for (let i = f + 1; i < dependences.length; i++) {
7
+ const curPath = dependences[i].paths.toString();
8
+ if (firstPath === curPath) {
9
+ dependences.splice(f, 1);
10
+
11
+ return sameDependences(dependences);
12
+ }
13
+ }
14
+ }
15
+
16
+ return dependences;
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
+ // }