@ibyar/expressions 0.5.6 → 0.6.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/api/abstract.js +5 -0
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +28 -13
- package/api/class/class.js +46 -41
- package/api/class/class.js.map +1 -1
- package/api/computing/return.d.ts +4 -0
- package/api/computing/return.js +5 -0
- package/api/computing/return.js.map +1 -1
- package/api/computing/throw.d.ts +4 -0
- package/api/computing/throw.js +4 -0
- package/api/computing/throw.js.map +1 -1
- package/api/definition/bind.d.ts +6 -0
- package/api/definition/bind.js +6 -0
- package/api/definition/bind.js.map +1 -1
- package/api/definition/function.js +6 -5
- package/api/definition/function.js.map +1 -1
- package/api/definition/member.js.map +1 -1
- package/api/definition/object.js +1 -1
- package/api/definition/object.js.map +1 -1
- package/api/definition/values.d.ts +12 -3
- package/api/definition/values.js +25 -4
- package/api/definition/values.js.map +1 -1
- package/api/deserialize/deserialize.d.ts +5 -0
- package/api/deserialize/deserialize.js +5 -0
- package/api/deserialize/deserialize.js.map +1 -1
- package/api/expression.d.ts +151 -5
- package/api/expression.js.map +1 -1
- package/api/module/export.d.ts +63 -0
- package/api/module/export.js +64 -1
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +53 -0
- package/api/module/import.js +53 -0
- package/api/module/import.js.map +1 -1
- package/api/operators/grouping.d.ts +7 -0
- package/api/operators/grouping.js +7 -0
- package/api/operators/grouping.js.map +1 -1
- package/api/operators/pipeline.d.ts +12 -0
- package/api/operators/pipeline.js +12 -0
- package/api/operators/pipeline.js.map +1 -1
- package/api/operators/unary.js +3 -0
- package/api/operators/unary.js.map +1 -1
- package/api/program.d.ts +2 -2
- package/api/program.js.map +1 -1
- package/api/statement/control/block.d.ts +4 -0
- package/api/statement/control/block.js +4 -0
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/empty.d.ts +7 -0
- package/api/statement/control/empty.js +7 -0
- package/api/statement/control/empty.js.map +1 -1
- package/api/statement/control/if.d.ts +5 -0
- package/api/statement/control/if.js +5 -0
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +6 -0
- package/api/statement/control/switch.js +9 -0
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +8 -0
- package/api/statement/control/terminate.js +8 -0
- package/api/statement/control/terminate.js.map +1 -1
- package/api/statement/iterations/for.d.ts +5 -0
- package/api/statement/iterations/for.js +13 -0
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +6 -0
- package/api/statement/iterations/while.js +10 -0
- package/api/statement/iterations/while.js.map +1 -1
- package/package.json +5 -3
- package/scope/event.d.ts +3 -3
- package/scope/event.js +2 -2
- package/scope/event.js.map +1 -1
- package/scope/pool.d.ts +7 -0
- package/scope/pool.js +29 -0
- package/scope/pool.js.map +1 -0
- package/scope/proxy.d.ts +6 -9
- package/scope/proxy.js +22 -31
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +161 -38
- package/scope/scope.js +260 -106
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +95 -19
- package/scope/stack.js +13 -0
- package/scope/stack.js.map +1 -1
- package/v8/enums.js +31 -0
- package/v8/enums.js.map +1 -1
- package/v8/inline.d.ts +36 -0
- package/v8/inline.js +407 -5
- package/v8/inline.js.map +1 -1
- package/v8/nodes.js +2 -1
- package/v8/nodes.js.map +1 -1
- package/v8/parser.d.ts +8 -0
- package/v8/parser.js +304 -1
- package/v8/parser.js.map +1 -1
- package/v8/stream.d.ts +4 -0
- package/v8/stream.js +79 -17
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +229 -0
- package/v8/token.js +236 -1
- package/v8/token.js.map +1 -1
- package/visit/visitor.d.ts +3 -0
package/scope/event.js
CHANGED
|
@@ -9,7 +9,7 @@ function visitInnerScope(eventNames, events, scope, scopeTuples) {
|
|
|
9
9
|
if (!nextEvents.length) {
|
|
10
10
|
return;
|
|
11
11
|
}
|
|
12
|
-
const innerScope = scope.
|
|
12
|
+
const innerScope = scope.getInnerScope(eventName) ?? scope.setInnerScope(eventName);
|
|
13
13
|
visitInnerScope(nextEvents, events[eventName], innerScope, scopeTuples);
|
|
14
14
|
});
|
|
15
15
|
}
|
|
@@ -23,7 +23,7 @@ export function findScopeByEventMap(events, stack) {
|
|
|
23
23
|
if (!nextEvents.length) {
|
|
24
24
|
return;
|
|
25
25
|
}
|
|
26
|
-
const eventScope = scope.
|
|
26
|
+
const eventScope = scope.getInnerScope(eventName) ?? scope.setInnerScope(eventName);
|
|
27
27
|
visitInnerScope(nextEvents, events[eventName], eventScope, scopeTuples);
|
|
28
28
|
});
|
|
29
29
|
return scopeTuples;
|
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,
|
|
1
|
+
{"version":3,"file":"event.js","sourceRoot":"","sources":["../../../src/expressions/scope/event.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAkB,MAAM,YAAY,CAAC;AAG3D,SAAS,eAAe,CAAC,UAAoB,EAAE,MAA0B,EAAE,KAAqB,EAAE,WAAuC;IACxI,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAC9B,IAAI,SAAS,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE;YAC9B,OAAO;SACP;QACD,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;QACrC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACvB,OAAO;SACP;QACD,MAAM,UAAU,GAAG,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACpF,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,UAAU,EAAE,WAAW,CAAC,CAAC;IACzE,CAAC,CAAC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAA0B,EAAE,KAAY;IAC3E,MAAM,WAAW,GAA+B,EAAE,CAAC;IACnD,MAAM,cAAc,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC3C,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE;QAClC,MAAM,KAAK,GAAG,KAAK,CAAC,SAAS,CAAU,SAAS,CAAC,CAAC;QAClD,WAAW,CAAC,IAAI,CAAC,CAAC,SAAS,EAAE,KAAK,CAAC,CAAC,CAAC;QACrC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC;QAClD,IAAI,CAAC,UAAU,CAAC,MAAM,EAAE;YACvB,OAAO;SACP;QACD,MAAM,UAAU,GAAG,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,aAAa,CAAC,SAAS,CAAC,CAAC;QACpF,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,SAAS,CAAC,EAAE,UAAU,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,CAAuC,CAAC;AAC3G,CAAC","sourcesContent":["import { ExpressionEventMap } from '../api/expression.js';\nimport { ReactiveScope, Scope, Context } from './scope.js';\nimport { Stack } from './stack.js';\n\nfunction visitInnerScope(eventNames: string[], events: ExpressionEventMap, scope: Scope<Context>, scopeTuples: [string, Scope<Context>][]) {\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.getInnerScope(eventName) ?? scope.setInnerScope(eventName);\n\t\tvisitInnerScope(nextEvents, events[eventName], innerScope, scopeTuples);\n\t});\n}\n\nexport function findScopeByEventMap(events: ExpressionEventMap, stack: Stack): [string, Scope<Context>][] {\n\tconst scopeTuples: [string, Scope<Context>][] = [];\n\tconst rootEventNames = Object.keys(events);\n\trootEventNames.forEach(eventName => {\n\t\tconst scope = stack.findScope<Context>(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.getInnerScope(eventName) ?? scope.setInnerScope(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<Context>][] {\n\tconst allScopes = findScopeByEventMap(events, stack);\n\treturn allScopes.filter(tuple => tuple[1] instanceof ReactiveScope) as [string, ReactiveScope<Context>][];\n}\n"]}
|
package/scope/pool.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ReactiveScope, ReactiveScopeControl, ReadOnlyScope, Scope } from './scope.js';
|
|
2
|
+
export declare type ScopeType = 'scope' | 'read-only' | 'reactive' | 'reactive-control';
|
|
3
|
+
export declare function getScopeFor<S extends Scope<T>, T extends object>(ctx: T): S | undefined;
|
|
4
|
+
export declare function getScopeFor<T extends object>(ctx: T, type: 'scope', propertyKeys?: (keyof T)[]): Scope<T>;
|
|
5
|
+
export declare function getScopeFor<T extends object>(ctx: T, type: 'read-only', propertyKeys?: (keyof T)[]): ReadOnlyScope<T>;
|
|
6
|
+
export declare function getScopeFor<T extends object>(ctx: T, type: 'reactive', propertyKeys?: (keyof T)[]): ReactiveScope<T>;
|
|
7
|
+
export declare function getScopeFor<T extends object>(ctx: T, type: 'reactive-control', propertyKeys?: (keyof T)[]): ReactiveScopeControl<T>;
|
package/scope/pool.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { ReactiveScope, ReactiveScopeControl, ReadOnlyScope, Scope } from './scope.js';
|
|
2
|
+
const pool = new WeakMap();
|
|
3
|
+
export function getScopeFor(ctx, type, propertyKeys) {
|
|
4
|
+
if (pool.has(ctx)) {
|
|
5
|
+
return pool.get(ctx);
|
|
6
|
+
}
|
|
7
|
+
if (!type) {
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
let scope;
|
|
11
|
+
switch (type) {
|
|
12
|
+
case 'read-only':
|
|
13
|
+
scope = ReadOnlyScope.for(ctx, propertyKeys);
|
|
14
|
+
break;
|
|
15
|
+
case 'reactive':
|
|
16
|
+
scope = ReactiveScope.for(ctx, propertyKeys);
|
|
17
|
+
break;
|
|
18
|
+
case 'reactive-control':
|
|
19
|
+
scope = ReactiveScopeControl.for(ctx, propertyKeys);
|
|
20
|
+
break;
|
|
21
|
+
default:
|
|
22
|
+
case 'scope':
|
|
23
|
+
scope = Scope.for(ctx, propertyKeys);
|
|
24
|
+
break;
|
|
25
|
+
}
|
|
26
|
+
pool.set(ctx, scope);
|
|
27
|
+
return scope;
|
|
28
|
+
}
|
|
29
|
+
//# sourceMappingURL=pool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../../../src/expressions/scope/pool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,oBAAoB,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAEvF,MAAM,IAAI,GAAG,IAAI,OAAO,EAAsB,CAAC;AAS/C,MAAM,UAAU,WAAW,CAAuC,GAAM,EAAE,IAAgB,EAAE,YAA0B;IACrH,IAAI,IAAI,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE;QAClB,OAAO,IAAI,CAAC,GAAG,CAAC,GAAG,CAAQ,CAAC;KAC5B;IACD,IAAI,CAAC,IAAI,EAAE;QACV,OAAO;KACP;IACD,IAAI,KAAe,CAAC;IACpB,QAAQ,IAAI,EAAE;QACb,KAAK,WAAW;YACf,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YAC7C,MAAM;QACP,KAAK,UAAU;YACd,KAAK,GAAG,aAAa,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YAC7C,MAAM;QACP,KAAK,kBAAkB;YACtB,KAAK,GAAG,oBAAoB,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YACpD,MAAM;QACP,QAAQ;QACR,KAAK,OAAO;YACX,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YACrC,MAAM;KACP;IACD,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrB,OAAO,KAAiB,CAAC;AAC1B,CAAC","sourcesContent":["import { ReactiveScope, ReactiveScopeControl, ReadOnlyScope, Scope } from './scope.js';\n\nconst pool = new WeakMap<object, Scope<any>>();\n\nexport type ScopeType = 'scope' | 'read-only' | 'reactive' | 'reactive-control';\n\nexport function getScopeFor<S extends Scope<T>, T extends object>(ctx: T): S | undefined;\nexport function getScopeFor<T extends object>(ctx: T, type: 'scope', propertyKeys?: (keyof T)[]): Scope<T>;\nexport function getScopeFor<T extends object>(ctx: T, type: 'read-only', propertyKeys?: (keyof T)[]): ReadOnlyScope<T>;\nexport function getScopeFor<T extends object>(ctx: T, type: 'reactive', propertyKeys?: (keyof T)[]): ReactiveScope<T>;\nexport function getScopeFor<T extends object>(ctx: T, type: 'reactive-control', propertyKeys?: (keyof T)[]): ReactiveScopeControl<T>;\nexport function getScopeFor<S extends Scope<T>, T extends object>(ctx: T, type?: ScopeType, propertyKeys?: (keyof T)[]): S | undefined {\n\tif (pool.has(ctx)) {\n\t\treturn pool.get(ctx) as any;\n\t}\n\tif (!type) {\n\t\treturn;\n\t}\n\tlet scope: Scope<T>;\n\tswitch (type) {\n\t\tcase 'read-only':\n\t\t\tscope = ReadOnlyScope.for(ctx, propertyKeys);\n\t\t\tbreak;\n\t\tcase 'reactive':\n\t\t\tscope = ReactiveScope.for(ctx, propertyKeys);\n\t\t\tbreak;\n\t\tcase 'reactive-control':\n\t\t\tscope = ReactiveScopeControl.for(ctx, propertyKeys);\n\t\t\tbreak;\n\t\tdefault:\n\t\tcase 'scope':\n\t\t\tscope = Scope.for(ctx, propertyKeys);\n\t\t\tbreak;\n\t}\n\tpool.set(ctx, scope);\n\treturn scope as any as S;\n}\n"]}
|
package/scope/proxy.d.ts
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
|
-
import type { Scope,
|
|
2
|
-
export declare
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
export declare class ScopeProxyHandler<T extends ScopeContext> implements ProxyHandler<ScopeContext> {
|
|
1
|
+
import type { Scope, Context } from './scope.js';
|
|
2
|
+
export declare function hasBindingHook<T>(ctx: T): boolean;
|
|
3
|
+
/**
|
|
4
|
+
* crete new proxy handler object as scoped context
|
|
5
|
+
*/
|
|
6
|
+
export declare class ScopeProxyHandler<T extends Context> implements ProxyHandler<Context> {
|
|
9
7
|
private scope;
|
|
10
|
-
private functionHandler;
|
|
11
8
|
constructor(scope: Scope<T>);
|
|
12
9
|
has(model: T, propertyKey: PropertyKey): boolean;
|
|
13
10
|
get(model: T, propertyKey: PropertyKey, receiver: any): any;
|
package/scope/proxy.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
}
|
|
1
|
+
export function hasBindingHook(ctx) {
|
|
2
|
+
switch (true) {
|
|
3
|
+
// exclude classes that have binding hook
|
|
4
|
+
case ctx instanceof Map:
|
|
5
|
+
case ctx instanceof Set:
|
|
6
|
+
case ctx instanceof Date:
|
|
7
|
+
case ctx instanceof WeakMap:
|
|
8
|
+
case ctx instanceof WeakSet:
|
|
9
|
+
case ctx instanceof Promise:
|
|
10
|
+
case HTMLElement && ctx instanceof HTMLElement:
|
|
11
|
+
return true;
|
|
12
|
+
default:
|
|
13
|
+
return false;
|
|
21
14
|
}
|
|
22
15
|
}
|
|
16
|
+
/**
|
|
17
|
+
* crete new proxy handler object as scoped context
|
|
18
|
+
*/
|
|
23
19
|
export class ScopeProxyHandler {
|
|
20
|
+
// private functionHandler: FunctionProxyHandler<Function>;
|
|
24
21
|
constructor(scope) {
|
|
25
22
|
this.scope = scope;
|
|
26
23
|
}
|
|
@@ -29,20 +26,14 @@ export class ScopeProxyHandler {
|
|
|
29
26
|
}
|
|
30
27
|
get(model, propertyKey, receiver) {
|
|
31
28
|
const value = this.scope.get(propertyKey);
|
|
32
|
-
if (value
|
|
29
|
+
if (!(value && typeof value === 'object')) {
|
|
33
30
|
return value;
|
|
34
31
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
return new Proxy(value, new ScopeProxyHandler(scope));
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
else if (typeof value === 'function') {
|
|
42
|
-
return new Proxy(value, this.functionHandler
|
|
43
|
-
?? (this.functionHandler = new FunctionProxyHandler(this.scope.getContext())));
|
|
32
|
+
const scope = this.scope.getInnerScope(propertyKey);
|
|
33
|
+
if (!scope) {
|
|
34
|
+
return value;
|
|
44
35
|
}
|
|
45
|
-
return
|
|
36
|
+
return createProxyForContext(scope);
|
|
46
37
|
}
|
|
47
38
|
set(model, propertyKey, value, receiver) {
|
|
48
39
|
return this.scope.set(propertyKey, value);
|
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,
|
|
1
|
+
{"version":3,"file":"proxy.js","sourceRoot":"","sources":["../../../src/expressions/scope/proxy.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,cAAc,CAAI,GAAM;IACvC,QAAQ,IAAI,EAAE;QACb,yCAAyC;QACzC,KAAK,GAAG,YAAY,GAAG,CAAC;QACxB,KAAK,GAAG,YAAY,GAAG,CAAC;QACxB,KAAK,GAAG,YAAY,IAAI,CAAC;QACzB,KAAK,GAAG,YAAY,OAAO,CAAC;QAC5B,KAAK,GAAG,YAAY,OAAO,CAAC;QAC5B,KAAK,GAAG,YAAY,OAAO,CAAC;QAC5B,KAAK,WAAW,IAAI,GAAG,YAAY,WAAW;YAC7C,OAAO,IAAI,CAAC;QACb;YACC,OAAO,KAAK,CAAC;KACd;AACF,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,iBAAiB;IAC7B,2DAA2D;IAC3D,YAAoB,KAAe;QAAf,UAAK,GAAL,KAAK,CAAU;IAAI,CAAC;IACxC,GAAG,CAAC,KAAQ,EAAE,WAAwB;QACrC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;IACD,GAAG,CAAC,KAAQ,EAAE,WAAwB,EAAE,QAAa;QACpD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,CAAC,CAAC;QAC1C,IAAI,CAAC,CAAC,KAAK,IAAI,OAAO,KAAK,KAAK,QAAQ,CAAC,EAAE;YAC1C,OAAO,KAAK,CAAC;SACb;QACD,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;QACpD,IAAI,CAAC,KAAK,EAAE;YACX,OAAO,KAAK,CAAC;SACb;QACD,OAAO,qBAAqB,CAAC,KAAK,CAAC,CAAC;IACrC,CAAC;IACD,GAAG,CAAC,KAAQ,EAAE,WAAwB,EAAE,KAAU,EAAE,QAAa;QAChE,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAC3C,CAAC;IACD,cAAc,CAAC,KAAQ,EAAE,WAA4B;QACpD,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACvC,CAAC;CACD;AAOD,MAAM,UAAU,8BAA8B,CAAmB,OAAU,EAAE,KAAe;IAC3F,OAAO,KAAK,CAAC,SAAS,CAAI,OAAO,EAAE,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;AAClE,CAAC;AAED,MAAM,UAAU,qBAAqB,CAAmB,KAAe;IACtE,OAAO,IAAI,KAAK,CAAI,KAAK,CAAC,UAAU,EAAE,EAAE,IAAI,iBAAiB,CAAC,KAAK,CAAC,CAAC,CAAC;AACvE,CAAC","sourcesContent":["import type { Scope, Context } from './scope.js';\n\nexport function hasBindingHook<T>(ctx: T) {\n\tswitch (true) {\n\t\t// exclude classes that have binding hook\n\t\tcase ctx instanceof Map:\n\t\tcase ctx instanceof Set:\n\t\tcase ctx instanceof Date:\n\t\tcase ctx instanceof WeakMap:\n\t\tcase ctx instanceof WeakSet:\n\t\tcase ctx instanceof Promise:\n\t\tcase HTMLElement && ctx instanceof HTMLElement:\n\t\t\treturn true;\n\t\tdefault:\n\t\t\treturn false;\n\t}\n}\n\n/**\n * crete new proxy handler object as scoped context\n */\nexport class ScopeProxyHandler<T extends Context> implements ProxyHandler<Context> {\n\t// private 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 && typeof value === 'object')) {\n\t\t\treturn value;\n\t\t}\n\t\tconst scope = this.scope.getInnerScope(propertyKey);\n\t\tif (!scope) {\n\t\t\treturn value;\n\t\t}\n\t\treturn createProxyForContext(scope);\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,32 +1,89 @@
|
|
|
1
1
|
import { TypeOf } from '../api/utils.js';
|
|
2
|
-
export declare type
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
export declare type Context = Record<PropertyKey, any>;
|
|
3
|
+
export interface Scope<T = Context> {
|
|
4
|
+
/**
|
|
5
|
+
* get value of `propertyKey` in current context
|
|
6
|
+
* @param propertyKey
|
|
7
|
+
*/
|
|
6
8
|
get(propertyKey: keyof T): any;
|
|
9
|
+
/**
|
|
10
|
+
* set the value of `propertyKey` in current context, could be instilled with `value`.
|
|
11
|
+
* @param propertyKey
|
|
12
|
+
* @param value
|
|
13
|
+
* @param receiver
|
|
14
|
+
*/
|
|
7
15
|
set(propertyKey: keyof T, value?: any, receiver?: any): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* is current context has `propertyKey` in hash map keys
|
|
18
|
+
* @param propertyKey
|
|
19
|
+
*/
|
|
8
20
|
has(propertyKey: keyof T): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* delete property from context
|
|
23
|
+
* @param propertyKey
|
|
24
|
+
*/
|
|
9
25
|
delete(propertyKey: keyof T): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* get current context object of this scope
|
|
28
|
+
*/
|
|
10
29
|
getContext(): T;
|
|
30
|
+
/**
|
|
31
|
+
* get a proxy of the current context object if exists.
|
|
32
|
+
*/
|
|
11
33
|
getContextProxy?(): T;
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
34
|
+
/**
|
|
35
|
+
* get a scope for an object named as `propertyKey` from cache map,
|
|
36
|
+
*
|
|
37
|
+
* if the current value is not type od `object`, will return `undefined`.
|
|
38
|
+
* @param propertyKey the name of the property
|
|
39
|
+
*/
|
|
40
|
+
getInnerScope<S extends Scope<Context>>(propertyKey: keyof T): S | undefined;
|
|
41
|
+
/**
|
|
42
|
+
* create a scope with the same type of this scope
|
|
43
|
+
*/
|
|
44
|
+
setInnerScope<S extends Scope<Context>>(propertyKey: keyof T): S;
|
|
45
|
+
/**
|
|
46
|
+
* sc
|
|
47
|
+
* @param propertyKey
|
|
48
|
+
* @param scope
|
|
49
|
+
*/
|
|
50
|
+
setInnerScope<S extends Scope<Context>>(propertyKey: keyof T, scope?: S): S;
|
|
51
|
+
getClass(): TypeOf<Scope<Context>>;
|
|
15
52
|
}
|
|
16
|
-
export declare class Scope<T extends
|
|
17
|
-
protected
|
|
18
|
-
|
|
19
|
-
static
|
|
20
|
-
|
|
21
|
-
protected
|
|
53
|
+
export declare class Scope<T extends Context> implements Scope<T> {
|
|
54
|
+
protected _ctx: T;
|
|
55
|
+
protected _keys?: (keyof T)[] | undefined;
|
|
56
|
+
static for<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]): Scope<T>;
|
|
57
|
+
static blockScope<T extends Context>(propertyKeys?: (keyof T)[]): Scope<T>;
|
|
58
|
+
protected _inners: Map<keyof T, Scope<any>>;
|
|
22
59
|
constructor(context: T, propertyKeys?: (keyof T)[]);
|
|
23
60
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
61
|
+
/**
|
|
62
|
+
* a class scope used for class instance and private static properties
|
|
63
|
+
*/
|
|
64
|
+
export declare class ClassScope<T extends Context> extends Scope<T> {
|
|
65
|
+
private _pKeys?;
|
|
66
|
+
static for<T extends Context>(ctx: T, propertyKeys?: (keyof T)[], privateKeys?: (keyof T)[]): ClassScope<T>;
|
|
67
|
+
static blockScope<T extends Context>(propertyKeys?: (keyof T)[], privateKeys?: (keyof T)[]): ClassScope<T>;
|
|
68
|
+
static readOnlyScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[], privateKeys?: (keyof T)[]): ReadOnlyScope<{
|
|
69
|
+
this: T;
|
|
70
|
+
}>;
|
|
71
|
+
protected _private: Context;
|
|
72
|
+
constructor(context: T, propertyKeys?: (keyof T)[], privateKeys?: (keyof T)[]);
|
|
73
|
+
getPrivateContext(): T;
|
|
74
|
+
get(key: keyof T): any;
|
|
75
|
+
set(key: keyof T, value: any, receiver?: any): boolean;
|
|
76
|
+
has(key: keyof T): boolean;
|
|
77
|
+
delete(key: keyof T): boolean;
|
|
78
|
+
protected isPrivateKey(key: keyof T): boolean;
|
|
79
|
+
getClass(): TypeOf<ReadOnlyScope<Context>>;
|
|
80
|
+
}
|
|
81
|
+
export declare class ReadOnlyScope<T extends Context> extends Scope<T> {
|
|
82
|
+
static for<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]): ReadOnlyScope<T>;
|
|
83
|
+
static blockScope<T extends Context>(propertyKeys?: (keyof T)[]): ReadOnlyScope<T>;
|
|
27
84
|
set(propertyKey: keyof T, value: any, receiver?: any): boolean;
|
|
28
85
|
delete(propertyKey: keyof T): boolean;
|
|
29
|
-
getClass(): TypeOf<ReadOnlyScope<
|
|
86
|
+
getClass(): TypeOf<ReadOnlyScope<Context>>;
|
|
30
87
|
}
|
|
31
88
|
export declare class ScopeSubscription<T> {
|
|
32
89
|
private propertyKey;
|
|
@@ -38,58 +95,124 @@ export declare class ScopeSubscription<T> {
|
|
|
38
95
|
}
|
|
39
96
|
export declare type ValueChangedCallback = (newValue: any, oldValue?: any) => void;
|
|
40
97
|
export declare class ValueChangeObserver<T> {
|
|
41
|
-
private
|
|
42
|
-
private
|
|
98
|
+
private _subscribers;
|
|
99
|
+
private _lock;
|
|
43
100
|
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
44
101
|
subscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T>;
|
|
45
102
|
unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>): void;
|
|
46
103
|
pause(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
|
|
47
104
|
resume(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
|
|
105
|
+
/**
|
|
106
|
+
* check if this Observer has any subscribers
|
|
107
|
+
*/
|
|
108
|
+
hasSubscribers(): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* check if there is any subscribers registered by the propertyKey.
|
|
111
|
+
*
|
|
112
|
+
* @param propertyKey
|
|
113
|
+
*/
|
|
114
|
+
hasSubscribers(propertyKey: keyof T): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* clear subscription maps
|
|
117
|
+
*/
|
|
48
118
|
destroy(): void;
|
|
49
119
|
}
|
|
50
|
-
export declare class ReactiveScope<T extends
|
|
51
|
-
protected
|
|
52
|
-
|
|
53
|
-
static
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
120
|
+
export declare class ReactiveScope<T extends Context> extends Scope<T> {
|
|
121
|
+
protected _name?: keyof T | undefined;
|
|
122
|
+
protected _parent?: ReactiveScope<any> | undefined;
|
|
123
|
+
static for<T extends Context>(context: T, propertyKeys?: (keyof T)[]): ReactiveScope<T>;
|
|
124
|
+
static blockScope<T extends Context>(propertyKeys?: (keyof T)[]): ReactiveScope<T>;
|
|
125
|
+
static scopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]): Scope<{
|
|
126
|
+
this: T;
|
|
127
|
+
}>;
|
|
128
|
+
static readOnlyScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]): ReadOnlyScope<{
|
|
129
|
+
this: T;
|
|
130
|
+
}>;
|
|
131
|
+
protected _clone: T;
|
|
132
|
+
protected _inners: Map<keyof T, ReactiveScope<any>>;
|
|
133
|
+
protected _observer: ValueChangeObserver<T>;
|
|
134
|
+
constructor(context: T, propertyKeys?: (keyof T)[], _name?: keyof T | undefined, _parent?: ReactiveScope<any> | undefined);
|
|
58
135
|
set(propertyKey: keyof T, newValue: any, receiver?: any): boolean;
|
|
59
136
|
delete(propertyKey: keyof T): boolean;
|
|
60
|
-
getScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined;
|
|
61
|
-
getScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V>;
|
|
62
137
|
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
63
138
|
subscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T>;
|
|
64
139
|
unsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>): void;
|
|
65
|
-
|
|
140
|
+
detectChanges(): void;
|
|
141
|
+
protected getPropertyKeys<V extends Record<PropertyKey, any>>(...objs: V[]): (keyof V)[];
|
|
142
|
+
getClass(): TypeOf<ReactiveScope<Context>>;
|
|
66
143
|
}
|
|
67
|
-
|
|
144
|
+
/**
|
|
145
|
+
* used control/notify/pause scope about changes in current context
|
|
146
|
+
*/
|
|
147
|
+
export interface ScopeControl<T extends Context> {
|
|
148
|
+
/**
|
|
149
|
+
* get current stacte of applying change detection.
|
|
150
|
+
*/
|
|
68
151
|
isAttached(): boolean;
|
|
152
|
+
/**
|
|
153
|
+
* used when want to update ui-view like, you want to replace an array with another
|
|
154
|
+
* without reflect changes on view until reattached again.
|
|
155
|
+
*/
|
|
69
156
|
detach(): void;
|
|
157
|
+
/**
|
|
158
|
+
* apply all the not emitted changes, and continue emit in time.
|
|
159
|
+
*/
|
|
70
160
|
reattach(): void;
|
|
161
|
+
/**
|
|
162
|
+
* apply changes now,
|
|
163
|
+
* will not effect the state of the detector wither if attached ot not.
|
|
164
|
+
*
|
|
165
|
+
* if a propertyKey is provided, will emit this property only
|
|
166
|
+
* @param propertyKey
|
|
167
|
+
*/
|
|
71
168
|
emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
|
|
169
|
+
/**
|
|
170
|
+
* throw error if any changes has been made
|
|
171
|
+
*/
|
|
172
|
+
checkNoChanges(): void;
|
|
72
173
|
}
|
|
73
|
-
export declare class ReactiveScopeControl<T extends
|
|
74
|
-
static for<T extends
|
|
75
|
-
static blockScope<T extends
|
|
76
|
-
|
|
77
|
-
|
|
174
|
+
export declare class ReactiveScopeControl<T extends Context> extends ReactiveScope<T> implements ScopeControl<T> {
|
|
175
|
+
static for<T extends Context>(context: T, propertyKeys?: (keyof T)[]): ReactiveScopeControl<T>;
|
|
176
|
+
static blockScope<T extends Context>(propertyKeys?: (keyof T)[]): ReactiveScopeControl<T>;
|
|
177
|
+
static scopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]): Scope<{
|
|
178
|
+
this: T;
|
|
179
|
+
}>;
|
|
180
|
+
static readOnlyScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]): ReadOnlyScope<{
|
|
181
|
+
this: T;
|
|
182
|
+
}>;
|
|
183
|
+
static reactiveScopeForThis<T extends Context>(ctx: T, propertyKeys?: (keyof T)[]): Scope<{
|
|
184
|
+
this: T;
|
|
185
|
+
}>;
|
|
186
|
+
protected _attached: boolean;
|
|
187
|
+
protected _marked: {
|
|
188
|
+
[key: keyof Context]: [any, any];
|
|
189
|
+
};
|
|
78
190
|
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
79
191
|
isAttached(): boolean;
|
|
80
192
|
detach(): void;
|
|
81
193
|
reattach(): void;
|
|
82
194
|
emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
|
|
83
|
-
|
|
195
|
+
detectChanges(): void;
|
|
196
|
+
checkNoChanges(): void;
|
|
197
|
+
getClass(): TypeOf<ReactiveScopeControl<Context>>;
|
|
84
198
|
}
|
|
85
199
|
interface ImportMeta {
|
|
86
200
|
url: URL;
|
|
201
|
+
/**
|
|
202
|
+
*
|
|
203
|
+
* Provides a module-relative resolution function scoped to each module, returning
|
|
204
|
+
* the URL string.
|
|
205
|
+
*
|
|
206
|
+
* @param specified The module specifier to resolve relative to `parent`.
|
|
207
|
+
* @param parent The absolute parent module URL to resolve from. If none
|
|
208
|
+
* is specified, the value of `import.meta.url` is used as the default.
|
|
209
|
+
*/
|
|
87
210
|
resolve?(specified: string, parent?: string | URL): Promise<string>;
|
|
88
211
|
}
|
|
89
212
|
export interface ModuleImport {
|
|
90
213
|
meta: ImportMeta;
|
|
91
214
|
}
|
|
92
|
-
export interface ModuleContext extends
|
|
215
|
+
export interface ModuleContext extends Context {
|
|
93
216
|
import: ModuleImport & ((path: string) => Promise<any>);
|
|
94
217
|
}
|
|
95
218
|
export declare class ModuleScope extends ReactiveScope<ModuleContext> {
|