@ibyar/expressions 0.5.2 → 0.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -3
- package/api/abstract.d.ts +3 -4
- package/api/abstract.js +1 -1
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +196 -0
- package/api/class/class.js +594 -0
- package/api/class/class.js.map +1 -0
- package/api/class/decorator.d.ts +20 -0
- package/api/class/decorator.js +48 -0
- package/api/class/decorator.js.map +1 -0
- package/api/computing/call.d.ts +3 -1
- package/api/computing/call.js +16 -4
- package/api/computing/call.js.map +1 -1
- package/api/computing/new.d.ts +2 -1
- package/api/computing/new.js +4 -0
- package/api/computing/new.js.map +1 -1
- package/api/computing/rest.d.ts +3 -3
- package/api/computing/rest.js +5 -2
- package/api/computing/rest.js.map +1 -1
- package/api/computing/return.d.ts +2 -1
- package/api/computing/return.js +3 -0
- package/api/computing/return.js.map +1 -1
- package/api/computing/spread.d.ts +2 -1
- package/api/computing/spread.js +5 -2
- package/api/computing/spread.js.map +1 -1
- package/api/computing/throw.d.ts +2 -1
- package/api/computing/throw.js +3 -0
- package/api/computing/throw.js.map +1 -1
- package/api/computing/yield.d.ts +2 -1
- package/api/computing/yield.js +3 -0
- package/api/computing/yield.js.map +1 -1
- package/api/definition/array.d.ts +6 -7
- package/api/definition/array.js +13 -13
- package/api/definition/array.js.map +1 -1
- package/api/definition/bind.d.ts +2 -2
- package/api/definition/bind.js +1 -1
- package/api/definition/bind.js.map +1 -1
- package/api/definition/function.d.ts +8 -8
- package/api/definition/function.js +25 -25
- package/api/definition/function.js.map +1 -1
- package/api/definition/member.d.ts +2 -2
- package/api/definition/member.js +1 -1
- package/api/definition/member.js.map +1 -1
- package/api/definition/object.d.ts +7 -7
- package/api/definition/object.js +9 -9
- package/api/definition/object.js.map +1 -1
- package/api/definition/statement.d.ts +2 -2
- package/api/definition/statement.js +2 -2
- package/api/definition/statement.js.map +1 -1
- package/api/definition/values.d.ts +5 -4
- package/api/definition/values.js +7 -4
- package/api/definition/values.js.map +1 -1
- package/api/expression.d.ts +9 -12
- package/api/expression.js.map +1 -1
- package/api/{app → module/app}/program.d.ts +8 -9
- package/api/module/app/program.js +45 -0
- package/api/module/app/program.js.map +1 -0
- package/api/module/export.d.ts +60 -25
- package/api/module/export.js +230 -60
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +66 -25
- package/api/module/import.js +236 -68
- package/api/module/import.js.map +1 -1
- package/api/operators/assignment.d.ts +2 -2
- package/api/operators/assignment.js +1 -1
- package/api/operators/assignment.js.map +1 -1
- package/api/operators/await.d.ts +2 -2
- package/api/operators/await.js +1 -1
- package/api/operators/await.js.map +1 -1
- package/api/operators/binary.d.ts +2 -2
- package/api/operators/binary.js +1 -1
- package/api/operators/binary.js.map +1 -1
- package/api/operators/chaining.d.ts +2 -2
- package/api/operators/chaining.js +1 -1
- package/api/operators/chaining.js.map +1 -1
- package/api/operators/comma.d.ts +2 -2
- package/api/operators/comma.js +2 -2
- package/api/operators/comma.js.map +1 -1
- package/api/operators/grouping.d.ts +2 -2
- package/api/operators/grouping.js +1 -1
- package/api/operators/grouping.js.map +1 -1
- package/api/operators/logical.d.ts +2 -2
- package/api/operators/logical.js +1 -1
- package/api/operators/logical.js.map +1 -1
- package/api/operators/pipeline.d.ts +2 -2
- package/api/operators/pipeline.js +1 -1
- package/api/operators/pipeline.js.map +1 -1
- package/api/operators/ternary.d.ts +2 -2
- package/api/operators/ternary.js +1 -1
- package/api/operators/ternary.js.map +1 -1
- package/api/operators/unary.d.ts +3 -3
- package/api/operators/unary.js +4 -3
- package/api/operators/unary.js.map +1 -1
- package/api/operators/update.d.ts +2 -2
- package/api/operators/update.js +1 -1
- package/api/operators/update.js.map +1 -1
- package/api/statement/control/block.d.ts +3 -3
- package/api/statement/control/block.js +2 -2
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/empty.d.ts +1 -1
- package/api/statement/control/empty.js.map +1 -1
- package/api/statement/control/if.d.ts +2 -2
- package/api/statement/control/if.js +1 -1
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +4 -5
- package/api/statement/control/switch.js +5 -6
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +3 -3
- package/api/statement/control/terminate.js +2 -2
- package/api/statement/control/terminate.js.map +1 -1
- package/api/statement/declarations/declares.d.ts +12 -11
- package/api/statement/declarations/declares.js +23 -18
- package/api/statement/declarations/declares.js.map +1 -1
- package/api/statement/iterations/for.d.ts +5 -5
- package/api/statement/iterations/for.js +7 -7
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +3 -3
- package/api/statement/iterations/while.js +2 -2
- package/api/statement/iterations/while.js.map +1 -1
- package/api/utils.d.ts +3 -0
- package/api/utils.js +2 -0
- package/api/utils.js.map +1 -0
- package/package.json +4 -4
- package/scope/finalizer.d.ts +4 -0
- package/scope/finalizer.js +11 -0
- package/scope/finalizer.js.map +1 -0
- package/scope/proxy.d.ts +2 -1
- package/scope/proxy.js +18 -2
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +40 -51
- package/scope/scope.js +67 -134
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +41 -24
- package/scope/stack.js +148 -102
- package/scope/stack.js.map +1 -1
- package/v8/parser.js +3 -2
- package/v8/parser.js.map +1 -1
- package/visit/visitor.js +4 -7
- package/visit/visitor.js.map +1 -1
- package/api/app/class.d.ts +0 -117
- package/api/app/class.js +0 -292
- package/api/app/class.js.map +0 -1
- package/api/app/program.js +0 -39
- package/api/app/program.js.map +0 -1
- package/api/module/module.d.ts +0 -26
- package/api/module/module.js +0 -63
- package/api/module/module.js.map +0 -1
|
@@ -12,7 +12,7 @@ let WhileNode = WhileNode_1 = class WhileNode extends AbstractExpressionNode {
|
|
|
12
12
|
static fromJSON(node, deserializer) {
|
|
13
13
|
return new WhileNode_1(deserializer(node.test), deserializer(node.body));
|
|
14
14
|
}
|
|
15
|
-
static visit(node, visitNode
|
|
15
|
+
static visit(node, visitNode) {
|
|
16
16
|
visitNode(node.body);
|
|
17
17
|
visitNode(node.test);
|
|
18
18
|
}
|
|
@@ -78,7 +78,7 @@ let DoWhileNode = DoWhileNode_1 = class DoWhileNode extends AbstractExpressionNo
|
|
|
78
78
|
static fromJSON(node, deserializer) {
|
|
79
79
|
return new DoWhileNode_1(deserializer(node.test), deserializer(node.body));
|
|
80
80
|
}
|
|
81
|
-
static visit(node, visitNode
|
|
81
|
+
static visit(node, visitNode) {
|
|
82
82
|
visitNode(node.test);
|
|
83
83
|
visitNode(node.body);
|
|
84
84
|
}
|
|
@@ -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,cAAc,EAAE,iBAAiB,EAAE,MAAM,yBAAyB,CAAC;AAS5E,IAAa,SAAS,iBAAtB,MAAa,SAAU,SAAQ,sBAAsB;IAWpD,YAAoB,IAAoB,EAAU,IAAoB;QACrE,KAAK,EAAE,CAAC;QADW,SAAI,GAAJ,IAAI,CAAgB;QAAU,SAAI,GAAJ,IAAI,CAAgB;IAEtE,CAAC;IAZD,MAAM,CAAC,QAAQ,CAAC,IAAe,EAAE,YAA8B;QAC9D,OAAO,IAAI,WAAS,CACnB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EACvB,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CACvB,CAAC;IACH,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,IAAe,EAAE,SAAwB
|
|
1
|
+
{"version":3,"file":"while.js","sourceRoot":"","sources":["../../../../../src/expressions/api/statement/iterations/while.ts"],"names":[],"mappings":";;AAMA,OAAO,EAAE,sBAAsB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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;AA9DY,WAAW;IADvB,YAAY,CAAC,kBAAkB,CAAC;;GACpB,WAAW,CA8DvB;SA9DY,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 { BreakStatement, ContinueStatement } 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 (ContinueStatement.ContinueSymbol === result) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (BreakStatement.BreakSymbol === result) {\n\t\t\t\tbreak;\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 (ContinueStatement.ContinueSymbol === result) {\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (BreakStatement.BreakSymbol === result) {\n\t\t\t\tbreak;\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/api/utils.d.ts
ADDED
package/api/utils.js
ADDED
package/api/utils.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/expressions/api/utils.ts"],"names":[],"mappings":"","sourcesContent":["export interface TypeOf<T> {\n\tnew(...params: any[]): T;\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ibyar/expressions",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.4",
|
|
4
4
|
"description": "Aurora expression, an template expression evaluation",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"homepage": "https://github.com/ibyar/aurora/tree/dev/packages/expressions",
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
},
|
|
25
25
|
"dependencies": {
|
|
26
26
|
"reflect-metadata": "^0.1.13",
|
|
27
|
-
"tslib": "^2.
|
|
27
|
+
"tslib": "^2.4.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"typescript": "^4.
|
|
30
|
+
"typescript": "^4.6.4"
|
|
31
31
|
},
|
|
32
32
|
"scripts": {
|
|
33
33
|
"build": "tsc --build --verbose"
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"eval",
|
|
50
50
|
"evaluation"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "0e62f914850836abc384d26c9f94a7b8389a2c0d"
|
|
53
53
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const actionsFinalizer = !FinalizationRegistry ? undefined : new FinalizationRegistry(actions => actions.forEach(action => { try {
|
|
2
|
+
action();
|
|
3
|
+
}
|
|
4
|
+
catch (e) { } }));
|
|
5
|
+
export function finalizerRegister(target, actions, unregisterToken) {
|
|
6
|
+
actionsFinalizer?.register(target, actions, unregisterToken);
|
|
7
|
+
}
|
|
8
|
+
export function finalizerUnregister(unregisterToken) {
|
|
9
|
+
actionsFinalizer?.unregister(unregisterToken);
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=finalizer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"finalizer.js","sourceRoot":"","sources":["../../../src/expressions/scope/finalizer.ts"],"names":[],"mappings":"AACA,MAAM,gBAAgB,GAAG,CAAC,oBAAoB,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,IAAI,oBAAoB,CACpF,OAAO,CAAC,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,GAAG,IAAI;IAAE,MAAM,EAAE,CAAC;CAAE;AAAC,OAAO,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,CACzE,CAAC;AAGF,MAAM,UAAU,iBAAiB,CAAC,MAAc,EAAE,OAAgB,EAAE,eAAwB;IAC3F,gBAAgB,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,EAAE,eAAe,CAAC,CAAC;AAC9D,CAAC;AAGD,MAAM,UAAU,mBAAmB,CAAC,eAAuB;IAC1D,gBAAgB,EAAE,UAAU,CAAC,eAAe,CAAC,CAAC;AAC/C,CAAC","sourcesContent":["type Actions = (() => void)[];\nconst actionsFinalizer = !FinalizationRegistry ? undefined : new FinalizationRegistry<Actions>(\n\tactions => actions.forEach(action => { try { action(); } catch (e) { } })\n);\n\n\nexport function finalizerRegister(target: object, actions: Actions, unregisterToken?: object): void {\n\tactionsFinalizer?.register(target, actions, unregisterToken);\n}\n\n\nexport function finalizerUnregister(unregisterToken: object): void {\n\tactionsFinalizer?.unregister(unregisterToken);\n}\n"]}
|
package/scope/proxy.d.ts
CHANGED
|
@@ -2,7 +2,8 @@ import type { Scope, ScopeContext } from './scope.js';
|
|
|
2
2
|
export declare class FunctionProxyHandler<T extends Function> implements ProxyHandler<T> {
|
|
3
3
|
private thisContext;
|
|
4
4
|
constructor(thisContext: object);
|
|
5
|
-
apply(targetFunc: T,
|
|
5
|
+
apply(targetFunc: T, targetThisArg: any, argArray: any[]): any;
|
|
6
|
+
private computeThisArg;
|
|
6
7
|
}
|
|
7
8
|
export declare class ScopeProxyHandler<T extends ScopeContext> implements ProxyHandler<ScopeContext> {
|
|
8
9
|
private scope;
|
package/scope/proxy.js
CHANGED
|
@@ -2,8 +2,21 @@ export class FunctionProxyHandler {
|
|
|
2
2
|
constructor(thisContext) {
|
|
3
3
|
this.thisContext = thisContext;
|
|
4
4
|
}
|
|
5
|
-
apply(targetFunc,
|
|
6
|
-
return targetFunc.apply(this.
|
|
5
|
+
apply(targetFunc, targetThisArg, argArray) {
|
|
6
|
+
return targetFunc.apply(this.computeThisArg(targetThisArg), argArray);
|
|
7
|
+
}
|
|
8
|
+
computeThisArg(targetThisArg) {
|
|
9
|
+
switch (true) {
|
|
10
|
+
case this.thisContext instanceof Map:
|
|
11
|
+
case this.thisContext instanceof Set:
|
|
12
|
+
case this.thisContext instanceof Date:
|
|
13
|
+
case this.thisContext instanceof WeakMap:
|
|
14
|
+
case this.thisContext instanceof WeakSet:
|
|
15
|
+
case this.thisContext instanceof Promise:
|
|
16
|
+
return this.thisContext;
|
|
17
|
+
default:
|
|
18
|
+
return targetThisArg;
|
|
19
|
+
}
|
|
7
20
|
}
|
|
8
21
|
}
|
|
9
22
|
export class ScopeProxyHandler {
|
|
@@ -20,6 +33,9 @@ export class ScopeProxyHandler {
|
|
|
20
33
|
return this.proxyMap.get(propertyKey);
|
|
21
34
|
}
|
|
22
35
|
const value = this.scope.get(propertyKey);
|
|
36
|
+
if (value == null) {
|
|
37
|
+
return value;
|
|
38
|
+
}
|
|
23
39
|
if (typeof value === 'object') {
|
|
24
40
|
const scope = this.scope.getScope(propertyKey);
|
|
25
41
|
if (scope) {
|
package/scope/proxy.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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,
|
|
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,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;gBACvC,OAAO,IAAI,CAAC,WAAW,CAAC;YACzB;gBACC,OAAO,aAAa,CAAC;SACtB;IACF,CAAC;CACD;AAKD,MAAM,OAAO,iBAAiB;IAI7B,YAAoB,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;QAH3B,aAAQ,GAAG,IAAI,GAAG,EAAkB,CAAC;QACrC,kBAAa,GAAG,IAAI,OAAO,EAAkB,CAAC;IAEf,CAAC;IACxC,GAAG,CAAC,KAAQ,EAAE,WAAwB;QACrC,OAAO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C;SACb;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IACD,GAAG,CAAC,KAAQ,EAAE,WAAwB,EAAE,KAAU,EAAE,QAAa;QAChE,IAAI,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,OAAO,KAAK,KAAK,UAAU,CAAC,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,EAAE;YAChG,KAAK,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;SACtC;QACD,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,cAAc,CAAC,KAAQ,EAAE,WAA4B;QACpD,MAAM,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;QAC5D,IAAI,QAAQ,EAAE;YACb,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;YACvC,IAAI,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,EAAE;gBACnC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;aAClC;SACD;QACD,OAAO,QAAQ,CAAC;IACjB,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\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\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 proxyMap = new Map<PropertyKey, T>();\n\tprivate proxyValueMap = new WeakMap<object, object>();\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\tif (this.proxyMap.has(propertyKey)) {\n\t\t\treturn this.proxyMap.get(propertyKey);\n\t\t}\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\tconst proxy = new Proxy(value, new ScopeProxyHandler(scope));\n\t\t\t\tthis.proxyMap.set(propertyKey, proxy);\n\t\t\t\tthis.proxyValueMap.set(proxy, value);\n\t\t\t\treturn proxy;\n\t\t\t}\n\t\t} else if (typeof value === 'function') {\n\t\t\tconst proxy = new Proxy(value, this.functionHandler\n\t\t\t\t?? (this.functionHandler = new FunctionProxyHandler(this.scope.getContext()))\n\t\t\t);\n\t\t\tthis.proxyMap.set(propertyKey, proxy);\n\t\t\tthis.proxyValueMap.set(proxy, value);\n\t\t\treturn proxy;\n\t\t}\n\t\treturn value;\n\t}\n\tset(model: T, propertyKey: PropertyKey, value: any, receiver: any): boolean {\n\t\tif ((typeof value === 'object' || typeof value === 'function') && this.proxyValueMap.has(value)) {\n\t\t\tvalue = this.proxyValueMap.get(value);\n\t\t}\n\t\treturn this.scope.set(propertyKey, value);\n\t}\n\tdeleteProperty(model: T, propertyKey: string | symbol): boolean {\n\t\tconst isDelete = Reflect.deleteProperty(model, propertyKey);\n\t\tif (isDelete) {\n\t\t\tthis.scope.set(propertyKey, undefined);\n\t\t\tif (this.proxyMap.has(propertyKey)) {\n\t\t\t\tthis.proxyMap.delete(propertyKey);\n\t\t\t}\n\t\t}\n\t\treturn isDelete;\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
|
@@ -1,48 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
import { TypeOf } from '../api/utils.js';
|
|
2
2
|
export declare type ScopeContext = {
|
|
3
3
|
[key: PropertyKey]: ScopeContext | any;
|
|
4
4
|
};
|
|
5
5
|
export interface Scope<T = ScopeContext> {
|
|
6
|
-
type: ScopeType;
|
|
7
6
|
get(propertyKey: keyof T): any;
|
|
8
7
|
set(propertyKey: keyof T, value?: any, receiver?: any): boolean;
|
|
9
8
|
has(propertyKey: keyof T): boolean;
|
|
10
9
|
delete(propertyKey: keyof T): boolean;
|
|
11
10
|
getContext(): T;
|
|
11
|
+
getContextProxy?(): T;
|
|
12
12
|
getScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;
|
|
13
13
|
getScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;
|
|
14
|
+
getClass(): TypeOf<Scope<ScopeContext>>;
|
|
14
15
|
}
|
|
15
16
|
export declare class Scope<T extends ScopeContext> implements Scope<T> {
|
|
16
17
|
protected context: T;
|
|
17
|
-
|
|
18
|
-
static
|
|
19
|
-
static blockScopeFor<T extends ScopeContext>(context: T): Scope<T>;
|
|
20
|
-
static functionScopeFor<T extends ScopeContext>(context: T): Scope<T>;
|
|
21
|
-
static classScopeFor<T extends ScopeContext>(context: T): Scope<T>;
|
|
22
|
-
static moduleScopeFor<T extends ScopeContext>(context: T): Scope<T>;
|
|
23
|
-
static globalScopeFor<T extends ScopeContext>(context: T): Scope<T>;
|
|
24
|
-
static blockScope<T extends ScopeContext>(): Scope<T>;
|
|
25
|
-
static functionScope<T extends ScopeContext>(): Scope<T>;
|
|
26
|
-
static classScope<T extends ScopeContext>(): Scope<T>;
|
|
27
|
-
static moduleScope<T extends ScopeContext>(): Scope<T>;
|
|
28
|
-
static globalScope<T extends ScopeContext>(): Scope<T>;
|
|
18
|
+
static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): Scope<T>;
|
|
19
|
+
static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): Scope<T>;
|
|
29
20
|
protected scopeMap: Map<keyof T, Scope<any>>;
|
|
30
|
-
|
|
21
|
+
protected propertyKeys?: (keyof T)[];
|
|
22
|
+
constructor(context: T, propertyKeys?: (keyof T)[]);
|
|
31
23
|
}
|
|
32
24
|
export declare class ReadOnlyScope<T extends ScopeContext> extends Scope<T> {
|
|
33
|
-
static for<T extends ScopeContext>(context: T,
|
|
34
|
-
static
|
|
35
|
-
static functionScopeFor<T extends ScopeContext>(context: T): ReadOnlyScope<T>;
|
|
36
|
-
static classScopeFor<T extends ScopeContext>(context: T): ReadOnlyScope<T>;
|
|
37
|
-
static moduleScopeFor<T extends ScopeContext>(context: T): ReadOnlyScope<T>;
|
|
38
|
-
static globalScopeFor<T extends ScopeContext>(context: T): ReadOnlyScope<T>;
|
|
39
|
-
static blockScope<T extends ScopeContext>(): ReadOnlyScope<T>;
|
|
40
|
-
static functionScope<T extends ScopeContext>(): ReadOnlyScope<T>;
|
|
41
|
-
static classScope<T extends ScopeContext>(): ReadOnlyScope<T>;
|
|
42
|
-
static moduleScope<T extends ScopeContext>(): ReadOnlyScope<T>;
|
|
43
|
-
static globalScope<T extends ScopeContext>(): ReadOnlyScope<T>;
|
|
25
|
+
static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): ReadOnlyScope<T>;
|
|
26
|
+
static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): ReadOnlyScope<T>;
|
|
44
27
|
set(propertyKey: keyof T, value: any, receiver?: any): boolean;
|
|
45
28
|
delete(propertyKey: keyof T): boolean;
|
|
29
|
+
getClass(): TypeOf<ReadOnlyScope<ScopeContext>>;
|
|
46
30
|
}
|
|
47
31
|
export declare class ScopeSubscription<T> {
|
|
48
32
|
private propertyKey;
|
|
@@ -64,22 +48,13 @@ export declare class ValueChangeObserver<T> {
|
|
|
64
48
|
destroy(): void;
|
|
65
49
|
}
|
|
66
50
|
export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
|
|
67
|
-
protected name?: string | undefined;
|
|
68
51
|
protected parent?: ReactiveScope<any> | undefined;
|
|
69
|
-
static for<T extends ScopeContext>(context: T,
|
|
70
|
-
static
|
|
71
|
-
static functionScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
|
|
72
|
-
static classScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
|
|
73
|
-
static moduleScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
|
|
74
|
-
static globalScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
|
|
75
|
-
static blockScope<T extends ScopeContext>(): ReactiveScope<T>;
|
|
76
|
-
static functionScope<T extends ScopeContext>(): ReactiveScope<T>;
|
|
77
|
-
static classScope<T extends ScopeContext>(): ReactiveScope<T>;
|
|
78
|
-
static moduleScope<T extends ScopeContext>(): ReactiveScope<T>;
|
|
79
|
-
static globalScope<T extends ScopeContext>(): ReactiveScope<T>;
|
|
52
|
+
static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): ReactiveScope<T>;
|
|
53
|
+
static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): ReactiveScope<T>;
|
|
80
54
|
protected observer: ValueChangeObserver<T>;
|
|
81
|
-
|
|
82
|
-
constructor(context: T,
|
|
55
|
+
protected name?: string;
|
|
56
|
+
constructor(context: T, propertyKeys?: (keyof T)[]);
|
|
57
|
+
constructor(context: T, name: string, parent: ReactiveScope<any>, propertyKeys?: (keyof T)[]);
|
|
83
58
|
set(propertyKey: keyof T, newValue: any, receiver?: any): boolean;
|
|
84
59
|
delete(propertyKey: keyof T): boolean;
|
|
85
60
|
getScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined;
|
|
@@ -87,28 +62,42 @@ export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
|
|
|
87
62
|
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
88
63
|
subscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T>;
|
|
89
64
|
unsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>): void;
|
|
65
|
+
getClass(): TypeOf<ReactiveScope<ScopeContext>>;
|
|
90
66
|
}
|
|
91
67
|
export interface ScopeControl<T extends ScopeContext> {
|
|
68
|
+
isAttached(): boolean;
|
|
92
69
|
detach(): void;
|
|
93
70
|
reattach(): void;
|
|
94
71
|
emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
|
|
95
72
|
}
|
|
96
73
|
export declare class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {
|
|
97
|
-
static for<T extends ScopeContext>(context: T,
|
|
98
|
-
static
|
|
99
|
-
static functionScopeFor<T extends ScopeContext>(context: T): ReactiveScopeControl<T>;
|
|
100
|
-
static classScopeFor<T extends ScopeContext>(context: T): ReactiveScopeControl<T>;
|
|
101
|
-
static moduleScopeFor<T extends ScopeContext>(context: T): ReactiveScopeControl<T>;
|
|
102
|
-
static globalScopeFor<T extends ScopeContext>(context: T): ReactiveScopeControl<T>;
|
|
103
|
-
static blockScope<T extends ScopeContext>(): ReactiveScopeControl<T>;
|
|
104
|
-
static functionScope<T extends ScopeContext>(): ReactiveScopeControl<T>;
|
|
105
|
-
static classScope<T extends ScopeContext>(): ReactiveScopeControl<T>;
|
|
106
|
-
static moduleScope<T extends ScopeContext>(): ReactiveScopeControl<T>;
|
|
107
|
-
static globalScope<T extends ScopeContext>(): ReactiveScopeControl<T>;
|
|
74
|
+
static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): ReactiveScopeControl<T>;
|
|
75
|
+
static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): ReactiveScopeControl<T>;
|
|
108
76
|
protected attached: boolean;
|
|
109
77
|
protected marked: ScopeContext;
|
|
110
78
|
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
79
|
+
isAttached(): boolean;
|
|
111
80
|
detach(): void;
|
|
112
81
|
reattach(): void;
|
|
113
82
|
emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
|
|
83
|
+
getClass(): TypeOf<ReactiveScopeControl<ScopeContext>>;
|
|
114
84
|
}
|
|
85
|
+
interface ImportMeta {
|
|
86
|
+
url: URL;
|
|
87
|
+
resolve?(specified: string, parent?: string | URL): Promise<string>;
|
|
88
|
+
}
|
|
89
|
+
export interface ModuleImport {
|
|
90
|
+
meta: ImportMeta;
|
|
91
|
+
}
|
|
92
|
+
export interface ModuleContext extends ScopeContext {
|
|
93
|
+
import: ModuleImport & ((path: string) => Promise<any>);
|
|
94
|
+
}
|
|
95
|
+
export declare class ModuleScope extends ReactiveScope<ModuleContext> {
|
|
96
|
+
constructor(context: ModuleContext, propertyKeys?: (keyof ModuleContext)[]);
|
|
97
|
+
importModule(propertyKey: keyof ModuleContext, scope: ModuleScope): void;
|
|
98
|
+
}
|
|
99
|
+
export declare class WebModuleScope extends ModuleScope {
|
|
100
|
+
constructor();
|
|
101
|
+
updateContext(context: any): void;
|
|
102
|
+
}
|
|
103
|
+
export {};
|
package/scope/scope.js
CHANGED
|
@@ -1,41 +1,19 @@
|
|
|
1
1
|
export class Scope {
|
|
2
|
-
constructor(context,
|
|
2
|
+
constructor(context, propertyKeys) {
|
|
3
3
|
this.context = context;
|
|
4
|
-
this.type = type;
|
|
5
4
|
this.scopeMap = new Map();
|
|
5
|
+
this.propertyKeys = propertyKeys;
|
|
6
|
+
if (Array.isArray(this.propertyKeys)) {
|
|
7
|
+
this.has = (propertyKey) => {
|
|
8
|
+
return this.propertyKeys.includes(propertyKey);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
}
|
|
7
|
-
static for(context,
|
|
8
|
-
return new Scope(context,
|
|
9
|
-
}
|
|
10
|
-
static blockScopeFor(context) {
|
|
11
|
-
return new Scope(context, 'block');
|
|
12
|
-
}
|
|
13
|
-
static functionScopeFor(context) {
|
|
14
|
-
return new Scope(context, 'function');
|
|
15
|
-
}
|
|
16
|
-
static classScopeFor(context) {
|
|
17
|
-
return new Scope(context, 'class');
|
|
18
|
-
}
|
|
19
|
-
static moduleScopeFor(context) {
|
|
20
|
-
return new Scope(context, 'module');
|
|
21
|
-
}
|
|
22
|
-
static globalScopeFor(context) {
|
|
23
|
-
return new Scope(context, 'global');
|
|
24
|
-
}
|
|
25
|
-
static blockScope() {
|
|
26
|
-
return new Scope({}, 'block');
|
|
27
|
-
}
|
|
28
|
-
static functionScope() {
|
|
29
|
-
return new Scope({}, 'function');
|
|
30
|
-
}
|
|
31
|
-
static classScope() {
|
|
32
|
-
return new Scope({}, 'class');
|
|
33
|
-
}
|
|
34
|
-
static moduleScope() {
|
|
35
|
-
return new Scope({}, 'module');
|
|
12
|
+
static for(context, propertyKeys) {
|
|
13
|
+
return new Scope(context, propertyKeys);
|
|
36
14
|
}
|
|
37
|
-
static
|
|
38
|
-
return new Scope({},
|
|
15
|
+
static blockScope(propertyKeys) {
|
|
16
|
+
return new Scope({}, propertyKeys);
|
|
39
17
|
}
|
|
40
18
|
get(propertyKey) {
|
|
41
19
|
return Reflect.get(this.context, propertyKey);
|
|
@@ -62,7 +40,7 @@ export class Scope {
|
|
|
62
40
|
if (typeof scopeContext !== 'object') {
|
|
63
41
|
return;
|
|
64
42
|
}
|
|
65
|
-
scope = new
|
|
43
|
+
scope = new (this.getClass())(scopeContext);
|
|
66
44
|
this.scopeMap.set(propertyKey, scope);
|
|
67
45
|
return scope;
|
|
68
46
|
}
|
|
@@ -73,44 +51,20 @@ export class Scope {
|
|
|
73
51
|
scope.context = scopeContext;
|
|
74
52
|
return scope;
|
|
75
53
|
}
|
|
76
|
-
scope = new
|
|
54
|
+
scope = new (this.getClass())(scopeContext);
|
|
77
55
|
this.scopeMap.set(propertyKey, scope);
|
|
78
56
|
return scope;
|
|
79
57
|
}
|
|
58
|
+
getClass() {
|
|
59
|
+
return Scope;
|
|
60
|
+
}
|
|
80
61
|
}
|
|
81
62
|
export class ReadOnlyScope extends Scope {
|
|
82
|
-
static for(context,
|
|
83
|
-
return new ReadOnlyScope(context,
|
|
84
|
-
}
|
|
85
|
-
static blockScopeFor(context) {
|
|
86
|
-
return new ReadOnlyScope(context, 'block');
|
|
87
|
-
}
|
|
88
|
-
static functionScopeFor(context) {
|
|
89
|
-
return new ReadOnlyScope(context, 'function');
|
|
90
|
-
}
|
|
91
|
-
static classScopeFor(context) {
|
|
92
|
-
return new ReadOnlyScope(context, 'class');
|
|
63
|
+
static for(context, propertyKeys) {
|
|
64
|
+
return new ReadOnlyScope(context, propertyKeys);
|
|
93
65
|
}
|
|
94
|
-
static
|
|
95
|
-
return new ReadOnlyScope(
|
|
96
|
-
}
|
|
97
|
-
static globalScopeFor(context) {
|
|
98
|
-
return new ReadOnlyScope(context, 'global');
|
|
99
|
-
}
|
|
100
|
-
static blockScope() {
|
|
101
|
-
return new ReadOnlyScope({}, 'block');
|
|
102
|
-
}
|
|
103
|
-
static functionScope() {
|
|
104
|
-
return new ReadOnlyScope({}, 'function');
|
|
105
|
-
}
|
|
106
|
-
static classScope() {
|
|
107
|
-
return new ReadOnlyScope({}, 'class');
|
|
108
|
-
}
|
|
109
|
-
static moduleScope() {
|
|
110
|
-
return new ReadOnlyScope({}, 'module');
|
|
111
|
-
}
|
|
112
|
-
static globalScope() {
|
|
113
|
-
return new ReadOnlyScope({}, 'global');
|
|
66
|
+
static blockScope(propertyKeys) {
|
|
67
|
+
return new ReadOnlyScope({}, propertyKeys);
|
|
114
68
|
}
|
|
115
69
|
set(propertyKey, value, receiver) {
|
|
116
70
|
return false;
|
|
@@ -118,6 +72,9 @@ export class ReadOnlyScope extends Scope {
|
|
|
118
72
|
delete(propertyKey) {
|
|
119
73
|
return false;
|
|
120
74
|
}
|
|
75
|
+
getClass() {
|
|
76
|
+
return ReadOnlyScope;
|
|
77
|
+
}
|
|
121
78
|
}
|
|
122
79
|
export class ScopeSubscription {
|
|
123
80
|
constructor(propertyKey, observer) {
|
|
@@ -144,7 +101,7 @@ export class ValueChangeObserver {
|
|
|
144
101
|
return;
|
|
145
102
|
}
|
|
146
103
|
const subscribers = this.subscribers.get(propertyKey);
|
|
147
|
-
if (!subscribers) {
|
|
104
|
+
if (!subscribers || subscribers.size == 0) {
|
|
148
105
|
return;
|
|
149
106
|
}
|
|
150
107
|
this.propertiesLock.push(propertyKey);
|
|
@@ -195,44 +152,22 @@ export class ValueChangeObserver {
|
|
|
195
152
|
}
|
|
196
153
|
}
|
|
197
154
|
export class ReactiveScope extends Scope {
|
|
198
|
-
constructor(context,
|
|
199
|
-
super(context,
|
|
200
|
-
this.name = name;
|
|
155
|
+
constructor(context, name, parent, propertyKeys) {
|
|
156
|
+
super(context, Array.isArray(name) ? name : propertyKeys);
|
|
201
157
|
this.parent = parent;
|
|
202
158
|
this.observer = new ValueChangeObserver();
|
|
159
|
+
if (typeof name == 'string') {
|
|
160
|
+
this.name = name;
|
|
161
|
+
}
|
|
162
|
+
if (Array.isArray(name)) {
|
|
163
|
+
this.propertyKeys = name;
|
|
164
|
+
}
|
|
203
165
|
}
|
|
204
|
-
static for(context,
|
|
205
|
-
return new ReactiveScope(context,
|
|
206
|
-
}
|
|
207
|
-
static blockScopeFor(context) {
|
|
208
|
-
return new ReactiveScope(context, 'block');
|
|
209
|
-
}
|
|
210
|
-
static functionScopeFor(context) {
|
|
211
|
-
return new ReactiveScope(context, 'function');
|
|
212
|
-
}
|
|
213
|
-
static classScopeFor(context) {
|
|
214
|
-
return new ReactiveScope(context, 'class');
|
|
215
|
-
}
|
|
216
|
-
static moduleScopeFor(context) {
|
|
217
|
-
return new ReactiveScope(context, 'module');
|
|
218
|
-
}
|
|
219
|
-
static globalScopeFor(context) {
|
|
220
|
-
return new ReactiveScope(context, 'global');
|
|
221
|
-
}
|
|
222
|
-
static blockScope() {
|
|
223
|
-
return new ReactiveScope({}, 'block');
|
|
224
|
-
}
|
|
225
|
-
static functionScope() {
|
|
226
|
-
return new ReactiveScope({}, 'function');
|
|
227
|
-
}
|
|
228
|
-
static classScope() {
|
|
229
|
-
return new ReactiveScope({}, 'class');
|
|
230
|
-
}
|
|
231
|
-
static moduleScope() {
|
|
232
|
-
return new ReactiveScope({}, 'module');
|
|
166
|
+
static for(context, propertyKeys) {
|
|
167
|
+
return new ReactiveScope(context, propertyKeys);
|
|
233
168
|
}
|
|
234
|
-
static
|
|
235
|
-
return new ReactiveScope({},
|
|
169
|
+
static blockScope(propertyKeys) {
|
|
170
|
+
return new ReactiveScope({}, propertyKeys);
|
|
236
171
|
}
|
|
237
172
|
set(propertyKey, newValue, receiver) {
|
|
238
173
|
const oldValue = Reflect.get(this.context, propertyKey);
|
|
@@ -260,7 +195,7 @@ export class ReactiveScope extends Scope {
|
|
|
260
195
|
if (typeof scopeContext !== 'object') {
|
|
261
196
|
return;
|
|
262
197
|
}
|
|
263
|
-
scope = new ReactiveScope(scopeContext,
|
|
198
|
+
scope = new ReactiveScope(scopeContext, propertyKey, this);
|
|
264
199
|
this.scopeMap.set(propertyKey, scope);
|
|
265
200
|
return scope;
|
|
266
201
|
}
|
|
@@ -271,7 +206,7 @@ export class ReactiveScope extends Scope {
|
|
|
271
206
|
scope.context = scopeContext;
|
|
272
207
|
return scope;
|
|
273
208
|
}
|
|
274
|
-
scope = new ReactiveScope(scopeContext,
|
|
209
|
+
scope = new ReactiveScope(scopeContext, propertyKey, this);
|
|
275
210
|
this.scopeMap.set(propertyKey, scope);
|
|
276
211
|
return scope;
|
|
277
212
|
}
|
|
@@ -293,6 +228,9 @@ export class ReactiveScope extends Scope {
|
|
|
293
228
|
this.observer.destroy();
|
|
294
229
|
}
|
|
295
230
|
}
|
|
231
|
+
getClass() {
|
|
232
|
+
return ReactiveScope;
|
|
233
|
+
}
|
|
296
234
|
}
|
|
297
235
|
export class ReactiveScopeControl extends ReactiveScope {
|
|
298
236
|
constructor() {
|
|
@@ -300,38 +238,11 @@ export class ReactiveScopeControl extends ReactiveScope {
|
|
|
300
238
|
this.attached = true;
|
|
301
239
|
this.marked = {};
|
|
302
240
|
}
|
|
303
|
-
static for(context,
|
|
304
|
-
return new ReactiveScopeControl(context,
|
|
305
|
-
}
|
|
306
|
-
static blockScopeFor(context) {
|
|
307
|
-
return new ReactiveScopeControl(context, 'block');
|
|
308
|
-
}
|
|
309
|
-
static functionScopeFor(context) {
|
|
310
|
-
return new ReactiveScopeControl(context, 'function');
|
|
311
|
-
}
|
|
312
|
-
static classScopeFor(context) {
|
|
313
|
-
return new ReactiveScopeControl(context, 'class');
|
|
314
|
-
}
|
|
315
|
-
static moduleScopeFor(context) {
|
|
316
|
-
return new ReactiveScopeControl(context, 'module');
|
|
317
|
-
}
|
|
318
|
-
static globalScopeFor(context) {
|
|
319
|
-
return new ReactiveScopeControl(context, 'global');
|
|
320
|
-
}
|
|
321
|
-
static blockScope() {
|
|
322
|
-
return new ReactiveScopeControl({}, 'block');
|
|
323
|
-
}
|
|
324
|
-
static functionScope() {
|
|
325
|
-
return new ReactiveScopeControl({}, 'function');
|
|
241
|
+
static for(context, propertyKeys) {
|
|
242
|
+
return new ReactiveScopeControl(context, propertyKeys);
|
|
326
243
|
}
|
|
327
|
-
static
|
|
328
|
-
return new ReactiveScopeControl({},
|
|
329
|
-
}
|
|
330
|
-
static moduleScope() {
|
|
331
|
-
return new ReactiveScopeControl({}, 'module');
|
|
332
|
-
}
|
|
333
|
-
static globalScope() {
|
|
334
|
-
return new ReactiveScopeControl({}, 'global');
|
|
244
|
+
static blockScope(propertyKeys) {
|
|
245
|
+
return new ReactiveScopeControl({}, propertyKeys);
|
|
335
246
|
}
|
|
336
247
|
emit(propertyKey, newValue, oldValue) {
|
|
337
248
|
if (this.attached) {
|
|
@@ -341,6 +252,9 @@ export class ReactiveScopeControl extends ReactiveScope {
|
|
|
341
252
|
this.marked[propertyKey] = newValue;
|
|
342
253
|
}
|
|
343
254
|
}
|
|
255
|
+
isAttached() {
|
|
256
|
+
return this.attached;
|
|
257
|
+
}
|
|
344
258
|
detach() {
|
|
345
259
|
this.attached = false;
|
|
346
260
|
}
|
|
@@ -360,5 +274,24 @@ export class ReactiveScopeControl extends ReactiveScope {
|
|
|
360
274
|
super.emit(propertyKey, latestChanges[propertyKey]);
|
|
361
275
|
});
|
|
362
276
|
}
|
|
277
|
+
getClass() {
|
|
278
|
+
return ReactiveScopeControl;
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
export class ModuleScope extends ReactiveScope {
|
|
282
|
+
constructor(context, propertyKeys) {
|
|
283
|
+
super(context, propertyKeys);
|
|
284
|
+
}
|
|
285
|
+
importModule(propertyKey, scope) {
|
|
286
|
+
this.scopeMap.set(propertyKey, scope);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
export class WebModuleScope extends ModuleScope {
|
|
290
|
+
constructor() {
|
|
291
|
+
super({});
|
|
292
|
+
}
|
|
293
|
+
updateContext(context) {
|
|
294
|
+
this.context = context;
|
|
295
|
+
}
|
|
363
296
|
}
|
|
364
297
|
//# sourceMappingURL=scope.js.map
|