@ibyar/expressions 0.5.6 → 0.5.62

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 (85) hide show
  1. package/api/abstract.js +5 -0
  2. package/api/abstract.js.map +1 -1
  3. package/api/class/class.d.ts +25 -0
  4. package/api/class/class.js +27 -0
  5. package/api/class/class.js.map +1 -1
  6. package/api/computing/return.d.ts +4 -0
  7. package/api/computing/return.js +5 -0
  8. package/api/computing/return.js.map +1 -1
  9. package/api/computing/throw.d.ts +4 -0
  10. package/api/computing/throw.js +4 -0
  11. package/api/computing/throw.js.map +1 -1
  12. package/api/definition/bind.d.ts +6 -0
  13. package/api/definition/bind.js +6 -0
  14. package/api/definition/bind.js.map +1 -1
  15. package/api/definition/function.js +1 -0
  16. package/api/definition/function.js.map +1 -1
  17. package/api/definition/values.d.ts +9 -0
  18. package/api/definition/values.js +21 -0
  19. package/api/definition/values.js.map +1 -1
  20. package/api/deserialize/deserialize.d.ts +5 -0
  21. package/api/deserialize/deserialize.js +5 -0
  22. package/api/deserialize/deserialize.js.map +1 -1
  23. package/api/expression.d.ts +146 -0
  24. package/api/module/export.d.ts +63 -0
  25. package/api/module/export.js +63 -0
  26. package/api/module/export.js.map +1 -1
  27. package/api/module/import.d.ts +53 -0
  28. package/api/module/import.js +53 -0
  29. package/api/module/import.js.map +1 -1
  30. package/api/operators/grouping.d.ts +7 -0
  31. package/api/operators/grouping.js +7 -0
  32. package/api/operators/grouping.js.map +1 -1
  33. package/api/operators/pipeline.d.ts +12 -0
  34. package/api/operators/pipeline.js +12 -0
  35. package/api/operators/pipeline.js.map +1 -1
  36. package/api/operators/unary.js +3 -0
  37. package/api/operators/unary.js.map +1 -1
  38. package/api/statement/control/block.d.ts +4 -0
  39. package/api/statement/control/block.js +4 -0
  40. package/api/statement/control/block.js.map +1 -1
  41. package/api/statement/control/empty.d.ts +7 -0
  42. package/api/statement/control/empty.js +7 -0
  43. package/api/statement/control/empty.js.map +1 -1
  44. package/api/statement/control/if.d.ts +5 -0
  45. package/api/statement/control/if.js +5 -0
  46. package/api/statement/control/if.js.map +1 -1
  47. package/api/statement/control/switch.d.ts +6 -0
  48. package/api/statement/control/switch.js +9 -0
  49. package/api/statement/control/switch.js.map +1 -1
  50. package/api/statement/control/terminate.d.ts +8 -0
  51. package/api/statement/control/terminate.js +8 -0
  52. package/api/statement/control/terminate.js.map +1 -1
  53. package/api/statement/iterations/for.d.ts +5 -0
  54. package/api/statement/iterations/for.js +13 -0
  55. package/api/statement/iterations/for.js.map +1 -1
  56. package/api/statement/iterations/while.d.ts +6 -0
  57. package/api/statement/iterations/while.js +10 -0
  58. package/api/statement/iterations/while.js.map +1 -1
  59. package/package.json +2 -2
  60. package/scope/proxy.d.ts +3 -0
  61. package/scope/proxy.js +4 -0
  62. package/scope/proxy.js.map +1 -1
  63. package/scope/scope.d.ts +68 -0
  64. package/scope/scope.js +5 -0
  65. package/scope/scope.js.map +1 -1
  66. package/scope/stack.d.ts +74 -0
  67. package/scope/stack.js +6 -0
  68. package/scope/stack.js.map +1 -1
  69. package/v8/enums.js +31 -0
  70. package/v8/enums.js.map +1 -1
  71. package/v8/inline.d.ts +36 -0
  72. package/v8/inline.js +407 -5
  73. package/v8/inline.js.map +1 -1
  74. package/v8/nodes.js +2 -1
  75. package/v8/nodes.js.map +1 -1
  76. package/v8/parser.d.ts +8 -0
  77. package/v8/parser.js +304 -1
  78. package/v8/parser.js.map +1 -1
  79. package/v8/stream.d.ts +4 -0
  80. package/v8/stream.js +79 -17
  81. package/v8/stream.js.map +1 -1
  82. package/v8/token.d.ts +229 -0
  83. package/v8/token.js +236 -1
  84. package/v8/token.js.map +1 -1
  85. package/visit/visitor.d.ts +3 -0
@@ -2,6 +2,12 @@ import type { NodeDeserializer, ExpressionNode, ExpressionEventPath, VisitNodeTy
2
2
  import type { Scope } from '../../../scope/scope.js';
3
3
  import type { Stack } from '../../../scope/stack.js';
4
4
  import { AbstractExpressionNode, ReturnValue } from '../../abstract.js';
5
+ /**
6
+ * The while statement creates a loop that executes a specified
7
+ * statement as long as the test condition evaluates to true.
8
+ * The condition is evaluated before executing the statement.
9
+ *
10
+ */
5
11
  export declare class WhileNode extends AbstractExpressionNode {
6
12
  private test;
7
13
  private body;
@@ -3,6 +3,12 @@ import { __decorate, __metadata } from "tslib";
3
3
  import { AbstractExpressionNode, ReturnValue } from '../../abstract.js';
4
4
  import { Deserializer } from '../../deserialize/deserialize.js';
5
5
  import { TerminateReturnType } from '../control/terminate.js';
6
+ /**
7
+ * The while statement creates a loop that executes a specified
8
+ * statement as long as the test condition evaluates to true.
9
+ * The condition is evaluated before executing the statement.
10
+ *
11
+ */
6
12
  let WhileNode = WhileNode_1 = class WhileNode extends AbstractExpressionNode {
7
13
  constructor(test, body) {
8
14
  super();
@@ -34,6 +40,8 @@ let WhileNode = WhileNode_1 = class WhileNode extends AbstractExpressionNode {
34
40
  const whileBlock = stack.pushBlockScope();
35
41
  while (condition) {
36
42
  const result = this.body.get(stack);
43
+ // useless case, as it at the end of for statement
44
+ // an array/block statement, should return last signal
37
45
  if (result instanceof TerminateReturnType) {
38
46
  if (result.type === 'continue') {
39
47
  continue;
@@ -101,6 +109,8 @@ let DoWhileNode = DoWhileNode_1 = class DoWhileNode extends AbstractExpressionNo
101
109
  const whileBlock = stack.pushBlockScope();
102
110
  do {
103
111
  const result = this.body.get(stack);
112
+ // useless case, as it at the end of for statement
113
+ // an array/block statement, should return last signal
104
114
  if (result instanceof TerminateReturnType) {
105
115
  if (result.type === 'continue') {
106
116
  continue;
@@ -1 +1 @@
1
- {"version":3,"file":"while.js","sourceRoot":"","sources":["../../../../../src/expressions/api/statement/iterations/while.ts"],"names":[],"mappings":";;AAMA,OAAO,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,yBAAyB,CAAC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KAAK,CAAC,CAAC;IACf,CAAC;IACD,UAAU,CAAC,QAAe;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9E,CAAC;IACD,cAAc,CAAC,QAAe;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtF,CAAC;IACD,QAAQ;QACP,OAAO,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC;IACvE,CAAC;IACD,MAAM;QACL,OAAO;YACN,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACxB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;SACxB,CAAC;IACH,CAAC;CACD,CAAA;AA/DY,WAAW;IADvB,YAAY,CAAC,kBAAkB,CAAC;;GACpB,WAAW,CA+DvB;SA/DY,WAAW","sourcesContent":["import type {\n\tNodeDeserializer, ExpressionNode,\n\tExpressionEventPath, VisitNodeType\n} from '../../expression.js';\nimport type { Scope } from '../../../scope/scope.js';\nimport type { Stack } from '../../../scope/stack.js';\nimport { AbstractExpressionNode, ReturnValue } from '../../abstract.js';\nimport { Deserializer } from '../../deserialize/deserialize.js';\nimport { TerminateReturnType } from '../control/terminate.js';\n\n/**\n * The while statement creates a loop that executes a specified\n * statement as long as the test condition evaluates to true.\n * The condition is evaluated before executing the statement.\n * \n */\n@Deserializer('WhileStatement')\nexport class WhileNode extends AbstractExpressionNode {\n\tstatic fromJSON(node: WhileNode, deserializer: NodeDeserializer): WhileNode {\n\t\treturn new WhileNode(\n\t\t\tdeserializer(node.test),\n\t\t\tdeserializer(node.body)\n\t\t);\n\t}\n\tstatic visit(node: WhileNode, visitNode: VisitNodeType): void {\n\t\tvisitNode(node.body);\n\t\tvisitNode(node.test);\n\t}\n\tconstructor(private test: ExpressionNode, private body: ExpressionNode) {\n\t\tsuper();\n\t}\n\tgetTest() {\n\t\treturn this.test;\n\t}\n\tgetBody() {\n\t\treturn this.body;\n\t}\n\tshareVariables(scopeList: Scope<any>[]): void {\n\t\tthis.test.shareVariables(scopeList);\n\t\tthis.body.shareVariables(scopeList);\n\t}\n\tset(stack: Stack, value: any) {\n\t\tthrow new Error(`WhileNode#set() has no implementation.`);\n\t}\n\tget(stack: Stack) {\n\t\tconst condition = this.test.get(stack);\n\t\tconst whileBlock = stack.pushBlockScope();\n\t\twhile (condition) {\n\t\t\tconst result = this.body.get(stack);\n\t\t\t// useless case, as it at the end of for statement\n\t\t\t// an array/block statement, should return last signal\n\t\t\tif (result instanceof TerminateReturnType) {\n\t\t\t\tif (result.type === 'continue') {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result instanceof ReturnValue) {\n\t\t\t\tstack.clearTo(whileBlock);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t\tstack.clearTo(whileBlock);\n\t\treturn void 0;\n\t}\n\tdependency(computed?: true): ExpressionNode[] {\n\t\treturn this.test.dependency(computed).concat(this.body.dependency(computed));\n\t}\n\tdependencyPath(computed?: true): ExpressionEventPath[] {\n\t\treturn this.test.dependencyPath(computed).concat(this.body.dependencyPath(computed));\n\t}\n\ttoString(): string {\n\t\treturn `while (${this.test.toString()}) ${this.body.toString()}`;\n\t}\n\ttoJson(): object {\n\t\treturn {\n\t\t\ttest: this.test.toJSON(),\n\t\t\tbody: this.body.toJSON()\n\t\t};\n\t}\n}\n\n@Deserializer('DoWhileStatement')\nexport class DoWhileNode extends AbstractExpressionNode {\n\tstatic fromJSON(node: DoWhileNode, deserializer: NodeDeserializer): DoWhileNode {\n\t\treturn new DoWhileNode(\n\t\t\tdeserializer(node.test),\n\t\t\tdeserializer(node.body)\n\t\t);\n\t}\n\tstatic visit(node: DoWhileNode, visitNode: VisitNodeType): void {\n\t\tvisitNode(node.test);\n\t\tvisitNode(node.body);\n\t}\n\tconstructor(private test: ExpressionNode, private body: ExpressionNode) {\n\t\tsuper();\n\t}\n\tgetTest() {\n\t\treturn this.test;\n\t}\n\tgetBody() {\n\t\treturn this.body;\n\t}\n\tshareVariables(scopeList: Scope<any>[]): void {\n\t\tthis.test.shareVariables(scopeList);\n\t\tthis.body.shareVariables(scopeList);\n\t}\n\tset(stack: Stack, value: any) {\n\t\tthrow new Error(`WhileNode#set() has no implementation.`);\n\t}\n\tget(stack: Stack) {\n\t\tconst whileBlock = stack.pushBlockScope();\n\t\tdo {\n\t\t\tconst result = this.body.get(stack);\n\t\t\t// useless case, as it at the end of for statement\n\t\t\t// an array/block statement, should return last signal\n\t\t\tif (result instanceof TerminateReturnType) {\n\t\t\t\tif (result.type === 'continue') {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result instanceof ReturnValue) {\n\t\t\t\tstack.clearTo(whileBlock);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t} while (this.test.get(stack));\n\t\tstack.clearTo(whileBlock);\n\t\treturn void 0;\n\t}\n\tdependency(computed?: true): ExpressionNode[] {\n\t\treturn this.body.dependency(computed).concat(this.test.dependency(computed));\n\t}\n\tdependencyPath(computed?: true): ExpressionEventPath[] {\n\t\treturn this.body.dependencyPath(computed).concat(this.test.dependencyPath(computed));\n\t}\n\ttoString(): string {\n\t\treturn `do {${this.body.toString()}} while (${this.test.toString()})`;\n\t}\n\ttoJson(): object {\n\t\treturn {\n\t\t\ttest: this.test.toJSON(),\n\t\t\tbody: this.body.toJSON()\n\t\t};\n\t}\n}\n"]}
1
+ {"version":3,"file":"while.js","sourceRoot":"","sources":["../../../../../src/exp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;qBAAM;oBACN,MAAM;iBACN;aACD;YACD,IAAI,MAAM,YAAY,WAAW,EAAE;gBAClC,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;gBAC1B,OAAO,MAAM,CAAC;aACd;SACD,QAAQ,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;QAC/B,KAAK,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC;QAC1B,OAAO,KAAK,CAAC,CAAC;IACf,CAAC;IACD,UAAU,CAAC,QAAe;QACzB,OAAO,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC9E,CAAC;IACD,cAAc,CAAC,QAAe;QAC7B,OAAO,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IACtF,CAAC;IACD,QAAQ;QACP,OAAO,OAAO,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,YAAY,IAAI,CAAC,IAAI,CAAC,QAAQ,EAAE,GAAG,CAAC;IACvE,CAAC;IACD,MAAM;QACL,OAAO;YACN,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;YACxB,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,MAAM,EAAE;SACxB,CAAC;IACH,CAAC;CACD,CAAA;AA/DY,WAAW;IADvB,YAAY,CAAC,kBAAkB,CAAC;;GACpB,WAAW,CA+DvB;SA/DY,WAAW","sourcesContent":["import type {\n\tNodeDeserializer, ExpressionNode,\n\tExpressionEventPath, VisitNodeType\n} from '../../expression.js';\nimport type { Scope } from '../../../scope/scope.js';\nimport type { Stack } from '../../../scope/stack.js';\nimport { AbstractExpressionNode, ReturnValue } from '../../abstract.js';\nimport { Deserializer } from '../../deserialize/deserialize.js';\nimport { TerminateReturnType } from '../control/terminate.js';\n\n/**\n * The while statement creates a loop that executes a specified\n * statement as long as the test condition evaluates to true.\n * The condition is evaluated before executing the statement.\n * \n */\n@Deserializer('WhileStatement')\nexport class WhileNode extends AbstractExpressionNode {\n\tstatic fromJSON(node: WhileNode, deserializer: NodeDeserializer): WhileNode {\n\t\treturn new WhileNode(\n\t\t\tdeserializer(node.test),\n\t\t\tdeserializer(node.body)\n\t\t);\n\t}\n\tstatic visit(node: WhileNode, visitNode: VisitNodeType): void {\n\t\tvisitNode(node.body);\n\t\tvisitNode(node.test);\n\t}\n\tconstructor(private test: ExpressionNode, private body: ExpressionNode) {\n\t\tsuper();\n\t}\n\tgetTest() {\n\t\treturn this.test;\n\t}\n\tgetBody() {\n\t\treturn this.body;\n\t}\n\tshareVariables(scopeList: Scope<any>[]): void {\n\t\tthis.test.shareVariables(scopeList);\n\t\tthis.body.shareVariables(scopeList);\n\t}\n\tset(stack: Stack, value: any) {\n\t\tthrow new Error(`WhileNode#set() has no implementation.`);\n\t}\n\tget(stack: Stack) {\n\t\tconst condition = this.test.get(stack);\n\t\tconst whileBlock = stack.pushBlockScope();\n\t\twhile (condition) {\n\t\t\tconst result = this.body.get(stack);\n\t\t\t// useless case, as it at the end of for statement\n\t\t\t// an array/block statement, should return last signal\n\t\t\tif (result instanceof TerminateReturnType) {\n\t\t\t\tif (result.type === 'continue') {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result instanceof ReturnValue) {\n\t\t\t\tstack.clearTo(whileBlock);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t}\n\t\tstack.clearTo(whileBlock);\n\t\treturn void 0;\n\t}\n\tdependency(computed?: true): ExpressionNode[] {\n\t\treturn this.test.dependency(computed).concat(this.body.dependency(computed));\n\t}\n\tdependencyPath(computed?: true): ExpressionEventPath[] {\n\t\treturn this.test.dependencyPath(computed).concat(this.body.dependencyPath(computed));\n\t}\n\ttoString(): string {\n\t\treturn `while (${this.test.toString()}) ${this.body.toString()}`;\n\t}\n\ttoJson(): object {\n\t\treturn {\n\t\t\ttest: this.test.toJSON(),\n\t\t\tbody: this.body.toJSON()\n\t\t};\n\t}\n}\n\n@Deserializer('DoWhileStatement')\nexport class DoWhileNode extends AbstractExpressionNode {\n\tstatic fromJSON(node: DoWhileNode, deserializer: NodeDeserializer): DoWhileNode {\n\t\treturn new DoWhileNode(\n\t\t\tdeserializer(node.test),\n\t\t\tdeserializer(node.body)\n\t\t);\n\t}\n\tstatic visit(node: DoWhileNode, visitNode: VisitNodeType): void {\n\t\tvisitNode(node.test);\n\t\tvisitNode(node.body);\n\t}\n\tconstructor(private test: ExpressionNode, private body: ExpressionNode) {\n\t\tsuper();\n\t}\n\tgetTest() {\n\t\treturn this.test;\n\t}\n\tgetBody() {\n\t\treturn this.body;\n\t}\n\tshareVariables(scopeList: Scope<any>[]): void {\n\t\tthis.test.shareVariables(scopeList);\n\t\tthis.body.shareVariables(scopeList);\n\t}\n\tset(stack: Stack, value: any) {\n\t\tthrow new Error(`WhileNode#set() has no implementation.`);\n\t}\n\tget(stack: Stack) {\n\t\tconst whileBlock = stack.pushBlockScope();\n\t\tdo {\n\t\t\tconst result = this.body.get(stack);\n\t\t\t// useless case, as it at the end of for statement\n\t\t\t// an array/block statement, should return last signal\n\t\t\tif (result instanceof TerminateReturnType) {\n\t\t\t\tif (result.type === 'continue') {\n\t\t\t\t\tcontinue;\n\t\t\t\t} else {\n\t\t\t\t\tbreak;\n\t\t\t\t}\n\t\t\t}\n\t\t\tif (result instanceof ReturnValue) {\n\t\t\t\tstack.clearTo(whileBlock);\n\t\t\t\treturn result;\n\t\t\t}\n\t\t} while (this.test.get(stack));\n\t\tstack.clearTo(whileBlock);\n\t\treturn void 0;\n\t}\n\tdependency(computed?: true): ExpressionNode[] {\n\t\treturn this.body.dependency(computed).concat(this.test.dependency(computed));\n\t}\n\tdependencyPath(computed?: true): ExpressionEventPath[] {\n\t\treturn this.body.dependencyPath(computed).concat(this.test.dependencyPath(computed));\n\t}\n\ttoString(): string {\n\t\treturn `do {${this.body.toString()}} while (${this.test.toString()})`;\n\t}\n\ttoJson(): object {\n\t\treturn {\n\t\t\ttest: this.test.toJSON(),\n\t\t\tbody: this.body.toJSON()\n\t\t};\n\t}\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ibyar/expressions",
3
- "version": "0.5.6",
3
+ "version": "0.5.62",
4
4
  "description": "Aurora expression, an template expression and evaluation, An 100% spec compliant ES2022 JavaScript toolchain,",
5
5
  "license": "MIT",
6
6
  "homepage": "https://github.com/ibyar/aurora/tree/dev/packages/expressions",
@@ -49,5 +49,5 @@
49
49
  "eval",
50
50
  "evaluation"
51
51
  ],
52
- "gitHead": "1e724c041319c2cfab7f9b21f6246cd658b8c3c3"
52
+ "gitHead": "17e31ddaba2c87e6b98e1415de85f62cb5ba7ba9"
53
53
  }
package/scope/proxy.d.ts CHANGED
@@ -5,6 +5,9 @@ export declare class FunctionProxyHandler<T extends Function> implements ProxyHa
5
5
  apply(targetFunc: T, targetThisArg: any, argArray: any[]): any;
6
6
  private computeThisArg;
7
7
  }
8
+ /**
9
+ * crete new proxy handler object as scoped context
10
+ */
8
11
  export declare class ScopeProxyHandler<T extends ScopeContext> implements ProxyHandler<ScopeContext> {
9
12
  private scope;
10
13
  private functionHandler;
package/scope/proxy.js CHANGED
@@ -7,6 +7,7 @@ export class FunctionProxyHandler {
7
7
  }
8
8
  computeThisArg(targetThisArg) {
9
9
  switch (true) {
10
+ // exclude classes that have binding hook
10
11
  case this.thisContext instanceof Map:
11
12
  case this.thisContext instanceof Set:
12
13
  case this.thisContext instanceof Date:
@@ -20,6 +21,9 @@ export class FunctionProxyHandler {
20
21
  }
21
22
  }
22
23
  }
24
+ /**
25
+ * crete new proxy handler object as scoped context
26
+ */
23
27
  export class ScopeProxyHandler {
24
28
  constructor(scope) {
25
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,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC9B,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YAC/C,IAAI,KAAK,EAAE;gBACV,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;aACtD;SACD;aAAM,IAAI,OAAO,KAAK,KAAK,UAAU,EAAE;YACvC,OAAO,IAAI,KAAK,CAAC,KAAK,EAAE,IAAI,CAAC,eAAe;mBACxC,CAAC,IAAI,CAAC,eAAe,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAC7E,CAAC;SACF;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IACD,GAAG,CAAC,KAAQ,EAAE,WAAwB,EAAE,KAAU,EAAE,QAAa;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,cAAc,CAAC,KAAQ,EAAE,WAA4B;QACpD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;CACD;AAOD,MAAM,UAAU,8BAA8B,CAAmB,OAAU,EAAE,KAAe;IAC3F,OAAO,KAAK,CAAC,SAAS,CAAI,OAAO,EAAE,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAmB,KAAe;IACtE,OAAO,IAAI,KAAK,CAAI,KAAK,CAAC,UAAU,EAAE,EAAE,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import type { Scope, ScopeContext } from './scope.js';\n\nexport class FunctionProxyHandler<T extends Function> implements ProxyHandler<T> {\n\tconstructor(private thisContext: object) { }\n\tapply(targetFunc: T, targetThisArg: any, argArray: any[]): any {\n\t\treturn targetFunc.apply(this.computeThisArg(targetThisArg), argArray);\n\t}\n\n\tprivate computeThisArg(targetThisArg: any): any {\n\t\tswitch (true) {\n\t\t\t// exclude classes that have binding hook\n\t\t\tcase this.thisContext instanceof Map:\n\t\t\tcase this.thisContext instanceof Set:\n\t\t\tcase this.thisContext instanceof Date:\n\t\t\tcase this.thisContext instanceof WeakMap:\n\t\t\tcase this.thisContext instanceof WeakSet:\n\t\t\tcase this.thisContext instanceof Promise:\n\t\t\tcase this.thisContext instanceof HTMLElement:\n\t\t\t\treturn this.thisContext;\n\t\t\tdefault:\n\t\t\t\treturn targetThisArg;\n\t\t}\n\t}\n}\n\n/**\n * crete new proxy handler object as scoped context\n */\nexport class ScopeProxyHandler<T extends ScopeContext> implements ProxyHandler<ScopeContext> {\n\tprivate functionHandler: FunctionProxyHandler<Function>;\n\tconstructor(private scope: Scope<T>) { }\n\thas(model: T, propertyKey: PropertyKey): boolean {\n\t\treturn this.scope.has(propertyKey);\n\t}\n\tget(model: T, propertyKey: PropertyKey, receiver: any): any {\n\t\tconst value = this.scope.get(propertyKey);\n\t\tif (value == null) {\n\t\t\treturn value;\n\t\t}\n\t\tif (typeof value === 'object') {\n\t\t\tconst scope = this.scope.getScope(propertyKey);\n\t\t\tif (scope) {\n\t\t\t\treturn new Proxy(value, new ScopeProxyHandler(scope));\n\t\t\t}\n\t\t} else if (typeof value === 'function') {\n\t\t\treturn new Proxy(value, this.functionHandler\n\t\t\t\t?? (this.functionHandler = new FunctionProxyHandler(this.scope.getContext()))\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\tset(model: T, propertyKey: PropertyKey, value: any, receiver: any): boolean {\n\t\treturn this.scope.set(propertyKey, value);\n\t}\n\tdeleteProperty(model: T, propertyKey: string | symbol): boolean {\n\t\treturn this.scope.delete(propertyKey);\n\t}\n}\n\nexport type RevocableProxy<T> = {\n\tproxy: T;\n\trevoke: () => void;\n};\n\nexport function createRevocableProxyForContext<T extends object>(context: T, scope: Scope<T>): RevocableProxy<T> {\n\treturn Proxy.revocable<T>(context, new ScopeProxyHandler(scope));\n}\n\nexport function createProxyForContext<T extends object>(scope: Scope<T>): T {\n\treturn new Proxy<T>(scope.getContext(), new ScopeProxyHandler(scope));\n}\n"]}
1
+ {"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/expressions/scope/proxy.ts"],"names":[],"mappings":"AAEA,MAAM,OAAO,oBAAoB;IAChC,YAAoB,WAAmB;QAAnB,gBAAW,GAAX,WAAW,CAAQ;IAAI,CAAC;IAC5C,KAAK,CAAC,UAAa,EAAE,aAAkB,EAAE,QAAe;QACvD,OAAO,UAAU,CAAC,KAAK,CAAC,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,EAAE,QAAQ,CAAC,CAAC;IACvE,CAAC;IAEO,cAAc,CAAC,aAAkB;QACxC,QAAQ,IAAI,EAAE;YACb,yCAAyC;YACzC,KAAK,IAAI,CAAC,WAAW,YAAY,GAAG,CAAC;YACrC,KAAK,IAAI,CAAC,WAAW,YAAY,GAAG,CAAC;YACrC,KAAK,IAAI,CAAC,WAAW,YAAY,IAAI,CAAC;YACtC,KAAK,IAAI,CAAC,WAAW,YAAY,OAAO,CAAC;YACzC,KAAK,IAAI,CAAC,WAAW,YAAY,OAAO,CAAC;YACzC,KAAK,IAAI,CAAC,WAAW,YAAY,OAAO,CAAC;YACzC,KAAK,IAAI,CAAC,WAAW,YAAY,WAAW;gBAC3C,OAAO,IAAI,CAAC,WAAW,CAAC;YACzB;gBACC,OAAO,aAAa,CAAC;SACtB;IACF,CAAC;CACD;AAED;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAE7B,YAAoB,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;IAAI,CAAC;IACxC,GAAG,CAAC,KAAQ,EAAE,WAAwB;QACrC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;IACD,GAAG,CAAC,KAAQ,EAAE,WAAwB,E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C;AACvE,CAAC","sourcesContent":["import type { Scope, ScopeContext } from './scope.js';\n\nexport class FunctionProxyHandler<T extends Function> implements ProxyHandler<T> {\n\tconstructor(private thisContext: object) { }\n\tapply(targetFunc: T, targetThisArg: any, argArray: any[]): any {\n\t\treturn targetFunc.apply(this.computeThisArg(targetThisArg), argArray);\n\t}\n\n\tprivate computeThisArg(targetThisArg: any): any {\n\t\tswitch (true) {\n\t\t\t// exclude classes that have binding hook\n\t\t\tcase this.thisContext instanceof Map:\n\t\t\tcase this.thisContext instanceof Set:\n\t\t\tcase this.thisContext instanceof Date:\n\t\t\tcase this.thisContext instanceof WeakMap:\n\t\t\tcase this.thisContext instanceof WeakSet:\n\t\t\tcase this.thisContext instanceof Promise:\n\t\t\tcase this.thisContext instanceof HTMLElement:\n\t\t\t\treturn this.thisContext;\n\t\t\tdefault:\n\t\t\t\treturn targetThisArg;\n\t\t}\n\t}\n}\n\n/**\n * crete new proxy handler object as scoped context\n */\nexport class ScopeProxyHandler<T extends ScopeContext> implements ProxyHandler<ScopeContext> {\n\tprivate functionHandler: FunctionProxyHandler<Function>;\n\tconstructor(private scope: Scope<T>) { }\n\thas(model: T, propertyKey: PropertyKey): boolean {\n\t\treturn this.scope.has(propertyKey);\n\t}\n\tget(model: T, propertyKey: PropertyKey, receiver: any): any {\n\t\tconst value = this.scope.get(propertyKey);\n\t\tif (value == null) {\n\t\t\treturn value;\n\t\t}\n\t\tif (typeof value === 'object') {\n\t\t\tconst scope = this.scope.getScope(propertyKey);\n\t\t\tif (scope) {\n\t\t\t\treturn new Proxy(value, new ScopeProxyHandler(scope));\n\t\t\t}\n\t\t} else if (typeof value === 'function') {\n\t\t\treturn new Proxy(value, this.functionHandler\n\t\t\t\t?? (this.functionHandler = new FunctionProxyHandler(this.scope.getContext()))\n\t\t\t);\n\t\t}\n\t\treturn value;\n\t}\n\tset(model: T, propertyKey: PropertyKey, value: any, receiver: any): boolean {\n\t\treturn this.scope.set(propertyKey, value);\n\t}\n\tdeleteProperty(model: T, propertyKey: string | symbol): boolean {\n\t\treturn this.scope.delete(propertyKey);\n\t}\n}\n\nexport type RevocableProxy<T> = {\n\tproxy: T;\n\trevoke: () => void;\n};\n\nexport function createRevocableProxyForContext<T extends object>(context: T, scope: Scope<T>): RevocableProxy<T> {\n\treturn Proxy.revocable<T>(context, new ScopeProxyHandler(scope));\n}\n\nexport function createProxyForContext<T extends object>(scope: Scope<T>): T {\n\treturn new Proxy<T>(scope.getContext(), new ScopeProxyHandler(scope));\n}\n"]}
package/scope/scope.d.ts CHANGED
@@ -3,13 +3,49 @@ export declare type ScopeContext = {
3
3
  [key: PropertyKey]: ScopeContext | any;
4
4
  };
5
5
  export interface Scope<T = ScopeContext> {
6
+ /**
7
+ * get value of `propertyKey` in current context
8
+ * @param propertyKey
9
+ */
6
10
  get(propertyKey: keyof T): any;
11
+ /**
12
+ * set the value of `propertyKey` in current context, could be instilled with `value`.
13
+ * @param propertyKey
14
+ * @param value
15
+ * @param receiver
16
+ */
7
17
  set(propertyKey: keyof T, value?: any, receiver?: any): boolean;
18
+ /**
19
+ * is current context has `propertyKey` in hash map keys
20
+ * @param propertyKey
21
+ */
8
22
  has(propertyKey: keyof T): boolean;
23
+ /**
24
+ * delete property from context
25
+ * @param propertyKey
26
+ */
9
27
  delete(propertyKey: keyof T): boolean;
28
+ /**
29
+ * get current context object of this scope
30
+ */
10
31
  getContext(): T;
32
+ /**
33
+ * get a proxy of the current context object if exists.
34
+ */
11
35
  getContextProxy?(): T;
36
+ /**
37
+ * get a scope for an object named as `propertyKey` from cache map,
38
+ *
39
+ * if the current value is not type od `object`, will return `undefined`.
40
+ * @param propertyKey the name of the property
41
+ */
12
42
  getScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;
43
+ /**
44
+ * get a scope for an object named as `propertyKey` from cache map,
45
+ *
46
+ * if no scope found in the cache, will create a new one, add this one to the map, return a reference.
47
+ * @param propertyKey
48
+ */
13
49
  getScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;
14
50
  getClass(): TypeOf<Scope<ScopeContext>>;
15
51
  }
@@ -45,6 +81,9 @@ export declare class ValueChangeObserver<T> {
45
81
  unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>): void;
46
82
  pause(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
47
83
  resume(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
84
+ /**
85
+ * clear subscription maps
86
+ */
48
87
  destroy(): void;
49
88
  }
50
89
  export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
@@ -64,10 +103,30 @@ export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
64
103
  unsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>): void;
65
104
  getClass(): TypeOf<ReactiveScope<ScopeContext>>;
66
105
  }
106
+ /**
107
+ * used control/notify/pause scope about changes in current context
108
+ */
67
109
  export interface ScopeControl<T extends ScopeContext> {
110
+ /**
111
+ * get current stacte of applying change detection.
112
+ */
68
113
  isAttached(): boolean;
114
+ /**
115
+ * used when want to update ui-view like, you want to replace an array with another
116
+ * without reflect changes on view until reattached again.
117
+ */
69
118
  detach(): void;
119
+ /**
120
+ * apply all the not emitted changes, and continue emit in time.
121
+ */
70
122
  reattach(): void;
123
+ /**
124
+ * apply changes now,
125
+ * will not effect the state of the detector wither if attached ot not.
126
+ *
127
+ * if a propertyKey is provided, will emit this property only
128
+ * @param propertyKey
129
+ */
71
130
  emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
72
131
  }
73
132
  export declare class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {
@@ -84,6 +143,15 @@ export declare class ReactiveScopeControl<T extends ScopeContext> extends Reacti
84
143
  }
85
144
  interface ImportMeta {
86
145
  url: URL;
146
+ /**
147
+ *
148
+ * Provides a module-relative resolution function scoped to each module, returning
149
+ * the URL string.
150
+ *
151
+ * @param specified The module specifier to resolve relative to `parent`.
152
+ * @param parent The absolute parent module URL to resolve from. If none
153
+ * is specified, the value of `import.meta.url` is used as the default.
154
+ */
87
155
  resolve?(specified: string, parent?: string | URL): Promise<string>;
88
156
  }
89
157
  export interface ModuleImport {
package/scope/scope.js CHANGED
@@ -67,9 +67,11 @@ export class ReadOnlyScope extends Scope {
67
67
  return new ReadOnlyScope({}, propertyKeys);
68
68
  }
69
69
  set(propertyKey, value, receiver) {
70
+ // do nothing
70
71
  return false;
71
72
  }
72
73
  delete(propertyKey) {
74
+ // do nothing
73
75
  return false;
74
76
  }
75
77
  getClass() {
@@ -147,6 +149,9 @@ export class ValueChangeObserver {
147
149
  const subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);
148
150
  subscriptionInfo && (subscriptionInfo.enable = true);
149
151
  }
152
+ /**
153
+ * clear subscription maps
154
+ */
150
155
  destroy() {
151
156
  this.subscribers.clear();
152
157
  }
@@ -1 +1 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AA4DA,MAAM,OAAO,KAAK;IASjB,YAAsB,OAAU,EAAE,YAA0B;QAAtC,YAAO,GAAP,OAAO,CAAG;QAFtB,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;QAGnD,IAAI,CAAC,YAAY,GAAG,YAAY,CAAC;QACjC,IAAI,KAAK,CAAC,OAAO,CAAC,IAAI,CAAC,YAAY,CAAC,EAAE;YACrC,IAAI,CAAC,GAAG,GAAG,CAAC,WAAoB,EAAW,EAAE;gBAC5C,OAAO,IAAI,CAAC,YAAa,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAC;YACjD,CAAC,CAAC;SACF;IACF,CAAC;IAfD,MAAM,CAAC,GAAG,CAAyB,OAAU,EAAE,YAA0B;QACxE,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACzC,CAAC;IACD,MAAM,CAAC,UAAU,CAAyB,YAA0B;QACnE,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE,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;QACL,IAAI,CAAC,QAAQ,GAAG,KAAK,CAAC;IACvB,CAAC;IACD,QAAQ;QACP,IAAI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC;IACD,WAAW,CAAC,WAAqB,EAAE,aAAmB;QACrD,IAAI,WAAW,EAAE;YAChB,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,CAAC;YACvC,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;YACjD,OAAO;SACP;QACD,MAAM,aAAa,GAAG,IAAI,CAAC,MAAM,CAAC;QAClC,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAChD,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACJ,CAAC;IACD,QAAQ;QACP,OAAO,oBAAoB,CAAC;IAC7B,CAAC;CACD;AAyBD,MAAM,OAAO,WAAY,SAAQ,aAA4B;IAC5D,YAAY,OAAsB,EAAE,YAAsC;QACzE,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9B,CAAC;IACD,YAAY,CAAC,WAAgC,EAAE,KAAkB;QAChE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;CACD;AACD,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC9C;QACC,KAAK,CAAC,EAAmB,CAAC,CAAC;IAC5B,CAAC;IACD,aAAa,CAAC,OAAY;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD","sourcesContent":["import { TypeOf } from '../api/utils.js';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\n\n\t/**\n\t * get value of `propertyKey` in current context\n\t * @param propertyKey \n\t */\n\tget(propertyKey: keyof T): any;\n\n\t/**\n\t * set the value of `propertyKey` in current context, could be instilled with `value`.\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: keyof T, value?: any, receiver?: any): boolean;\n\n\t/**\n\t * is current context has `propertyKey` in hash map keys\n\t * @param propertyKey \n\t */\n\thas(propertyKey: keyof T): boolean;\n\n\t/**\n\t * delete property from context\n\t * @param propertyKey \n\t */\n\tdelete(propertyKey: keyof T): boolean;\n\n\t/**\n\t * get current context object of this scope\n\t */\n\tgetContext(): T;\n\n\t/**\n\t * get a proxy of the current context object if exists. \n\t */\n\tgetContextProxy?(): T;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if the current value is not type od `object`, will return `undefined`.\n\t * @param propertyKey the name of the property\n\t */\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if no scope found in the cache, will create a new one, add this one to the map, return a reference.\n\t * @param propertyKey\n\t */\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;\n\n\tgetClass(): TypeOf<Scope<ScopeContext>>;\n}\n\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope({} as T, propertyKeys);\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tprotected propertyKeys?: (keyof T)[];\n\tconstructor(protected context: T, propertyKeys?: (keyof T)[]) {\n\t\tthis.propertyKeys = propertyKeys;\n\t\tif (Array.isArray(this.propertyKeys)) {\n\t\t\tthis.has = (propertyKey: keyof T): boolean => {\n\t\t\t\treturn this.propertyKeys!.includes(propertyKey);\n\t\t\t};\n\t\t}\n\t}\n\tget(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.context, propertyKey);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this.context, propertyKey, value);\n\t}\n\thas(propertyKey: keyof T): boolean {\n\t\treturn propertyKey in this.context;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this.context, propertyKey);\n\t}\n\tgetContext(): T {\n\t\treturn this.context;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new (this.getClass())(scopeContext);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V> {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new (this.getClass())(scopeContext);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetClass(): TypeOf<Scope<ScopeContext>> {\n\t\treturn Scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope({} as T, propertyKeys);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tgetClass(): TypeOf<ReadOnlyScope<ScopeContext>> {\n\t\treturn ReadOnlyScope;\n\t}\n}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<T>) { }\n\tpause() {\n\t\tthis.observer.pause(this.propertyKey, this);\n\t}\n\tresume() {\n\t\tthis.observer.resume(this.propertyKey, this);\n\t}\n\tunsubscribe(): void {\n\t\tthis.observer.unsubscribe(this.propertyKey, this);\n\t}\n}\n\nexport type ValueChangedCallback = (newValue: any, oldValue?: any) => void;\n\ntype SubscriptionInfo = { callback: ValueChangedCallback, enable: boolean };\n\nexport class ValueChangeObserver<T> {\n\tprivate subscribers: Map<keyof T, Map<ScopeSubscription<T>, SubscriptionInfo>> = new Map();\n\tprivate propertiesLock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.propertiesLock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this.subscribers.get(propertyKey);\n\t\tif (!subscribers || subscribers.size == 0) {\n\t\t\treturn;\n\t\t}\n\t\tthis.propertiesLock.push(propertyKey);\n\t\tsubscribers?.forEach(subscriptionInfo => {\n\t\t\tif (!subscriptionInfo.enable) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tsubscriptionInfo.callback(newValue, oldValue);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e);\n\t\t\t}\n\t\t});\n\t\tif (this.propertiesLock.pop() !== propertyKey) {\n\t\t\tconsole.error('lock error');\n\t\t};\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\tconst subscription: ScopeSubscription<T> = new ScopeSubscription(propertyKey, this);\n\t\tlet propertySubscribers = this.subscribers.get(propertyKey);\n\t\tif (!propertySubscribers) {\n\t\t\tpropertySubscribers = new Map();\n\t\t\tthis.subscribers.set(propertyKey, propertySubscribers);\n\t\t}\n\t\tpropertySubscribers.set(subscription, { callback, enable: true });\n\t\treturn subscription;\n\t}\n\n\tunsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (subscription) {\n\t\t\tthis.subscribers.get(propertyKey)?.delete(subscription);\n\t\t} else {\n\t\t\tthis.subscribers.delete(propertyKey);\n\t\t}\n\t}\n\n\tpause(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = false);\n\t}\n\n\tresume(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = true);\n\t}\n\n\t/**\n\t * clear subscription maps\n\t */\n\tdestroy() {\n\t\tthis.subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope({} as T, propertyKeys);\n\t}\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\tprotected name?: string;\n\n\tconstructor(context: T, propertyKeys?: (keyof T)[]);\n\tconstructor(context: T, name: string, parent: ReactiveScope<any>, propertyKeys?: (keyof T)[]);\n\tconstructor(context: T, name?: string | (keyof T)[], protected parent?: ReactiveScope<any>, propertyKeys?: (keyof T)[]) {\n\t\tsuper(context, Array.isArray(name) ? name : propertyKeys);\n\t\tif (typeof name == 'string') {\n\t\t\tthis.name = name;\n\t\t}\n\t\tif (Array.isArray(name)) {\n\t\t\tthis.propertyKeys = name;\n\t\t}\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst result = Reflect.set(this.context, propertyKey, newValue);\n\t\tif (result) {\n\t\t\tthis.emit(propertyKey, newValue, oldValue);\n\t\t}\n\t\treturn result;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this.context, propertyKey);\n\t\tif (isDelete && oldValue !== undefined) {\n\t\t\tthis.emit(propertyKey, undefined, oldValue);\n\t\t}\n\t\treturn isDelete;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tthis.observer.emit(propertyKey, newValue, oldValue);\n\t\tthis.parent?.emit(this.name!, this.context);\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\treturn this.observer.subscribe(propertyKey, callback);\n\t}\n\tunsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (propertyKey && subscription) {\n\t\t\tthis.observer.unsubscribe(propertyKey, subscription);\n\t\t} else if (propertyKey) {\n\t\t\tthis.observer.unsubscribe(propertyKey);\n\t\t} else {\n\t\t\tthis.observer.destroy();\n\t\t}\n\t}\n\tgetClass(): TypeOf<ReactiveScope<ScopeContext>> {\n\t\treturn ReactiveScope;\n\t}\n}\n\n/**\n * used control/notify/pause scope about changes in current context\n */\nexport interface ScopeControl<T extends ScopeContext> {\n\n\t/**\n\t * get current stacte of applying change detection.\n\t */\n\tisAttached(): boolean;\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * apply changes now,\n\t * will not effect the state of the detector wither if attached ot not.\n\t * \n\t * if a propertyKey is provided, will emit this property only \n\t * @param propertyKey \n\t */\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void;\n}\n\nexport class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl({} as T, propertyKeys);\n\t}\n\n\tprotected attached: boolean = true;\n\tprotected marked: ScopeContext = {};\n\toverride emit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.attached) {\n\t\t\tsuper.emit(propertyKey, newValue, oldValue);\n\t\t} else {\n\t\t\tthis.marked[propertyKey] = newValue;\n\t\t}\n\t}\n\tisAttached(): boolean {\n\t\treturn this.attached;\n\t}\n\tdetach(): void {\n\t\tthis.attached = false;\n\t}\n\treattach(): void {\n\t\tthis.attached = true;\n\t\tthis.emitChanges();\n\t}\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void {\n\t\tif (propertyKey) {\n\t\t\tsuper.emit(propertyKey, propertyValue);\n\t\t\tReflect.deleteProperty(this.marked, propertyKey);\n\t\t\treturn;\n\t\t}\n\t\tconst latestChanges = this.marked;\n\t\tthis.marked = {};\n\t\tObject.keys(latestChanges).forEach(propertyKey => {\n\t\t\tsuper.emit(propertyKey, latestChanges[propertyKey]);\n\t\t});\n\t}\n\tgetClass(): TypeOf<ReactiveScopeControl<ScopeContext>> {\n\t\treturn ReactiveScopeControl;\n\t}\n}\n\n\ninterface ImportMeta {\n\turl: URL;\n\t/**\n\t *\n\t * Provides a module-relative resolution function scoped to each module, returning\n\t * the URL string.\n\t *\n\t * @param specified The module specifier to resolve relative to `parent`.\n\t * @param parent The absolute parent module URL to resolve from. If none\n\t * is specified, the value of `import.meta.url` is used as the default.\n\t */\n\tresolve?(specified: string, parent?: string | URL): Promise<string>;\n}\n\nexport interface ModuleImport {\n\tmeta: ImportMeta\n}\n\nexport interface ModuleContext extends ScopeContext {\n\timport: ModuleImport & ((path: string) => Promise<any>);\n}\n\nexport class ModuleScope extends ReactiveScope<ModuleContext> {\n\tconstructor(context: ModuleContext, propertyKeys?: (keyof ModuleContext)[]) {\n\t\tsuper(context, propertyKeys);\n\t}\n\timportModule(propertyKey: keyof ModuleContext, scope: ModuleScope): void {\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t}\n}\nexport class WebModuleScope extends ModuleScope {\n\tconstructor() {\n\t\tsuper({} as ModuleContext);\n\t}\n\tupdateContext(context: any) {\n\t\tthis.context = context;\n\t}\n}\n"]}
1
+ {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AA4DA,MAAM,OAAO,KAAK;IASjB,YAAsB,OAAU,EAAE,YAA0B;QAAtC,YAAO,GAAP,OAAO,CAAG;QAFtB,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;QAG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Q,aAA4B;IAC5D,YAAY,OAAsB,EAAE,YAAsC;QACzE,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9B,CAAC;IACD,YAAY,CAAC,WAAgC,EAAE,KAAkB;QAChE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;CACD;AACD,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC9C;QACC,KAAK,CAAC,EAAmB,CAAC,CAAC;IAC5B,CAAC;IACD,aAAa,CAAC,OAAY;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD","sourcesContent":["import { TypeOf } from '../api/utils.js';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\n\n\t/**\n\t * get value of `propertyKey` in current context\n\t * @param propertyKey \n\t */\n\tget(propertyKey: keyof T): any;\n\n\t/**\n\t * set the value of `propertyKey` in current context, could be instilled with `value`.\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: keyof T, value?: any, receiver?: any): boolean;\n\n\t/**\n\t * is current context has `propertyKey` in hash map keys\n\t * @param propertyKey \n\t */\n\thas(propertyKey: keyof T): boolean;\n\n\t/**\n\t * delete property from context\n\t * @param propertyKey \n\t */\n\tdelete(propertyKey: keyof T): boolean;\n\n\t/**\n\t * get current context object of this scope\n\t */\n\tgetContext(): T;\n\n\t/**\n\t * get a proxy of the current context object if exists. \n\t */\n\tgetContextProxy?(): T;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if the current value is not type od `object`, will return `undefined`.\n\t * @param propertyKey the name of the property\n\t */\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if no scope found in the cache, will create a new one, add this one to the map, return a reference.\n\t * @param propertyKey\n\t */\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;\n\n\tgetClass(): TypeOf<Scope<ScopeContext>>;\n}\n\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope({} as T, propertyKeys);\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tprotected propertyKeys?: (keyof T)[];\n\tconstructor(protected context: T, propertyKeys?: (keyof T)[]) {\n\t\tthis.propertyKeys = propertyKeys;\n\t\tif (Array.isArray(this.propertyKeys)) {\n\t\t\tthis.has = (propertyKey: keyof T): boolean => {\n\t\t\t\treturn this.propertyKeys!.includes(propertyKey);\n\t\t\t};\n\t\t}\n\t}\n\tget(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.context, propertyKey);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this.context, propertyKey, value);\n\t}\n\thas(propertyKey: keyof T): boolean {\n\t\treturn propertyKey in this.context;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this.context, propertyKey);\n\t}\n\tgetContext(): T {\n\t\treturn this.context;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new (this.getClass())(scopeContext);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V> {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new (this.getClass())(scopeContext);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetClass(): TypeOf<Scope<ScopeContext>> {\n\t\treturn Scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope({} as T, propertyKeys);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tgetClass(): TypeOf<ReadOnlyScope<ScopeContext>> {\n\t\treturn ReadOnlyScope;\n\t}\n}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<T>) { }\n\tpause() {\n\t\tthis.observer.pause(this.propertyKey, this);\n\t}\n\tresume() {\n\t\tthis.observer.resume(this.propertyKey, this);\n\t}\n\tunsubscribe(): void {\n\t\tthis.observer.unsubscribe(this.propertyKey, this);\n\t}\n}\n\nexport type ValueChangedCallback = (newValue: any, oldValue?: any) => void;\n\ntype SubscriptionInfo = { callback: ValueChangedCallback, enable: boolean };\n\nexport class ValueChangeObserver<T> {\n\tprivate subscribers: Map<keyof T, Map<ScopeSubscription<T>, SubscriptionInfo>> = new Map();\n\tprivate propertiesLock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.propertiesLock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this.subscribers.get(propertyKey);\n\t\tif (!subscribers || subscribers.size == 0) {\n\t\t\treturn;\n\t\t}\n\t\tthis.propertiesLock.push(propertyKey);\n\t\tsubscribers?.forEach(subscriptionInfo => {\n\t\t\tif (!subscriptionInfo.enable) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tsubscriptionInfo.callback(newValue, oldValue);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e);\n\t\t\t}\n\t\t});\n\t\tif (this.propertiesLock.pop() !== propertyKey) {\n\t\t\tconsole.error('lock error');\n\t\t};\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\tconst subscription: ScopeSubscription<T> = new ScopeSubscription(propertyKey, this);\n\t\tlet propertySubscribers = this.subscribers.get(propertyKey);\n\t\tif (!propertySubscribers) {\n\t\t\tpropertySubscribers = new Map();\n\t\t\tthis.subscribers.set(propertyKey, propertySubscribers);\n\t\t}\n\t\tpropertySubscribers.set(subscription, { callback, enable: true });\n\t\treturn subscription;\n\t}\n\n\tunsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (subscription) {\n\t\t\tthis.subscribers.get(propertyKey)?.delete(subscription);\n\t\t} else {\n\t\t\tthis.subscribers.delete(propertyKey);\n\t\t}\n\t}\n\n\tpause(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = false);\n\t}\n\n\tresume(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = true);\n\t}\n\n\t/**\n\t * clear subscription maps\n\t */\n\tdestroy() {\n\t\tthis.subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope({} as T, propertyKeys);\n\t}\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\tprotected name?: string;\n\n\tconstructor(context: T, propertyKeys?: (keyof T)[]);\n\tconstructor(context: T, name: string, parent: ReactiveScope<any>, propertyKeys?: (keyof T)[]);\n\tconstructor(context: T, name?: string | (keyof T)[], protected parent?: ReactiveScope<any>, propertyKeys?: (keyof T)[]) {\n\t\tsuper(context, Array.isArray(name) ? name : propertyKeys);\n\t\tif (typeof name == 'string') {\n\t\t\tthis.name = name;\n\t\t}\n\t\tif (Array.isArray(name)) {\n\t\t\tthis.propertyKeys = name;\n\t\t}\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst result = Reflect.set(this.context, propertyKey, newValue);\n\t\tif (result) {\n\t\t\tthis.emit(propertyKey, newValue, oldValue);\n\t\t}\n\t\treturn result;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this.context, propertyKey);\n\t\tif (isDelete && oldValue !== undefined) {\n\t\t\tthis.emit(propertyKey, undefined, oldValue);\n\t\t}\n\t\treturn isDelete;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tthis.observer.emit(propertyKey, newValue, oldValue);\n\t\tthis.parent?.emit(this.name!, this.context);\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\treturn this.observer.subscribe(propertyKey, callback);\n\t}\n\tunsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (propertyKey && subscription) {\n\t\t\tthis.observer.unsubscribe(propertyKey, subscription);\n\t\t} else if (propertyKey) {\n\t\t\tthis.observer.unsubscribe(propertyKey);\n\t\t} else {\n\t\t\tthis.observer.destroy();\n\t\t}\n\t}\n\tgetClass(): TypeOf<ReactiveScope<ScopeContext>> {\n\t\treturn ReactiveScope;\n\t}\n}\n\n/**\n * used control/notify/pause scope about changes in current context\n */\nexport interface ScopeControl<T extends ScopeContext> {\n\n\t/**\n\t * get current stacte of applying change detection.\n\t */\n\tisAttached(): boolean;\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * apply changes now,\n\t * will not effect the state of the detector wither if attached ot not.\n\t * \n\t * if a propertyKey is provided, will emit this property only \n\t * @param propertyKey \n\t */\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void;\n}\n\nexport class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl({} as T, propertyKeys);\n\t}\n\n\tprotected attached: boolean = true;\n\tprotected marked: ScopeContext = {};\n\toverride emit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.attached) {\n\t\t\tsuper.emit(propertyKey, newValue, oldValue);\n\t\t} else {\n\t\t\tthis.marked[propertyKey] = newValue;\n\t\t}\n\t}\n\tisAttached(): boolean {\n\t\treturn this.attached;\n\t}\n\tdetach(): void {\n\t\tthis.attached = false;\n\t}\n\treattach(): void {\n\t\tthis.attached = true;\n\t\tthis.emitChanges();\n\t}\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void {\n\t\tif (propertyKey) {\n\t\t\tsuper.emit(propertyKey, propertyValue);\n\t\t\tReflect.deleteProperty(this.marked, propertyKey);\n\t\t\treturn;\n\t\t}\n\t\tconst latestChanges = this.marked;\n\t\tthis.marked = {};\n\t\tObject.keys(latestChanges).forEach(propertyKey => {\n\t\t\tsuper.emit(propertyKey, latestChanges[propertyKey]);\n\t\t});\n\t}\n\tgetClass(): TypeOf<ReactiveScopeControl<ScopeContext>> {\n\t\treturn ReactiveScopeControl;\n\t}\n}\n\n\ninterface ImportMeta {\n\turl: URL;\n\t/**\n\t *\n\t * Provides a module-relative resolution function scoped to each module, returning\n\t * the URL string.\n\t *\n\t * @param specified The module specifier to resolve relative to `parent`.\n\t * @param parent The absolute parent module URL to resolve from. If none\n\t * is specified, the value of `import.meta.url` is used as the default.\n\t */\n\tresolve?(specified: string, parent?: string | URL): Promise<string>;\n}\n\nexport interface ModuleImport {\n\tmeta: ImportMeta\n}\n\nexport interface ModuleContext extends ScopeContext {\n\timport: ModuleImport & ((path: string) => Promise<any>);\n}\n\nexport class ModuleScope extends ReactiveScope<ModuleContext> {\n\tconstructor(context: ModuleContext, propertyKeys?: (keyof ModuleContext)[]) {\n\t\tsuper(context, propertyKeys);\n\t}\n\timportModule(propertyKey: keyof ModuleContext, scope: ModuleScope): void {\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t}\n}\nexport class WebModuleScope extends ModuleScope {\n\tconstructor() {\n\t\tsuper({} as ModuleContext);\n\t}\n\tupdateContext(context: any) {\n\t\tthis.context = context;\n\t}\n}\n"]}
package/scope/stack.d.ts CHANGED
@@ -10,16 +10,64 @@ export interface AsyncIterableInfo {
10
10
  forAwaitBody: (iterator: any) => any;
11
11
  }
12
12
  export interface Stack {
13
+ /**
14
+ * a list of promises to resolve in an 'async' scope as 'async function'
15
+ */
13
16
  awaitPromise: Array<AwaitPromiseInfo>;
17
+ /**
18
+ * resolve await promise in 'await for in' scope
19
+ */
14
20
  forAwaitAsyncIterable?: AsyncIterableInfo;
21
+ /**
22
+ * is this stack has a propertyKey
23
+ * @param propertyKey
24
+ */
15
25
  has(propertyKey: PropertyKey): boolean;
26
+ /**
27
+ * get the first value for provided property key,
28
+ *
29
+ * will search current stack in all scope till find the first key, else undefined
30
+ * @param propertyKey
31
+ */
16
32
  get(propertyKey: PropertyKey): any;
33
+ /**
34
+ * set the value of `propertyKey` in its context provider with `value`.
35
+ * else define it in the first scope 'local scope'
36
+ * @param propertyKey
37
+ * @param value
38
+ * @param receiver
39
+ */
17
40
  set(propertyKey: PropertyKey, value: any, receiver?: any): boolean;
41
+ /**
42
+ * declare variable at last scope in the stack,
43
+ *
44
+ * @param propertyKey the name of property mey be string | number | symbol,
45
+ * @param propertyValue if not exist will be initialize with 'undefined' value
46
+ */
18
47
  declareVariable(propertyKey: PropertyKey, propertyValue?: any): any;
48
+ /**
49
+ * get context object of this provider,
50
+ * search for the first context object that has `propertyKey`.
51
+ *
52
+ * search for the first context that have property key,
53
+ * if not found will return the stack local scop as a default value
54
+ * @param propertyKey the property key
55
+ */
19
56
  findScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;
20
57
  resolveAwait(value: AwaitPromiseInfo): void;
58
+ /**
59
+ * get a reference to the last scope in this stack
60
+ */
21
61
  lastScope<T extends ScopeContext>(): Scope<T>;
62
+ /**
63
+ * clear every thing after this scope, and even this scope
64
+ * @param scope
65
+ */
22
66
  clearTo<T extends ScopeContext>(scope: Scope<T>): boolean;
67
+ /**
68
+ * clear every thing after this scope, but not this scope
69
+ * @param scope
70
+ */
23
71
  clearTill<T extends ScopeContext>(scope: Scope<T>): boolean;
24
72
  popScope<T extends ScopeContext>(): Scope<T>;
25
73
  removeScope<T extends ScopeContext>(scope: Scope<T>): void;
@@ -28,11 +76,34 @@ export interface Stack {
28
76
  pushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;
29
77
  pushReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
30
78
  pushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
79
+ /**
80
+ * create new stack instance with the same reference to the current scope array
81
+ */
31
82
  copyStack(): Stack;
83
+ /**
84
+ * used when want to update ui-view like, you want to replace an array with another
85
+ * without reflect changes on view until reattached again.
86
+ */
32
87
  detach(): void;
88
+ /**
89
+ * apply all the not emitted changes, and continue emit in time.
90
+ */
33
91
  reattach(): void;
92
+ /**
93
+ * import module scope from another stack, by the help of ModuleScopeResolver.
94
+ *
95
+ * used with import statement
96
+ */
34
97
  importModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;
98
+ /**
99
+ * get the current module for this stack.
100
+ *
101
+ * used with export statement
102
+ */
35
103
  getModule(): ModuleScope | undefined;
104
+ /**
105
+ * register action to do on destroy this stack
106
+ */
36
107
  onDestroy(action: () => void): void;
37
108
  }
38
109
  export declare class Stack implements Stack {
@@ -60,6 +131,9 @@ export interface ModuleScopeResolver {
60
131
  }
61
132
  export declare function createRootURL(source: string): URL;
62
133
  export interface ResolverConfig {
134
+ /**
135
+ *
136
+ */
63
137
  allowImportExternal?: boolean;
64
138
  }
65
139
  export declare class ModuleScopeResolver implements ModuleScopeResolver {
package/scope/stack.js CHANGED
@@ -15,11 +15,14 @@ export class Stack {
15
15
  if (resolver && moduleSource) {
16
16
  this.resolver = resolver;
17
17
  this.moduleSource = moduleSource;
18
+ // init module scope for import and export
18
19
  this.moduleScope = new ModuleScope(this.initModuleContext());
19
20
  this.pushScope(this.moduleScope);
21
+ // for the rest of module body
20
22
  this.pushReactiveScope();
21
23
  }
22
24
  else {
25
+ // not a module scope
23
26
  this.pushBlockScope();
24
27
  }
25
28
  finalizerRegister(this, this.onDestroyActions, this);
@@ -140,6 +143,7 @@ export class Stack {
140
143
  }
141
144
  importModule(source, importCallOptions) {
142
145
  if (!this.resolver || !this.moduleScope) {
146
+ // should o the parse and import the module
143
147
  throw new Error('Module Resolver is undefined');
144
148
  }
145
149
  return this.resolver.resolve(source, this.moduleScope, importCallOptions);
@@ -223,6 +227,8 @@ export class ModuleScopeResolver {
223
227
  }
224
228
  const webScope = new WebModuleScope();
225
229
  this.modules.push([source, webScope]);
230
+ // active later
231
+ // import(source, importCallOptions)
226
232
  import(source).then(module => {
227
233
  webScope.updateContext(module);
228
234
  });