@ibyar/expressions 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -0
- package/api/statement/declarations/declares.d.ts +1 -0
- package/api/statement/declarations/declares.js +3 -0
- package/api/statement/declarations/declares.js.map +1 -1
- package/package.json +2 -2
- package/scope/scope.d.ts +28 -0
- package/scope/scope.js +90 -3
- package/scope/scope.js.map +1 -1
package/README.md
CHANGED
|
@@ -179,3 +179,98 @@ b |> function(x) { console.log(x); return x; }
|
|
|
179
179
|
|> add : ? : 77
|
|
180
180
|
|> map
|
|
181
181
|
```
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
### How to use stack and scope:
|
|
185
|
+
|
|
186
|
+
1- create stack:
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
import { Scope, Stack } from '@ibyar/expressions';
|
|
190
|
+
|
|
191
|
+
const stack1 = new Stack();
|
|
192
|
+
|
|
193
|
+
// OR
|
|
194
|
+
|
|
195
|
+
const scope1 = new Scope<{x: number, y: number}>( {x: 8, y: 6}, 'block');
|
|
196
|
+
const scope2 = Scope.blockScopeFor({z: 9});
|
|
197
|
+
|
|
198
|
+
const stack2 = new Stack([scope1, scope2]);
|
|
199
|
+
|
|
200
|
+
```
|
|
201
|
+
|
|
202
|
+
2- any of the previous stacks, does not provide and public api like `Math`, `String`, ....
|
|
203
|
+
you need to provide these values to the stack, the stack work as a sandbox, isolated from the js-VM.
|
|
204
|
+
|
|
205
|
+
```ts
|
|
206
|
+
import { ReadOnlyScope } from '@ibyar/expressions';
|
|
207
|
+
|
|
208
|
+
stack1.pushScope(ReadOnlyScope.blockScopeFor({
|
|
209
|
+
Math: {
|
|
210
|
+
E: Math.E,
|
|
211
|
+
LN10: Math.LN10,
|
|
212
|
+
LN2: Math.LN2,
|
|
213
|
+
LOG10E: Math.LOG10E,
|
|
214
|
+
LOG2E: Math.LOG2E,
|
|
215
|
+
PI: Math.PI,
|
|
216
|
+
SQRT1_2: Math.SQRT1_2,
|
|
217
|
+
SQRT2: Math.SQRT2,
|
|
218
|
+
|
|
219
|
+
abs: Math.abs,
|
|
220
|
+
acos: Math.acos,
|
|
221
|
+
asin: Math.asin,
|
|
222
|
+
atan: Math.atan,
|
|
223
|
+
atan2: Math.atan2,
|
|
224
|
+
ceil: Math.ceil,
|
|
225
|
+
....
|
|
226
|
+
},
|
|
227
|
+
// or
|
|
228
|
+
Math,
|
|
229
|
+
// another object
|
|
230
|
+
Array: {
|
|
231
|
+
// in js a statement like `let x = new Array()` will throw exception.
|
|
232
|
+
isArray: Array.isArray,
|
|
233
|
+
},
|
|
234
|
+
|
|
235
|
+
Array, // `let x = new Array()` no Error.
|
|
236
|
+
|
|
237
|
+
|
|
238
|
+
parseFloat,
|
|
239
|
+
parseInt,
|
|
240
|
+
String,
|
|
241
|
+
console,
|
|
242
|
+
}));
|
|
243
|
+
```
|
|
244
|
+
so now you can write js code the use these as identifier
|
|
245
|
+
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
3- the stack is ready to use with expression
|
|
249
|
+
4- try to parse an expression like `let x = 'data'; console.log(x);`.
|
|
250
|
+
|
|
251
|
+
```ts
|
|
252
|
+
import { JavaScriptParser } from '@ibyar/expressions';
|
|
253
|
+
|
|
254
|
+
const ast = JavaScriptParser.parse(`let x = 'data'; console.log(x);`);
|
|
255
|
+
|
|
256
|
+
// use get method to execute an expression and return a value if available.
|
|
257
|
+
|
|
258
|
+
ast.get(stack1);
|
|
259
|
+
// it should print 'data' on the console
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
5- you can visit the ast
|
|
264
|
+
|
|
265
|
+
```ts
|
|
266
|
+
import { expressionVisitor, VariableDeclaration } from '@ibyar/expressions';
|
|
267
|
+
|
|
268
|
+
expressionVisitor.visit(ast, (expression, type, control) => {
|
|
269
|
+
if (type === 'VariableDeclaration') {
|
|
270
|
+
const kind = (expression as VariableDeclaration).getKind();
|
|
271
|
+
|
|
272
|
+
....
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
|
|
276
|
+
```
|
|
@@ -30,6 +30,7 @@ export declare class VariableDeclarationNode extends AbstractExpressionNode impl
|
|
|
30
30
|
static visit(node: VariableDeclarationNode, visitNode: VisitNodeType, visitNodeList: VisitNodeListType): void;
|
|
31
31
|
constructor(declarations: VariableNode[], kind: 'var' | 'let' | 'const');
|
|
32
32
|
getDeclarations(): VariableNode[];
|
|
33
|
+
getKind(): "var" | "let" | "const";
|
|
33
34
|
shareVariables(scopeList: Scope<any>[]): void;
|
|
34
35
|
set(stack: Stack, value: any): void;
|
|
35
36
|
get(stack: Stack): void;
|
|
@@ -83,6 +83,9 @@ let VariableDeclarationNode = VariableDeclarationNode_1 = class VariableDeclarat
|
|
|
83
83
|
getDeclarations() {
|
|
84
84
|
return this.declarations;
|
|
85
85
|
}
|
|
86
|
+
getKind() {
|
|
87
|
+
return this.kind;
|
|
88
|
+
}
|
|
86
89
|
shareVariables(scopeList) {
|
|
87
90
|
this.declarations.forEach(declaration => declaration.shareVariables(scopeList));
|
|
88
91
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"declares.js","sourceRoot":"","sources":["../../../../../src/expressions/api/statement/declarations/declares.ts"],"names":[],"mappings":";;AAQA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGhE,IAAa,YAAY,oBAAzB,MAAa,YAAa,SAAQ,sBAAsB;IAWvD,YAAmB,EAAwB,EAAS,IAAqB;QACxE,KAAK,EAAE,CAAC;QADU,OAAE,GAAF,EAAE,CAAsB;QAAS,SAAI,GAAJ,IAAI,CAAiB;IAEzE,CAAC;IAZD,MAAM,CAAC,QAAQ,CAAC,IAAkB,EAAE,YAA8B;QACjE,OAAO,IAAI,cAAY,CACtB,YAAY,CAAC,IAAI,CAAC,EAAE,CA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eAAe,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC;IAC/F,CAAC;IACD,QAAQ;QACP,OAAO,GAAG,IAAI,CAAC,IAAI,IAAI,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9E,CAAC;IACD,MAAM;QACL,OAAO;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACpD,CAAC;IACH,CAAC;CACD,CAAA;
|
|
1
|
+
{"version":3,"file":"declares.js","sourceRoot":"","sources":["../../../../../src/expressions/api/statement/declarations/declares.ts"],"names":[],"mappings":";;AAQA,OAAO,EAAE,sBAAsB,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,kCAAkC,CAAC;AAGhE,IAAa,YAAY,oBAAzB,MAAa,YAAa,SAAQ,sBAAsB;IAWvD,YAAmB,EAAwB,EAAS,IAAqB;QACxE,KAAK,EAAE,CAAC;QADU,OAAE,GAAF,EAAE,CAAsB;QAAS,SAAI,GAAJ,IAAI,CAAiB;IAEzE,CAAC;IAZD,MAAM,CAAC,QAAQ,CAAC,IAAkB,EAAE,YAA8B;QACjE,OAAO,IAAI,cAAY,CACtB,YAAY,CAAC,IAAI,CAAC,EAAE,CAAyB,EAC7C,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAC5C,CAAC;IACH,CAAC;IACD,MAAM,CAAC,KAAK,CAAC,IAAkB,EAAE,SAAwB,EAAE,aAAgC;QAC1F,SAAS,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QACnB,IA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CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC;IAC9E,CAAC;IACD,MAAM;QACL,OAAO;YACN,IAAI,EAAE,IAAI,CAAC,IAAI;YACf,YAAY,EAAE,IAAI,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;SACpD,CAAC;IACH,CAAC;CACD,CAAA;AAnDY,uBAAuB;IADnC,YAAY,CAAC,qBAAqB,CAAC;;GACvB,uBAAuB,CAmDnC;SAnDY,uBAAuB","sourcesContent":["\nimport type {\n\tNodeDeserializer, ExpressionNode, CanDeclareExpression,\n\tExpressionEventPath, VisitNodeType, VisitNodeListType\n} from '../../expression.js';\nimport type { Scope } from '../../../scope/scope.js';\nimport type { Stack } from '../../../scope/stack.js';\nimport type { ScopeType } from '../../../scope/scope.js';\nimport { AbstractExpressionNode, AwaitPromise } from '../../abstract.js';\nimport { Deserializer } from '../../deserialize/deserialize.js';\n\n@Deserializer('VariableDeclarator')\nexport class VariableNode extends AbstractExpressionNode implements CanDeclareExpression {\n\tstatic fromJSON(node: VariableNode, deserializer: NodeDeserializer): VariableNode {\n\t\treturn new VariableNode(\n\t\t\tdeserializer(node.id) as CanDeclareExpression,\n\t\t\tnode.init ? deserializer(node.init) : void 0\n\t\t);\n\t}\n\tstatic visit(node: VariableNode, visitNode: VisitNodeType, visitNodeList: VisitNodeListType): void {\n\t\tvisitNode(node.id);\n\t\tnode.init && visitNode(node.init);\n\t}\n\tconstructor(public id: CanDeclareExpression, public init?: ExpressionNode) {\n\t\tsuper();\n\t}\n\tgetId() {\n\t\treturn this.id;\n\t}\n\tgetInit() {\n\t\treturn this.init;\n\t}\n\tshareVariables(scopeList: Scope<any>[]): void {\n\t\tthis.init?.shareVariables(scopeList);\n\t}\n\tset(stack: Stack, value: any) {\n\t\tthrow new Error(`VariableNode#set() has no implementation.`);\n\t}\n\tget(stack: Stack) {\n\t\tthis.declareVariable(stack, 'block');\n\t}\n\tdeclareVariable(stack: Stack, scopeType: ScopeType, propertyValue?: any) {\n\t\tif (propertyValue !== undefined) {\n\t\t\tthis.id.declareVariable(stack, scopeType, propertyValue);\n\t\t\treturn;\n\t\t}\n\t\tconst value = this.init?.get(stack);\n\t\tif (value instanceof AwaitPromise) {\n\t\t\tvalue.node = this.id;\n\t\t\tvalue.declareVariable = true;\n\t\t\tvalue.scopeType = scopeType;\n\t\t\tvalue.node.declareVariable(stack, scopeType);\n\t\t\tstack.resolveAwait(value);\n\t\t} else {\n\t\t\tthis.id.declareVariable(stack, scopeType, value);\n\t\t}\n\t}\n\tdependency(computed?: true): ExpressionNode[] {\n\t\treturn this.init?.dependency() || [];\n\t}\n\tdependencyPath(computed?: true): ExpressionEventPath[] {\n\t\treturn this.init?.dependencyPath(computed) || [];\n\t}\n\ttoString() {\n\t\treturn `${this.id.toString()}${this.init ? ` = ${this.init.toString()}` : ''}`;\n\t}\n\ttoJson() {\n\t\treturn {\n\t\t\tid: this.id.toJSON(),\n\t\t\tinit: this.init?.toJSON()\n\t\t};\n\t}\n}\n\n@Deserializer('VariableDeclaration')\nexport class VariableDeclarationNode extends AbstractExpressionNode implements CanDeclareExpression {\n\tstatic fromJSON(node: VariableDeclarationNode, deserializer: NodeDeserializer): VariableDeclarationNode {\n\t\treturn new VariableDeclarationNode(\n\t\t\tnode.declarations.map(deserializer) as VariableNode[],\n\t\t\tnode.kind\n\t\t);\n\t}\n\tstatic visit(node: VariableDeclarationNode, visitNode: VisitNodeType, visitNodeList: VisitNodeListType): void {\n\t\tvisitNodeList(node.declarations);\n\t}\n\tconstructor(protected declarations: VariableNode[], protected kind: 'var' | 'let' | 'const') {\n\t\tsuper();\n\t}\n\tgetDeclarations() {\n\t\treturn this.declarations;\n\t}\n\tgetKind() {\n\t\treturn this.kind;\n\t}\n\tshareVariables(scopeList: Scope<any>[]): void {\n\t\tthis.declarations.forEach(declaration => declaration.shareVariables(scopeList));\n\t}\n\tset(stack: Stack, value: any) {\n\t\tif (Array.isArray(value)) {\n\t\t\tthrow new Error(`VariableDeclarationNode#set() has no implementation.`);\n\t\t}\n\t\tthis.declarations[0].id.set(stack, value);\n\t}\n\tget(stack: Stack) {\n\t\tfor (const item of this.declarations) {\n\t\t\titem.declareVariable(stack, this.kind === 'var' ? 'function' : 'block');\n\t\t}\n\t}\n\tdeclareVariable(stack: Stack, scopeType: ScopeType, propertyValue: any): any {\n\t\tthis.declarations[0].declareVariable(stack, scopeType, propertyValue);\n\t}\n\tdependency(computed?: true): ExpressionNode[] {\n\t\treturn this.declarations.flatMap(declareVariable => declareVariable.dependency(computed));\n\t}\n\tdependencyPath(computed?: true): ExpressionEventPath[] {\n\t\treturn this.declarations.flatMap(declareVariable => declareVariable.dependencyPath(computed));\n\t}\n\ttoString(): string {\n\t\treturn `${this.kind} ${this.declarations.map(v => v.toString()).join(', ')}`;\n\t}\n\ttoJson(): object {\n\t\treturn {\n\t\t\tkind: this.kind,\n\t\t\tdeclarations: this.declarations.map(v => v.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.
|
|
3
|
+
"version": "0.5.1",
|
|
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",
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"eval",
|
|
50
50
|
"evaluation"
|
|
51
51
|
],
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "5e5951cccc30d333c2629a95d0c8a0627129d43c"
|
|
53
53
|
}
|
package/scope/scope.d.ts
CHANGED
|
@@ -48,6 +48,8 @@ export declare class ScopeSubscription<T> {
|
|
|
48
48
|
private propertyKey;
|
|
49
49
|
private observer;
|
|
50
50
|
constructor(propertyKey: keyof T, observer: ValueChangeObserver<T>);
|
|
51
|
+
pause(): void;
|
|
52
|
+
resume(): void;
|
|
51
53
|
unsubscribe(): void;
|
|
52
54
|
}
|
|
53
55
|
export declare type ValueChangedCallback = (newValue: any, oldValue?: any) => void;
|
|
@@ -57,6 +59,8 @@ export declare class ValueChangeObserver<T> {
|
|
|
57
59
|
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
58
60
|
subscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T>;
|
|
59
61
|
unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>): void;
|
|
62
|
+
pause(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
|
|
63
|
+
resume(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
|
|
60
64
|
destroy(): void;
|
|
61
65
|
}
|
|
62
66
|
export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
|
|
@@ -84,3 +88,27 @@ export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
|
|
|
84
88
|
subscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T>;
|
|
85
89
|
unsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>): void;
|
|
86
90
|
}
|
|
91
|
+
export interface ScopeControl<T extends ScopeContext> {
|
|
92
|
+
detach(): void;
|
|
93
|
+
reattach(): void;
|
|
94
|
+
emitChanges(propertyKey?: keyof T): void;
|
|
95
|
+
}
|
|
96
|
+
export declare class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {
|
|
97
|
+
static for<T extends ScopeContext>(context: T, type: ScopeType): ReactiveScopeControl<T>;
|
|
98
|
+
static blockScopeFor<T extends ScopeContext>(context: T): ReactiveScopeControl<T>;
|
|
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>;
|
|
108
|
+
protected attached: boolean;
|
|
109
|
+
protected marked: ScopeContext;
|
|
110
|
+
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
111
|
+
detach(): void;
|
|
112
|
+
reattach(): void;
|
|
113
|
+
emitChanges(propertyKey?: keyof T): void;
|
|
114
|
+
}
|
package/scope/scope.js
CHANGED
|
@@ -124,6 +124,12 @@ export class ScopeSubscription {
|
|
|
124
124
|
this.propertyKey = propertyKey;
|
|
125
125
|
this.observer = observer;
|
|
126
126
|
}
|
|
127
|
+
pause() {
|
|
128
|
+
this.observer.pause(this.propertyKey, this);
|
|
129
|
+
}
|
|
130
|
+
resume() {
|
|
131
|
+
this.observer.resume(this.propertyKey, this);
|
|
132
|
+
}
|
|
127
133
|
unsubscribe() {
|
|
128
134
|
this.observer.unsubscribe(this.propertyKey, this);
|
|
129
135
|
}
|
|
@@ -142,9 +148,12 @@ export class ValueChangeObserver {
|
|
|
142
148
|
return;
|
|
143
149
|
}
|
|
144
150
|
this.propertiesLock.push(propertyKey);
|
|
145
|
-
subscribers?.forEach(
|
|
151
|
+
subscribers?.forEach(subscriptionInfo => {
|
|
152
|
+
if (!subscriptionInfo.enable) {
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
146
155
|
try {
|
|
147
|
-
|
|
156
|
+
subscriptionInfo.callback(newValue, oldValue);
|
|
148
157
|
}
|
|
149
158
|
catch (e) {
|
|
150
159
|
console.error(e);
|
|
@@ -162,7 +171,7 @@ export class ValueChangeObserver {
|
|
|
162
171
|
propertySubscribers = new Map();
|
|
163
172
|
this.subscribers.set(propertyKey, propertySubscribers);
|
|
164
173
|
}
|
|
165
|
-
propertySubscribers.set(subscription, callback);
|
|
174
|
+
propertySubscribers.set(subscription, { callback, enable: true });
|
|
166
175
|
return subscription;
|
|
167
176
|
}
|
|
168
177
|
unsubscribe(propertyKey, subscription) {
|
|
@@ -173,6 +182,14 @@ export class ValueChangeObserver {
|
|
|
173
182
|
this.subscribers.delete(propertyKey);
|
|
174
183
|
}
|
|
175
184
|
}
|
|
185
|
+
pause(propertyKey, subscription) {
|
|
186
|
+
const subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);
|
|
187
|
+
subscriptionInfo && (subscriptionInfo.enable = false);
|
|
188
|
+
}
|
|
189
|
+
resume(propertyKey, subscription) {
|
|
190
|
+
const subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);
|
|
191
|
+
subscriptionInfo && (subscriptionInfo.enable = true);
|
|
192
|
+
}
|
|
176
193
|
destroy() {
|
|
177
194
|
this.subscribers.clear();
|
|
178
195
|
}
|
|
@@ -277,4 +294,74 @@ export class ReactiveScope extends Scope {
|
|
|
277
294
|
}
|
|
278
295
|
}
|
|
279
296
|
}
|
|
297
|
+
export class ReactiveScopeControl extends ReactiveScope {
|
|
298
|
+
constructor() {
|
|
299
|
+
super(...arguments);
|
|
300
|
+
this.attached = true;
|
|
301
|
+
this.marked = {};
|
|
302
|
+
}
|
|
303
|
+
static for(context, type) {
|
|
304
|
+
return new ReactiveScopeControl(context, type);
|
|
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');
|
|
326
|
+
}
|
|
327
|
+
static classScope() {
|
|
328
|
+
return new ReactiveScopeControl({}, 'class');
|
|
329
|
+
}
|
|
330
|
+
static moduleScope() {
|
|
331
|
+
return new ReactiveScopeControl({}, 'module');
|
|
332
|
+
}
|
|
333
|
+
static globalScope() {
|
|
334
|
+
return new ReactiveScopeControl({}, 'global');
|
|
335
|
+
}
|
|
336
|
+
emit(propertyKey, newValue, oldValue) {
|
|
337
|
+
if (this.attached) {
|
|
338
|
+
super.emit(propertyKey, newValue, oldValue);
|
|
339
|
+
}
|
|
340
|
+
else {
|
|
341
|
+
this.marked[propertyKey] = newValue;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
detach() {
|
|
345
|
+
this.attached = false;
|
|
346
|
+
}
|
|
347
|
+
reattach() {
|
|
348
|
+
this.attached = true;
|
|
349
|
+
this.emitChanges();
|
|
350
|
+
}
|
|
351
|
+
emitChanges(propertyKey) {
|
|
352
|
+
if (propertyKey) {
|
|
353
|
+
if (propertyKey in this.marked) {
|
|
354
|
+
const lastValue = this.marked[propertyKey];
|
|
355
|
+
Reflect.deleteProperty(this.marked, propertyKey);
|
|
356
|
+
super.emit(propertyKey, lastValue);
|
|
357
|
+
}
|
|
358
|
+
return;
|
|
359
|
+
}
|
|
360
|
+
const oldChanges = this.marked;
|
|
361
|
+
this.marked = {};
|
|
362
|
+
Object.keys(oldChanges).forEach(propertyKey => {
|
|
363
|
+
super.emit(propertyKey, oldChanges[propertyKey]);
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
}
|
|
280
367
|
//# sourceMappingURL=scope.js.map
|
package/scope/scope.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AA2DA,MAAM,OAAO,KAAK;IAmCjB,YAAsB,OAAU,EAAS,IAAe;QAAlC,YAAO,GAAP,OAAO,CAAG;QAAS,SAAI,GAAJ,IAAI,CAAW;QAD9C,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IACQ,CAAC;IAlC7D,MAAM,CAAC,GAAG,CAAyB,OAAU,EAAE,IAAe;QAC7D,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,MAAM,CAAC,aAAa,CAAyB,OAAU;QACtD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,CAAC,gBAAgB,CAAyB,OAAU;QACzD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IACD,MAAM,CAAC,aAAa,CAAyB,OAAU;QACtD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,CAAC,cAAc,CAAyB,OAAU;QACvD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,cAAc,CAAyB,OAAU;QACvD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;IACrC,CAAC;IACD,MAAM,CAAC,UAAU;QAChB,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE,OAAO,CAAC,CAAC;IACpC,CAAC;IACD,MAAM,CAAC,aAAa;QACnB,OAAO,IAAI,KAAK,CAAC,EAAO,EAAE,UAAU,CAAC,CAAC;IACvC,CAAC;IACD,MAAM,CAAC,UAAU;QACh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;aAAM,IAAI,WAAW,EAAE;YAEvB,IAAI,CAAC,QAAQ,CAAC,WAAW,CAAC,WAAW,CAAC,CAAC;SACvC;aAAM;YACN,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;SACxB;IACF,CAAC;CACD","sourcesContent":["\nexport type ScopeType = 'block' | 'function' | 'class' | 'module' | 'global';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\n\n\t/**\n\t * scope type\n\t */\n\ttype: ScopeType;\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 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\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new Scope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'global');\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tconstructor(protected context: T, public type: ScopeType) { }\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 Scope(scopeContext, 'block');\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 Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\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, type: ScopeType) {\n\t\treturn new ReadOnlyScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'global');\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}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<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\nexport class ValueChangeObserver<T> {\n\tprivate subscribers: Map<keyof T, Map<ScopeSubscription<T>, ValueChangedCallback>> = 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) {\n\t\t\treturn;\n\t\t}\n\t\tthis.propertiesLock.push(propertyKey);\n\t\tsubscribers?.forEach((subscribe) => {\n\t\t\ttry {\n\t\t\t\tsubscribe(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);\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\t/**\n\t * clear subscription map\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, type: ScopeType) {\n\t\treturn new ReactiveScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'global');\n\t}\n\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\n\tconstructor(context: T, type: ScopeType);\n\tconstructor(context: T, type: ScopeType, name: string, parent: ReactiveScope<any>);\n\tconstructor(context: T, type: ScopeType, protected name?: string, protected parent?: ReactiveScope<any>) {\n\t\tsuper(context, type);\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, 'block', 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, 'block', propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\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\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\treturn this.observer.subscribe(propertyKey, callback);\n\t}\n\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\n\t\t\tthis.observer.unsubscribe(propertyKey);\n\t\t} else {\n\t\t\tthis.observer.destroy();\n\t\t}\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/sc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AI,CAAC,QAAQ,GAAG,IAAI,CAAC;QACrB,IAAI,CAAC,WAAW,EAAE,CAAC;IACpB,CAAC;IACD,WAAW,CAAC,WAAqB;QAChC,IAAI,WAAW,EAAE;YAChB,IAAI,WAAW,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC/B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;gBAC3C,OAAO,CAAC,cAAc,CAAC,IAAI,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;gBACjD,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;aACnC;YACD,OAAO;SACP;QACD,MAAM,UAAU,GAAG,IAAI,CAAC,MAAM,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAC7C,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["\nexport type ScopeType = 'block' | 'function' | 'class' | 'module' | 'global';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\n\n\t/**\n\t * scope type\n\t */\n\ttype: ScopeType;\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 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\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new Scope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'global');\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tconstructor(protected context: T, public type: ScopeType) { }\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 Scope(scopeContext, 'block');\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 Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\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, type: ScopeType) {\n\t\treturn new ReadOnlyScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'global');\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}\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) {\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, type: ScopeType) {\n\t\treturn new ReactiveScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'global');\n\t}\n\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\n\tconstructor(context: T, type: ScopeType);\n\tconstructor(context: T, type: ScopeType, name: string, parent: ReactiveScope<any>);\n\tconstructor(context: T, type: ScopeType, protected name?: string, protected parent?: ReactiveScope<any>) {\n\t\tsuper(context, type);\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, 'block', 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, 'block', 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}\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 * 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): void;\n}\n\nexport class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReactiveScopeControl(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'global');\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\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): void {\n\t\tif (propertyKey) {\n\t\t\tif (propertyKey in this.marked) {\n\t\t\t\tconst lastValue = this.marked[propertyKey];\n\t\t\t\tReflect.deleteProperty(this.marked, propertyKey);\n\t\t\t\tsuper.emit(propertyKey, lastValue);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst oldChanges = this.marked;\n\t\tthis.marked = {};\n\t\tObject.keys(oldChanges).forEach(propertyKey => {\n\t\t\tsuper.emit(propertyKey, oldChanges[propertyKey]);\n\t\t});\n\t}\n}\n"]}
|