@ibyar/expressions 0.5.1 → 0.5.6
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/LICENSE +1 -1
- package/README.md +5 -4
- package/api/abstract.d.ts +5 -6
- package/api/abstract.js +3 -3
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +202 -0
- package/api/class/class.js +635 -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/debugger.d.ts +15 -0
- package/api/computing/debugger.js +35 -0
- package/api/computing/debugger.js.map +1 -0
- 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 +6 -6
- 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 +12 -12
- package/api/definition/array.js +31 -25
- 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 +40 -51
- package/api/definition/function.js +291 -309
- 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 +15 -12
- package/api/definition/object.js +43 -13
- package/api/definition/object.js.map +1 -1
- package/api/definition/statement.d.ts +2 -2
- package/api/definition/statement.js +7 -3
- package/api/definition/statement.js.map +1 -1
- package/api/definition/values.d.ts +35 -50
- package/api/definition/values.js +66 -149
- package/api/definition/values.js.map +1 -1
- package/api/deserialize/deserialize.d.ts +2 -1
- package/api/deserialize/deserialize.js +4 -1
- package/api/deserialize/deserialize.js.map +1 -1
- package/api/deserialize/type-store.d.ts +2 -2
- package/api/deserialize/type-store.js.map +1 -1
- package/api/expression.d.ts +13 -18
- package/api/expression.js.map +1 -1
- package/api/index.d.ts +2 -0
- package/api/index.js +2 -0
- package/api/index.js.map +1 -1
- package/api/module/common.d.ts +29 -0
- package/api/module/common.js +71 -0
- package/api/module/common.js.map +1 -0
- package/api/module/export.d.ts +66 -25
- package/api/module/export.js +270 -58
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +61 -25
- package/api/module/import.js +226 -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/{app/program.d.ts → program.d.ts} +8 -9
- package/api/program.js +45 -0
- package/api/program.js.map +1 -0
- package/api/statement/control/block.d.ts +4 -5
- package/api/statement/control/block.js +22 -23
- 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 +13 -9
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +38 -13
- package/api/statement/control/terminate.js +81 -20
- package/api/statement/control/terminate.js.map +1 -1
- package/api/statement/declarations/declares.d.ts +17 -16
- package/api/statement/declarations/declares.js +24 -19
- package/api/statement/declarations/declares.js.map +1 -1
- package/api/statement/iterations/for.d.ts +5 -5
- package/api/statement/iterations/for.js +29 -23
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +3 -3
- package/api/statement/iterations/while.js +17 -13
- package/api/statement/iterations/while.js.map +1 -1
- package/api/utils.d.ts +5 -0
- package/api/utils.js +4 -0
- package/api/utils.js.map +1 -0
- package/package.json +5 -5
- package/scope/event.d.ts +2 -2
- package/scope/event.js +8 -14
- package/scope/event.js.map +1 -1
- 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 -3
- package/scope/proxy.js +22 -26
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +42 -53
- package/scope/scope.js +73 -143
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +43 -26
- package/scope/stack.js +148 -102
- package/scope/stack.js.map +1 -1
- package/v8/enums.d.ts +204 -0
- package/v8/enums.js +375 -0
- package/v8/enums.js.map +1 -0
- package/v8/index.d.ts +2 -1
- package/v8/index.js +2 -1
- package/v8/index.js.map +1 -1
- package/v8/inline.d.ts +177 -0
- package/v8/inline.js +1973 -0
- package/v8/inline.js.map +1 -0
- package/v8/nodes.d.ts +8 -7
- package/v8/nodes.js +37 -63
- package/v8/nodes.js.map +1 -1
- package/v8/parser.d.ts +41 -151
- package/v8/parser.js +507 -1578
- package/v8/parser.js.map +1 -1
- package/v8/stream.d.ts +35 -3
- package/v8/stream.js +616 -164
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +15 -9
- package/v8/token.js +79 -46
- package/v8/token.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
- package/v8/app.d.ts +0 -0
- package/v8/app.js +0 -2
- package/v8/app.js.map +0 -1
package/scope/event.js
CHANGED
|
@@ -1,41 +1,35 @@
|
|
|
1
1
|
import { ReactiveScope } from './scope.js';
|
|
2
|
-
function visitInnerScope(eventNames, events, scope,
|
|
2
|
+
function visitInnerScope(eventNames, events, scope, scopeTuples) {
|
|
3
3
|
eventNames.forEach(eventName => {
|
|
4
4
|
if (eventName.startsWith(':')) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
|
-
|
|
7
|
+
scopeTuples.push([eventName, scope]);
|
|
8
8
|
const nextEvents = Object.keys(events[eventName]);
|
|
9
9
|
if (!nextEvents.length) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
12
|
const innerScope = scope.getScopeOrCreat(eventName);
|
|
13
|
-
visitInnerScope(nextEvents, events[eventName], innerScope,
|
|
13
|
+
visitInnerScope(nextEvents, events[eventName], innerScope, scopeTuples);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
16
16
|
export function findScopeByEventMap(events, stack) {
|
|
17
|
-
const
|
|
17
|
+
const scopeTuples = [];
|
|
18
18
|
const rootEventNames = Object.keys(events);
|
|
19
19
|
rootEventNames.forEach(eventName => {
|
|
20
20
|
const scope = stack.findScope(eventName);
|
|
21
|
-
|
|
21
|
+
scopeTuples.push([eventName, scope]);
|
|
22
22
|
const nextEvents = Object.keys(events[eventName]);
|
|
23
23
|
if (!nextEvents.length) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
26
|
const eventScope = scope.getScopeOrCreat(eventName);
|
|
27
|
-
visitInnerScope(nextEvents, events[eventName], eventScope,
|
|
27
|
+
visitInnerScope(nextEvents, events[eventName], eventScope, scopeTuples);
|
|
28
28
|
});
|
|
29
|
-
return
|
|
29
|
+
return scopeTuples;
|
|
30
30
|
}
|
|
31
31
|
export function findReactiveScopeByEventMap(events, stack) {
|
|
32
32
|
const allScopes = findScopeByEventMap(events, stack);
|
|
33
|
-
|
|
34
|
-
allScopes.forEach((scope, eventName) => {
|
|
35
|
-
if (scope instanceof ReactiveScope) {
|
|
36
|
-
scopeMap.set(eventName, scope);
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
return scopeMap;
|
|
33
|
+
return allScopes.filter(tuple => tuple[1] instanceof ReactiveScope);
|
|
40
34
|
}
|
|
41
35
|
//# sourceMappingURL=event.js.map
|
package/scope/event.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../src/expressions/scope/event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,MAAM,YAAY,CAAC;AAGhE,SAAS,eAAe,CAAC,UAAoB,EAAE,MAA0B,EAAE,KAA0B,EAAE,
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../src/expressions/scope/event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAuB,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AU,EAAE,WAAW,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;IACH,OAAO,WAAW,CAAC;AACpB,CAAC;AAED,MAAM,UAAU,2BAA2B,CAAC,MAA0B,EAAE,KAAY;IACnF,MAAM,SAAS,GAAG,mBAAmB,CAAC,MAAM,EAAE,KAAK,CAAC,CAAC;IACrD,OAAO,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC,YAAY,aAAa,CAA4C,CAAC;AAChH,CAAC","sourcesContent":["import { ExpressionEventMap } from '../api/expression.js';\nimport { ReactiveScope, Scope, ScopeContext } from './scope.js';\nimport { Stack } from './stack.js';\n\nfunction visitInnerScope(eventNames: string[], events: ExpressionEventMap, scope: Scope<ScopeContext>, scopeTuples: [string, Scope<ScopeContext>][]) {\n\teventNames.forEach(eventName => {\n\t\tif (eventName.startsWith(':')) {\n\t\t\treturn;\n\t\t}\n\t\tscopeTuples.push([eventName, scope]);\n\t\tconst nextEvents = Object.keys(events[eventName]);\n\t\tif (!nextEvents.length) {\n\t\t\treturn;\n\t\t}\n\t\tconst innerScope = scope.getScopeOrCreat(eventName);\n\t\tvisitInnerScope(nextEvents, events[eventName], innerScope, scopeTuples);\n\t});\n}\n\nexport function findScopeByEventMap(events: ExpressionEventMap, stack: Stack): [string, Scope<ScopeContext>][] {\n\tconst scopeTuples: [string, Scope<ScopeContext>][] = [];\n\tconst rootEventNames = Object.keys(events);\n\trootEventNames.forEach(eventName => {\n\t\tconst scope = stack.findScope<ScopeContext>(eventName);\n\t\tscopeTuples.push([eventName, scope]);\n\t\tconst nextEvents = Object.keys(events[eventName]);\n\t\tif (!nextEvents.length) {\n\t\t\treturn;\n\t\t}\n\t\tconst eventScope = scope.getScopeOrCreat<ScopeContext>(eventName);\n\t\tvisitInnerScope(nextEvents, events[eventName], eventScope, scopeTuples);\n\t});\n\treturn scopeTuples;\n}\n\nexport function findReactiveScopeByEventMap(events: ExpressionEventMap, stack: Stack): [string, ReactiveScope<ScopeContext>][] {\n\tconst allScopes = findScopeByEventMap(events, stack);\n\treturn allScopes.filter(tuple => tuple[1] instanceof ReactiveScope) as [string, ReactiveScope<ScopeContext>][];\n}\n"]}
|
|
@@ -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,12 +2,11 @@ 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;
|
|
9
|
-
private proxyMap;
|
|
10
|
-
private proxyValueMap;
|
|
11
10
|
private functionHandler;
|
|
12
11
|
constructor(scope: Scope<T>);
|
|
13
12
|
has(model: T, propertyKey: PropertyKey): boolean;
|
package/scope/proxy.js
CHANGED
|
@@ -2,57 +2,53 @@ 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
|
+
case this.thisContext instanceof HTMLElement:
|
|
17
|
+
return this.thisContext;
|
|
18
|
+
default:
|
|
19
|
+
return targetThisArg;
|
|
20
|
+
}
|
|
7
21
|
}
|
|
8
22
|
}
|
|
9
23
|
export class ScopeProxyHandler {
|
|
10
24
|
constructor(scope) {
|
|
11
25
|
this.scope = scope;
|
|
12
|
-
this.proxyMap = new Map();
|
|
13
|
-
this.proxyValueMap = new WeakMap();
|
|
14
26
|
}
|
|
15
27
|
has(model, propertyKey) {
|
|
16
28
|
return this.scope.has(propertyKey);
|
|
17
29
|
}
|
|
18
30
|
get(model, propertyKey, receiver) {
|
|
19
|
-
if (this.proxyMap.has(propertyKey)) {
|
|
20
|
-
return this.proxyMap.get(propertyKey);
|
|
21
|
-
}
|
|
22
31
|
const value = this.scope.get(propertyKey);
|
|
32
|
+
if (value == null) {
|
|
33
|
+
return value;
|
|
34
|
+
}
|
|
23
35
|
if (typeof value === 'object') {
|
|
24
36
|
const scope = this.scope.getScope(propertyKey);
|
|
25
37
|
if (scope) {
|
|
26
|
-
|
|
27
|
-
this.proxyMap.set(propertyKey, proxy);
|
|
28
|
-
this.proxyValueMap.set(proxy, value);
|
|
29
|
-
return proxy;
|
|
38
|
+
return new Proxy(value, new ScopeProxyHandler(scope));
|
|
30
39
|
}
|
|
31
40
|
}
|
|
32
41
|
else if (typeof value === 'function') {
|
|
33
|
-
|
|
42
|
+
return new Proxy(value, this.functionHandler
|
|
34
43
|
?? (this.functionHandler = new FunctionProxyHandler(this.scope.getContext())));
|
|
35
|
-
this.proxyMap.set(propertyKey, proxy);
|
|
36
|
-
this.proxyValueMap.set(proxy, value);
|
|
37
|
-
return proxy;
|
|
38
44
|
}
|
|
39
45
|
return value;
|
|
40
46
|
}
|
|
41
47
|
set(model, propertyKey, value, receiver) {
|
|
42
|
-
if ((typeof value === 'object' || typeof value === 'function') && this.proxyValueMap.has(value)) {
|
|
43
|
-
value = this.proxyValueMap.get(value);
|
|
44
|
-
}
|
|
45
48
|
return this.scope.set(propertyKey, value);
|
|
46
49
|
}
|
|
47
50
|
deleteProperty(model, propertyKey) {
|
|
48
|
-
|
|
49
|
-
if (isDelete) {
|
|
50
|
-
this.scope.set(propertyKey, undefined);
|
|
51
|
-
if (this.proxyMap.has(propertyKey)) {
|
|
52
|
-
this.proxyMap.delete(propertyKey);
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return isDelete;
|
|
51
|
+
return this.scope.delete(propertyKey);
|
|
56
52
|
}
|
|
57
53
|
}
|
|
58
54
|
export function createRevocableProxyForContext(context, 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;YAEb,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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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"]}
|
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
|
-
emitChanges(propertyKey?: keyof T): void;
|
|
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
|
-
emitChanges(propertyKey?: keyof T): void;
|
|
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 {};
|