annil 1.6.4 → 1.7.1

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.
Files changed (20) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/README.md +1 -1
  3. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js +1 -2
  4. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.js.map +1 -1
  5. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js +3 -4
  6. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.js.map +1 -1
  7. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js +1 -2
  8. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.js.map +1 -1
  9. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.d.ts +1 -1
  10. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.js +31 -11
  11. package/dist/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.js.map +1 -1
  12. package/dist/api/SubComponent/SubInherit/SubInheritConstraint.d.ts +2 -1
  13. package/package.json +1 -1
  14. package/src/api/DefineComponent/assignOptions/computedWatchHandle/computedUpdater.ts +1 -2
  15. package/src/api/DefineComponent/assignOptions/computedWatchHandle/data-tracer.ts +7 -6
  16. package/src/api/DefineComponent/assignOptions/computedWatchHandle/initComputedAndGetCache.ts +1 -2
  17. package/src/api/DefineComponent/assignOptions/computedWatchHandle/uniqueDependences.ts +87 -23
  18. package/src/api/SubComponent/SubInherit/SubInheritConstraint.ts +4 -2
  19. package/src/api/SubComponent/SubInherit/test/error.test.ts +8 -0
  20. package/src/api/SubComponent/SubInherit/test/normal.test.ts +11 -0
package/CHANGELOG.md CHANGED
@@ -4,6 +4,27 @@
4
4
 
5
5
  * 解决DetailedType不接收接口类型的错误 ([ae8acbf](https://github.com/missannil/annil/commit/ae8acbfc2e62f99db565c448ad9253aa549e78bb))
6
6
 
7
+ ## [1.7.1](https://github.com/missannil/annil/compare/v1.7.0...v1.7.1) (2024-04-12)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * 1.7.0action发布时npm密钥过期问题 ([0ad71b9](https://github.com/missannil/annil/commit/0ad71b96aaa02668a4052cd57ea2ff8c46598107))
13
+
14
+ ## [1.7.0](https://github.com/missannil/annil/compare/v1.6.5...v1.7.0) (2024-04-11)
15
+
16
+
17
+ ### Features
18
+
19
+ * subComponent的inherit字段加入数组类型,表示联合类型 ([a7930ff](https://github.com/missannil/annil/commit/a7930ff1abe18579bff6f1746911c2f30274325b))
20
+
21
+ ## [1.6.5](https://github.com/missannil/annil/compare/v1.6.4...v1.6.5) (2024-02-13)
22
+
23
+
24
+ ### Bug Fixes
25
+
26
+ * computed 依赖优化 ([cff7833](https://github.com/missannil/annil/commit/cff7833196fc2df52ae769211a3c5893f67aa2ab))
27
+
7
28
  ## [1.6.4](https://github.com/missannil/annil/compare/v1.6.3...v1.6.4) (2024-02-12)
8
29
 
9
30
 
package/README.md CHANGED
@@ -23,7 +23,7 @@
23
23
 
24
24
  ### 简介
25
25
 
26
- annil(安奈儿)是微信小程序原生开发插件,她会带给您惊喜。
26
+ annil(安奈儿)是微信小程序原生开发插件。
27
27
 
28
28
  ### 特点
29
29
 
@@ -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 = uniqueDependences(newDependences);
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;AACpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAGxD,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,iBAAiB,CAAC,cAAc,CAAC,CAAC;YAGjF,OAAO,eAAe,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;QAC/C,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,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 ((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 && dependences[dependences.length - 1].paths.toString() === basePath.toString()) {
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":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,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"}
@@ -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: uniqueDependences(dependences),
21
+ dependences,
23
22
  method: computedFunc,
24
23
  value: initValue,
25
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;AACjE,OAAO,EAAE,iBAA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,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"}
@@ -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
- export function uniqueDependences(dependences) {
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.join(".") + ".";
3
+ const firstPath = dependences[f].paths.toString();
6
4
  for (let i = f + 1; i < dependences.length; i++) {
7
- const curPath = dependences[i].paths.join(".") + ".";
8
- if (firstPath.startsWith(curPath)) {
5
+ const curPath = dependences[i].paths.toString();
6
+ if (firstPath === curPath) {
9
7
  dependences.splice(f, 1);
10
- return uniqueDependences(dependences);
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,MAAM,UASG,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,CAAC,EAAE,CAAC;gBAElC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAEzB,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC;YACxC,CAAC;YACD,IAAI,OAAO,CAAC,UAAU,CAAC,SAAS,CAAC,EAAE,CAAC;gBAElC,WAAW,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;gBAEzB,OAAO,iBAAiB,CAAC,WAAW,CAAC,CAAC;YACxC,CAAC;QACH,CAAC;IACH,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
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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I,CAAC,CAAC;IAClE,CAAC;IAED,OAAO,WAAW,CAAC;AACrB,CAAC"}
@@ -2,7 +2,8 @@ import type { SelectKeys } from "hry-types/src/Object/_api";
2
2
  import type { RemoveInnerData } from "../../../types/RemoveInnerData";
3
3
  import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc";
4
4
  type WXMLSign = "wxml";
5
+ type unionAddList<Keys extends string> = Keys | Keys[];
5
6
  export type InheritConstraint<AllRootData extends object, TComponentDoc extends ComponentDoc> = {
6
- [k in keyof TComponentDoc["properties"]]?: RemoveInnerData<SelectKeys<AllRootData, TComponentDoc["properties"][k]> & string> | WXMLSign;
7
+ [k in keyof TComponentDoc["properties"]]?: unionAddList<RemoveInnerData<SelectKeys<AllRootData, TComponentDoc["properties"][k]> & string>> | WXMLSign;
7
8
  };
8
9
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "annil",
3
- "version": "1.6.4",
3
+ "version": "1.7.1",
4
4
  "description": "微信小程序(原生开发)插件",
5
5
  "main": "dist/index.js",
6
6
  "types": "src/index.ts",
@@ -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 = uniqueDependences(newDependences);
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
- // 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'],在这里去重效率高些,外部去重时还要再次遍历,加"dependences[dependences.length - 1].paths.toString() === basePath.toString()"这判断是有可能遇到` this.data.obj[this.data.id].list`的情况,这种情况下,第一个依赖是obj,第二个依赖是id,因为依赖不是一个路径连续向下的,所以不能去重。
22
- if (basePath.length !== 0 && dependences[dependences.length - 1].paths.toString() === basePath.toString()) {
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 });
@@ -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: uniqueDependences(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
- export /**
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.join(".") + ".";
5
+ const firstPath = dependences[f].paths.toString();
16
6
  for (let i = f + 1; i < dependences.length; i++) {
17
- const curPath = dependences[i].paths.join(".") + ".";
18
- if (firstPath.startsWith(curPath)) {
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 uniqueDependences(dependences);
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
+ // }
@@ -4,12 +4,14 @@ import type { ComponentDoc } from "../../DefineComponent/ReturnType/ComponentDoc
4
4
 
5
5
  type WXMLSign = "wxml";
6
6
 
7
+ type unionAddList<Keys extends string> = Keys | Keys[];
8
+
7
9
  /**
8
- * 子组件inherit字段约束,key为构建组件所需的properties字段,类型为根组件数据的key或`WXMLSign`。要求根数据类型为子数据类型的子类型。当key的值来自wxml(循环产生的子数据等情况)时用`WXMLSign`表示。
10
+ * 子组件inherit字段约束,key为构建组件所需的properties字段,类型为根组件数据的key或key[]或`WXMLSign`。要求根数据类型为子数据类型的子类型。当key的值来自wxml(循环产生的子数据等情况)时用`WXMLSign`表示。
9
11
  * @returns object
10
12
  */
11
13
  export type InheritConstraint<AllRootData extends object, TComponentDoc extends ComponentDoc> = {
12
14
  [k in keyof TComponentDoc["properties"]]?:
13
- | RemoveInnerData<SelectKeys<AllRootData, TComponentDoc["properties"][k]> & string>
15
+ | unionAddList<RemoveInnerData<SelectKeys<AllRootData, TComponentDoc["properties"][k]> & string>>
14
16
  | WXMLSign;
15
17
  };
@@ -74,3 +74,11 @@ SubComponent<Mock_RootDoc, Mock_CompDoc>()({
74
74
  aaa_xxx: "",
75
75
  },
76
76
  });
77
+ // 4 数组时类型错误
78
+
79
+ SubComponent<Mock_RootDoc, Mock_CompDoc>()({
80
+ inherit: {
81
+ // @ts-expect-error
82
+ aaa_num: ["optional_lit1eral_num", "require1d_num"],
83
+ },
84
+ });
@@ -54,3 +54,14 @@ SubComponent<Mock_RootDoc, Mock_CompDoc>()({
54
54
  aaa_obj1: "" as "required_obj" | "optional_obj" | "wxml",
55
55
  },
56
56
  });
57
+
58
+ // 3 value为数组时,表示多个字段的联合类型
59
+
60
+ SubComponent<Mock_RootDoc, Mock_CompDoc>()({
61
+ inherit: {
62
+ aaa_num: ["optional_literal_num", "required_num"],
63
+ aaa_str: ["literal_str", "str"],
64
+ aaa_obj: "" as "required_obj" | "optional_obj" | ["required_obj" | "optional_obj"] | "wxml",
65
+ aaa_obj1: "" as "required_obj" | "optional_obj" | ["required_obj" | "optional_obj"] | "wxml",
66
+ },
67
+ });