@ibyar/expressions 0.5.2 → 0.5.62
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +1 -1
- package/README.md +4 -3
- package/api/abstract.d.ts +5 -6
- package/api/abstract.js +8 -3
- package/api/abstract.js.map +1 -1
- package/api/class/class.d.ts +227 -0
- package/api/class/class.js +662 -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 +6 -1
- package/api/computing/return.js +8 -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 +6 -1
- package/api/computing/throw.js +7 -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 +8 -2
- package/api/definition/bind.js +7 -1
- package/api/definition/bind.js.map +1 -1
- package/api/definition/function.d.ts +40 -51
- package/api/definition/function.js +292 -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 +44 -50
- package/api/definition/values.js +87 -149
- package/api/definition/values.js.map +1 -1
- package/api/deserialize/deserialize.d.ts +7 -1
- package/api/deserialize/deserialize.js +9 -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 +159 -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 +129 -25
- package/api/module/export.js +333 -58
- package/api/module/export.js.map +1 -1
- package/api/module/import.d.ts +114 -25
- package/api/module/import.js +279 -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 +9 -2
- package/api/operators/grouping.js +8 -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 +14 -2
- package/api/operators/pipeline.js +13 -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 +7 -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 +8 -5
- package/api/statement/control/block.js +26 -23
- package/api/statement/control/block.js.map +1 -1
- package/api/statement/control/empty.d.ts +8 -1
- package/api/statement/control/empty.js +7 -0
- package/api/statement/control/empty.js.map +1 -1
- package/api/statement/control/if.d.ts +7 -2
- package/api/statement/control/if.js +6 -1
- package/api/statement/control/if.js.map +1 -1
- package/api/statement/control/switch.d.ts +10 -5
- package/api/statement/control/switch.js +22 -9
- package/api/statement/control/switch.js.map +1 -1
- package/api/statement/control/terminate.d.ts +46 -13
- package/api/statement/control/terminate.js +89 -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 +10 -5
- package/api/statement/iterations/for.js +42 -23
- package/api/statement/iterations/for.js.map +1 -1
- package/api/statement/iterations/while.d.ts +9 -3
- package/api/statement/iterations/while.js +27 -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/finalizer.d.ts +4 -0
- package/scope/finalizer.js +11 -0
- package/scope/finalizer.js.map +1 -0
- package/scope/proxy.d.ts +5 -3
- package/scope/proxy.js +26 -26
- package/scope/proxy.js.map +1 -1
- package/scope/scope.d.ts +108 -51
- package/scope/scope.js +72 -134
- package/scope/scope.js.map +1 -1
- package/scope/stack.d.ts +117 -26
- package/scope/stack.js +154 -102
- package/scope/stack.js.map +1 -1
- package/v8/enums.d.ts +204 -0
- package/v8/enums.js +406 -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 +213 -0
- package/v8/inline.js +2375 -0
- package/v8/inline.js.map +1 -0
- package/v8/nodes.d.ts +8 -7
- package/v8/nodes.js +39 -64
- package/v8/nodes.js.map +1 -1
- package/v8/parser.d.ts +49 -151
- package/v8/parser.js +839 -1607
- package/v8/parser.js.map +1 -1
- package/v8/stream.d.ts +39 -3
- package/v8/stream.js +685 -171
- package/v8/stream.js.map +1 -1
- package/v8/token.d.ts +244 -9
- package/v8/token.js +315 -47
- package/v8/token.js.map +1 -1
- package/visit/visitor.d.ts +3 -0
- 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/scope.d.ts
CHANGED
|
@@ -1,48 +1,68 @@
|
|
|
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
|
-
|
|
6
|
+
/**
|
|
7
|
+
* get value of `propertyKey` in current context
|
|
8
|
+
* @param propertyKey
|
|
9
|
+
*/
|
|
7
10
|
get(propertyKey: keyof T): any;
|
|
11
|
+
/**
|
|
12
|
+
* set the value of `propertyKey` in current context, could be instilled with `value`.
|
|
13
|
+
* @param propertyKey
|
|
14
|
+
* @param value
|
|
15
|
+
* @param receiver
|
|
16
|
+
*/
|
|
8
17
|
set(propertyKey: keyof T, value?: any, receiver?: any): boolean;
|
|
18
|
+
/**
|
|
19
|
+
* is current context has `propertyKey` in hash map keys
|
|
20
|
+
* @param propertyKey
|
|
21
|
+
*/
|
|
9
22
|
has(propertyKey: keyof T): boolean;
|
|
23
|
+
/**
|
|
24
|
+
* delete property from context
|
|
25
|
+
* @param propertyKey
|
|
26
|
+
*/
|
|
10
27
|
delete(propertyKey: keyof T): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* get current context object of this scope
|
|
30
|
+
*/
|
|
11
31
|
getContext(): T;
|
|
32
|
+
/**
|
|
33
|
+
* get a proxy of the current context object if exists.
|
|
34
|
+
*/
|
|
35
|
+
getContextProxy?(): T;
|
|
36
|
+
/**
|
|
37
|
+
* get a scope for an object named as `propertyKey` from cache map,
|
|
38
|
+
*
|
|
39
|
+
* if the current value is not type od `object`, will return `undefined`.
|
|
40
|
+
* @param propertyKey the name of the property
|
|
41
|
+
*/
|
|
12
42
|
getScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* get a scope for an object named as `propertyKey` from cache map,
|
|
45
|
+
*
|
|
46
|
+
* if no scope found in the cache, will create a new one, add this one to the map, return a reference.
|
|
47
|
+
* @param propertyKey
|
|
48
|
+
*/
|
|
13
49
|
getScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;
|
|
50
|
+
getClass(): TypeOf<Scope<ScopeContext>>;
|
|
14
51
|
}
|
|
15
52
|
export declare class Scope<T extends ScopeContext> implements Scope<T> {
|
|
16
53
|
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>;
|
|
54
|
+
static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): Scope<T>;
|
|
55
|
+
static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): Scope<T>;
|
|
29
56
|
protected scopeMap: Map<keyof T, Scope<any>>;
|
|
30
|
-
|
|
57
|
+
protected propertyKeys?: (keyof T)[];
|
|
58
|
+
constructor(context: T, propertyKeys?: (keyof T)[]);
|
|
31
59
|
}
|
|
32
60
|
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>;
|
|
61
|
+
static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): ReadOnlyScope<T>;
|
|
62
|
+
static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): ReadOnlyScope<T>;
|
|
44
63
|
set(propertyKey: keyof T, value: any, receiver?: any): boolean;
|
|
45
64
|
delete(propertyKey: keyof T): boolean;
|
|
65
|
+
getClass(): TypeOf<ReadOnlyScope<ScopeContext>>;
|
|
46
66
|
}
|
|
47
67
|
export declare class ScopeSubscription<T> {
|
|
48
68
|
private propertyKey;
|
|
@@ -61,25 +81,19 @@ export declare class ValueChangeObserver<T> {
|
|
|
61
81
|
unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>): void;
|
|
62
82
|
pause(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
|
|
63
83
|
resume(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
|
|
84
|
+
/**
|
|
85
|
+
* clear subscription maps
|
|
86
|
+
*/
|
|
64
87
|
destroy(): void;
|
|
65
88
|
}
|
|
66
89
|
export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
|
|
67
|
-
protected name?: string | undefined;
|
|
68
90
|
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>;
|
|
91
|
+
static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): ReactiveScope<T>;
|
|
92
|
+
static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): ReactiveScope<T>;
|
|
80
93
|
protected observer: ValueChangeObserver<T>;
|
|
81
|
-
|
|
82
|
-
constructor(context: T,
|
|
94
|
+
protected name?: string;
|
|
95
|
+
constructor(context: T, propertyKeys?: (keyof T)[]);
|
|
96
|
+
constructor(context: T, name: string, parent: ReactiveScope<any>, propertyKeys?: (keyof T)[]);
|
|
83
97
|
set(propertyKey: keyof T, newValue: any, receiver?: any): boolean;
|
|
84
98
|
delete(propertyKey: keyof T): boolean;
|
|
85
99
|
getScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined;
|
|
@@ -87,28 +101,71 @@ export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
|
|
|
87
101
|
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
88
102
|
subscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T>;
|
|
89
103
|
unsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>): void;
|
|
104
|
+
getClass(): TypeOf<ReactiveScope<ScopeContext>>;
|
|
90
105
|
}
|
|
106
|
+
/**
|
|
107
|
+
* used control/notify/pause scope about changes in current context
|
|
108
|
+
*/
|
|
91
109
|
export interface ScopeControl<T extends ScopeContext> {
|
|
110
|
+
/**
|
|
111
|
+
* get current stacte of applying change detection.
|
|
112
|
+
*/
|
|
113
|
+
isAttached(): boolean;
|
|
114
|
+
/**
|
|
115
|
+
* used when want to update ui-view like, you want to replace an array with another
|
|
116
|
+
* without reflect changes on view until reattached again.
|
|
117
|
+
*/
|
|
92
118
|
detach(): void;
|
|
119
|
+
/**
|
|
120
|
+
* apply all the not emitted changes, and continue emit in time.
|
|
121
|
+
*/
|
|
93
122
|
reattach(): void;
|
|
123
|
+
/**
|
|
124
|
+
* apply changes now,
|
|
125
|
+
* will not effect the state of the detector wither if attached ot not.
|
|
126
|
+
*
|
|
127
|
+
* if a propertyKey is provided, will emit this property only
|
|
128
|
+
* @param propertyKey
|
|
129
|
+
*/
|
|
94
130
|
emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
|
|
95
131
|
}
|
|
96
132
|
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>;
|
|
133
|
+
static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): ReactiveScopeControl<T>;
|
|
134
|
+
static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): ReactiveScopeControl<T>;
|
|
108
135
|
protected attached: boolean;
|
|
109
136
|
protected marked: ScopeContext;
|
|
110
137
|
emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
|
|
138
|
+
isAttached(): boolean;
|
|
111
139
|
detach(): void;
|
|
112
140
|
reattach(): void;
|
|
113
141
|
emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
|
|
142
|
+
getClass(): TypeOf<ReactiveScopeControl<ScopeContext>>;
|
|
114
143
|
}
|
|
144
|
+
interface ImportMeta {
|
|
145
|
+
url: URL;
|
|
146
|
+
/**
|
|
147
|
+
*
|
|
148
|
+
* Provides a module-relative resolution function scoped to each module, returning
|
|
149
|
+
* the URL string.
|
|
150
|
+
*
|
|
151
|
+
* @param specified The module specifier to resolve relative to `parent`.
|
|
152
|
+
* @param parent The absolute parent module URL to resolve from. If none
|
|
153
|
+
* is specified, the value of `import.meta.url` is used as the default.
|
|
154
|
+
*/
|
|
155
|
+
resolve?(specified: string, parent?: string | URL): Promise<string>;
|
|
156
|
+
}
|
|
157
|
+
export interface ModuleImport {
|
|
158
|
+
meta: ImportMeta;
|
|
159
|
+
}
|
|
160
|
+
export interface ModuleContext extends ScopeContext {
|
|
161
|
+
import: ModuleImport & ((path: string) => Promise<any>);
|
|
162
|
+
}
|
|
163
|
+
export declare class ModuleScope extends ReactiveScope<ModuleContext> {
|
|
164
|
+
constructor(context: ModuleContext, propertyKeys?: (keyof ModuleContext)[]);
|
|
165
|
+
importModule(propertyKey: keyof ModuleContext, scope: ModuleScope): void;
|
|
166
|
+
}
|
|
167
|
+
export declare class WebModuleScope extends ModuleScope {
|
|
168
|
+
constructor();
|
|
169
|
+
updateContext(context: any): void;
|
|
170
|
+
}
|
|
171
|
+
export {};
|
package/scope/scope.js
CHANGED
|
@@ -1,41 +1,19 @@
|
|
|
1
1
|
export class Scope {
|
|
2
|
-
constructor(context,
|
|
2
|
+
constructor(context, propertyKeys) {
|
|
3
3
|
this.context = context;
|
|
4
|
-
this.type = type;
|
|
5
4
|
this.scopeMap = new Map();
|
|
5
|
+
this.propertyKeys = propertyKeys;
|
|
6
|
+
if (Array.isArray(this.propertyKeys)) {
|
|
7
|
+
this.has = (propertyKey) => {
|
|
8
|
+
return this.propertyKeys.includes(propertyKey);
|
|
9
|
+
};
|
|
10
|
+
}
|
|
6
11
|
}
|
|
7
|
-
static for(context,
|
|
8
|
-
return new Scope(context,
|
|
9
|
-
}
|
|
10
|
-
static blockScopeFor(context) {
|
|
11
|
-
return new Scope(context, 'block');
|
|
12
|
-
}
|
|
13
|
-
static functionScopeFor(context) {
|
|
14
|
-
return new Scope(context, 'function');
|
|
15
|
-
}
|
|
16
|
-
static classScopeFor(context) {
|
|
17
|
-
return new Scope(context, 'class');
|
|
18
|
-
}
|
|
19
|
-
static moduleScopeFor(context) {
|
|
20
|
-
return new Scope(context, 'module');
|
|
21
|
-
}
|
|
22
|
-
static globalScopeFor(context) {
|
|
23
|
-
return new Scope(context, 'global');
|
|
24
|
-
}
|
|
25
|
-
static blockScope() {
|
|
26
|
-
return new Scope({}, 'block');
|
|
27
|
-
}
|
|
28
|
-
static functionScope() {
|
|
29
|
-
return new Scope({}, 'function');
|
|
30
|
-
}
|
|
31
|
-
static classScope() {
|
|
32
|
-
return new Scope({}, 'class');
|
|
33
|
-
}
|
|
34
|
-
static moduleScope() {
|
|
35
|
-
return new Scope({}, 'module');
|
|
12
|
+
static for(context, propertyKeys) {
|
|
13
|
+
return new Scope(context, propertyKeys);
|
|
36
14
|
}
|
|
37
|
-
static
|
|
38
|
-
return new Scope({},
|
|
15
|
+
static blockScope(propertyKeys) {
|
|
16
|
+
return new Scope({}, propertyKeys);
|
|
39
17
|
}
|
|
40
18
|
get(propertyKey) {
|
|
41
19
|
return Reflect.get(this.context, propertyKey);
|
|
@@ -62,7 +40,7 @@ export class Scope {
|
|
|
62
40
|
if (typeof scopeContext !== 'object') {
|
|
63
41
|
return;
|
|
64
42
|
}
|
|
65
|
-
scope = new
|
|
43
|
+
scope = new (this.getClass())(scopeContext);
|
|
66
44
|
this.scopeMap.set(propertyKey, scope);
|
|
67
45
|
return scope;
|
|
68
46
|
}
|
|
@@ -73,51 +51,32 @@ export class Scope {
|
|
|
73
51
|
scope.context = scopeContext;
|
|
74
52
|
return scope;
|
|
75
53
|
}
|
|
76
|
-
scope = new
|
|
54
|
+
scope = new (this.getClass())(scopeContext);
|
|
77
55
|
this.scopeMap.set(propertyKey, scope);
|
|
78
56
|
return scope;
|
|
79
57
|
}
|
|
58
|
+
getClass() {
|
|
59
|
+
return Scope;
|
|
60
|
+
}
|
|
80
61
|
}
|
|
81
62
|
export class ReadOnlyScope extends Scope {
|
|
82
|
-
static for(context,
|
|
83
|
-
return new ReadOnlyScope(context,
|
|
84
|
-
}
|
|
85
|
-
static blockScopeFor(context) {
|
|
86
|
-
return new ReadOnlyScope(context, 'block');
|
|
87
|
-
}
|
|
88
|
-
static functionScopeFor(context) {
|
|
89
|
-
return new ReadOnlyScope(context, 'function');
|
|
90
|
-
}
|
|
91
|
-
static classScopeFor(context) {
|
|
92
|
-
return new ReadOnlyScope(context, 'class');
|
|
63
|
+
static for(context, propertyKeys) {
|
|
64
|
+
return new ReadOnlyScope(context, propertyKeys);
|
|
93
65
|
}
|
|
94
|
-
static
|
|
95
|
-
return new ReadOnlyScope(
|
|
96
|
-
}
|
|
97
|
-
static globalScopeFor(context) {
|
|
98
|
-
return new ReadOnlyScope(context, 'global');
|
|
99
|
-
}
|
|
100
|
-
static blockScope() {
|
|
101
|
-
return new ReadOnlyScope({}, 'block');
|
|
102
|
-
}
|
|
103
|
-
static functionScope() {
|
|
104
|
-
return new ReadOnlyScope({}, 'function');
|
|
105
|
-
}
|
|
106
|
-
static classScope() {
|
|
107
|
-
return new ReadOnlyScope({}, 'class');
|
|
108
|
-
}
|
|
109
|
-
static moduleScope() {
|
|
110
|
-
return new ReadOnlyScope({}, 'module');
|
|
111
|
-
}
|
|
112
|
-
static globalScope() {
|
|
113
|
-
return new ReadOnlyScope({}, 'global');
|
|
66
|
+
static blockScope(propertyKeys) {
|
|
67
|
+
return new ReadOnlyScope({}, propertyKeys);
|
|
114
68
|
}
|
|
115
69
|
set(propertyKey, value, receiver) {
|
|
70
|
+
// do nothing
|
|
116
71
|
return false;
|
|
117
72
|
}
|
|
118
73
|
delete(propertyKey) {
|
|
74
|
+
// do nothing
|
|
119
75
|
return false;
|
|
120
76
|
}
|
|
77
|
+
getClass() {
|
|
78
|
+
return ReadOnlyScope;
|
|
79
|
+
}
|
|
121
80
|
}
|
|
122
81
|
export class ScopeSubscription {
|
|
123
82
|
constructor(propertyKey, observer) {
|
|
@@ -144,7 +103,7 @@ export class ValueChangeObserver {
|
|
|
144
103
|
return;
|
|
145
104
|
}
|
|
146
105
|
const subscribers = this.subscribers.get(propertyKey);
|
|
147
|
-
if (!subscribers) {
|
|
106
|
+
if (!subscribers || subscribers.size == 0) {
|
|
148
107
|
return;
|
|
149
108
|
}
|
|
150
109
|
this.propertiesLock.push(propertyKey);
|
|
@@ -190,49 +149,30 @@ export class ValueChangeObserver {
|
|
|
190
149
|
const subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);
|
|
191
150
|
subscriptionInfo && (subscriptionInfo.enable = true);
|
|
192
151
|
}
|
|
152
|
+
/**
|
|
153
|
+
* clear subscription maps
|
|
154
|
+
*/
|
|
193
155
|
destroy() {
|
|
194
156
|
this.subscribers.clear();
|
|
195
157
|
}
|
|
196
158
|
}
|
|
197
159
|
export class ReactiveScope extends Scope {
|
|
198
|
-
constructor(context,
|
|
199
|
-
super(context,
|
|
200
|
-
this.name = name;
|
|
160
|
+
constructor(context, name, parent, propertyKeys) {
|
|
161
|
+
super(context, Array.isArray(name) ? name : propertyKeys);
|
|
201
162
|
this.parent = parent;
|
|
202
163
|
this.observer = new ValueChangeObserver();
|
|
164
|
+
if (typeof name == 'string') {
|
|
165
|
+
this.name = name;
|
|
166
|
+
}
|
|
167
|
+
if (Array.isArray(name)) {
|
|
168
|
+
this.propertyKeys = name;
|
|
169
|
+
}
|
|
203
170
|
}
|
|
204
|
-
static for(context,
|
|
205
|
-
return new ReactiveScope(context,
|
|
206
|
-
}
|
|
207
|
-
static blockScopeFor(context) {
|
|
208
|
-
return new ReactiveScope(context, 'block');
|
|
209
|
-
}
|
|
210
|
-
static functionScopeFor(context) {
|
|
211
|
-
return new ReactiveScope(context, 'function');
|
|
212
|
-
}
|
|
213
|
-
static classScopeFor(context) {
|
|
214
|
-
return new ReactiveScope(context, 'class');
|
|
215
|
-
}
|
|
216
|
-
static moduleScopeFor(context) {
|
|
217
|
-
return new ReactiveScope(context, 'module');
|
|
218
|
-
}
|
|
219
|
-
static globalScopeFor(context) {
|
|
220
|
-
return new ReactiveScope(context, 'global');
|
|
221
|
-
}
|
|
222
|
-
static blockScope() {
|
|
223
|
-
return new ReactiveScope({}, 'block');
|
|
224
|
-
}
|
|
225
|
-
static functionScope() {
|
|
226
|
-
return new ReactiveScope({}, 'function');
|
|
227
|
-
}
|
|
228
|
-
static classScope() {
|
|
229
|
-
return new ReactiveScope({}, 'class');
|
|
230
|
-
}
|
|
231
|
-
static moduleScope() {
|
|
232
|
-
return new ReactiveScope({}, 'module');
|
|
171
|
+
static for(context, propertyKeys) {
|
|
172
|
+
return new ReactiveScope(context, propertyKeys);
|
|
233
173
|
}
|
|
234
|
-
static
|
|
235
|
-
return new ReactiveScope({},
|
|
174
|
+
static blockScope(propertyKeys) {
|
|
175
|
+
return new ReactiveScope({}, propertyKeys);
|
|
236
176
|
}
|
|
237
177
|
set(propertyKey, newValue, receiver) {
|
|
238
178
|
const oldValue = Reflect.get(this.context, propertyKey);
|
|
@@ -260,7 +200,7 @@ export class ReactiveScope extends Scope {
|
|
|
260
200
|
if (typeof scopeContext !== 'object') {
|
|
261
201
|
return;
|
|
262
202
|
}
|
|
263
|
-
scope = new ReactiveScope(scopeContext,
|
|
203
|
+
scope = new ReactiveScope(scopeContext, propertyKey, this);
|
|
264
204
|
this.scopeMap.set(propertyKey, scope);
|
|
265
205
|
return scope;
|
|
266
206
|
}
|
|
@@ -271,7 +211,7 @@ export class ReactiveScope extends Scope {
|
|
|
271
211
|
scope.context = scopeContext;
|
|
272
212
|
return scope;
|
|
273
213
|
}
|
|
274
|
-
scope = new ReactiveScope(scopeContext,
|
|
214
|
+
scope = new ReactiveScope(scopeContext, propertyKey, this);
|
|
275
215
|
this.scopeMap.set(propertyKey, scope);
|
|
276
216
|
return scope;
|
|
277
217
|
}
|
|
@@ -293,6 +233,9 @@ export class ReactiveScope extends Scope {
|
|
|
293
233
|
this.observer.destroy();
|
|
294
234
|
}
|
|
295
235
|
}
|
|
236
|
+
getClass() {
|
|
237
|
+
return ReactiveScope;
|
|
238
|
+
}
|
|
296
239
|
}
|
|
297
240
|
export class ReactiveScopeControl extends ReactiveScope {
|
|
298
241
|
constructor() {
|
|
@@ -300,38 +243,11 @@ export class ReactiveScopeControl extends ReactiveScope {
|
|
|
300
243
|
this.attached = true;
|
|
301
244
|
this.marked = {};
|
|
302
245
|
}
|
|
303
|
-
static for(context,
|
|
304
|
-
return new ReactiveScopeControl(context,
|
|
305
|
-
}
|
|
306
|
-
static blockScopeFor(context) {
|
|
307
|
-
return new ReactiveScopeControl(context, 'block');
|
|
308
|
-
}
|
|
309
|
-
static functionScopeFor(context) {
|
|
310
|
-
return new ReactiveScopeControl(context, 'function');
|
|
311
|
-
}
|
|
312
|
-
static classScopeFor(context) {
|
|
313
|
-
return new ReactiveScopeControl(context, 'class');
|
|
314
|
-
}
|
|
315
|
-
static moduleScopeFor(context) {
|
|
316
|
-
return new ReactiveScopeControl(context, 'module');
|
|
317
|
-
}
|
|
318
|
-
static globalScopeFor(context) {
|
|
319
|
-
return new ReactiveScopeControl(context, 'global');
|
|
320
|
-
}
|
|
321
|
-
static blockScope() {
|
|
322
|
-
return new ReactiveScopeControl({}, 'block');
|
|
323
|
-
}
|
|
324
|
-
static functionScope() {
|
|
325
|
-
return new ReactiveScopeControl({}, 'function');
|
|
246
|
+
static for(context, propertyKeys) {
|
|
247
|
+
return new ReactiveScopeControl(context, propertyKeys);
|
|
326
248
|
}
|
|
327
|
-
static
|
|
328
|
-
return new ReactiveScopeControl({},
|
|
329
|
-
}
|
|
330
|
-
static moduleScope() {
|
|
331
|
-
return new ReactiveScopeControl({}, 'module');
|
|
332
|
-
}
|
|
333
|
-
static globalScope() {
|
|
334
|
-
return new ReactiveScopeControl({}, 'global');
|
|
249
|
+
static blockScope(propertyKeys) {
|
|
250
|
+
return new ReactiveScopeControl({}, propertyKeys);
|
|
335
251
|
}
|
|
336
252
|
emit(propertyKey, newValue, oldValue) {
|
|
337
253
|
if (this.attached) {
|
|
@@ -341,6 +257,9 @@ export class ReactiveScopeControl extends ReactiveScope {
|
|
|
341
257
|
this.marked[propertyKey] = newValue;
|
|
342
258
|
}
|
|
343
259
|
}
|
|
260
|
+
isAttached() {
|
|
261
|
+
return this.attached;
|
|
262
|
+
}
|
|
344
263
|
detach() {
|
|
345
264
|
this.attached = false;
|
|
346
265
|
}
|
|
@@ -360,5 +279,24 @@ export class ReactiveScopeControl extends ReactiveScope {
|
|
|
360
279
|
super.emit(propertyKey, latestChanges[propertyKey]);
|
|
361
280
|
});
|
|
362
281
|
}
|
|
282
|
+
getClass() {
|
|
283
|
+
return ReactiveScopeControl;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
export class ModuleScope extends ReactiveScope {
|
|
287
|
+
constructor(context, propertyKeys) {
|
|
288
|
+
super(context, propertyKeys);
|
|
289
|
+
}
|
|
290
|
+
importModule(propertyKey, scope) {
|
|
291
|
+
this.scopeMap.set(propertyKey, scope);
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
export class WebModuleScope extends ModuleScope {
|
|
295
|
+
constructor() {
|
|
296
|
+
super({});
|
|
297
|
+
}
|
|
298
|
+
updateContext(context) {
|
|
299
|
+
this.context = context;
|
|
300
|
+
}
|
|
363
301
|
}
|
|
364
302
|
//# 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,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CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAChD,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC;QACrD,CAAC,CAAC,CAAC;IACJ,CAAC;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, propertyValue?: any): void;\n}\n\nexport class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends ScopeContext>(context: T, 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, propertyValue?: any): void {\n\t\tif (propertyKey) {\n\t\t\tsuper.emit(propertyKey, propertyValue);\n\t\t\tReflect.deleteProperty(this.marked, propertyKey);\n\t\t\treturn;\n\t\t}\n\t\tconst latestChanges = this.marked;\n\t\tthis.marked = {};\n\t\tObject.keys(latestChanges).forEach(propertyKey => {\n\t\t\tsuper.emit(propertyKey, latestChanges[propertyKey]);\n\t\t});\n\t}\n}\n"]}
|
|
1
|
+
{"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AA4DA,MAAM,OAAO,KAAK;IASjB,YAAsB,OAAU,EAAE,YAA0B;QAAtC,YAAO,GAAP,OAAO,CAAG;QAFtB,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;QAGnD,IAAI,CAAC,YAAY,GAAG,Y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B,EAAE,YAAsC;QACzE,KAAK,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IAC9B,CAAC;IACD,YAAY,CAAC,WAAgC,EAAE,KAAkB;QAChE,IAAI,CAAC,QAAQ,CAAC,GAAG,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IACvC,CAAC;CACD;AACD,MAAM,OAAO,cAAe,SAAQ,WAAW;IAC9C;QACC,KAAK,CAAC,EAAmB,CAAC,CAAC;IAC5B,CAAC;IACD,aAAa,CAAC,OAAY;QACzB,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC;IACxB,CAAC;CACD","sourcesContent":["import { TypeOf } from '../api/utils.js';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\n\n\t/**\n\t * get value of `propertyKey` in current context\n\t * @param propertyKey \n\t */\n\tget(propertyKey: keyof T): any;\n\n\t/**\n\t * set the value of `propertyKey` in current context, could be instilled with `value`.\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: keyof T, value?: any, receiver?: any): boolean;\n\n\t/**\n\t * is current context has `propertyKey` in hash map keys\n\t * @param propertyKey \n\t */\n\thas(propertyKey: keyof T): boolean;\n\n\t/**\n\t * delete property from context\n\t * @param propertyKey \n\t */\n\tdelete(propertyKey: keyof T): boolean;\n\n\t/**\n\t * get current context object of this scope\n\t */\n\tgetContext(): T;\n\n\t/**\n\t * get a proxy of the current context object if exists. \n\t */\n\tgetContextProxy?(): T;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if the current value is not type od `object`, will return `undefined`.\n\t * @param propertyKey the name of the property\n\t */\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if no scope found in the cache, will create a new one, add this one to the map, return a reference.\n\t * @param propertyKey\n\t */\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;\n\n\tgetClass(): TypeOf<Scope<ScopeContext>>;\n}\n\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new Scope({} as T, propertyKeys);\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tprotected propertyKeys?: (keyof T)[];\n\tconstructor(protected context: T, propertyKeys?: (keyof T)[]) {\n\t\tthis.propertyKeys = propertyKeys;\n\t\tif (Array.isArray(this.propertyKeys)) {\n\t\t\tthis.has = (propertyKey: keyof T): boolean => {\n\t\t\t\treturn this.propertyKeys!.includes(propertyKey);\n\t\t\t};\n\t\t}\n\t}\n\tget(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.context, propertyKey);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this.context, propertyKey, value);\n\t}\n\thas(propertyKey: keyof T): boolean {\n\t\treturn propertyKey in this.context;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this.context, propertyKey);\n\t}\n\tgetContext(): T {\n\t\treturn this.context;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new (this.getClass())(scopeContext);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V> {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new (this.getClass())(scopeContext);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetClass(): TypeOf<Scope<ScopeContext>> {\n\t\treturn Scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReadOnlyScope({} as T, propertyKeys);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tgetClass(): TypeOf<ReadOnlyScope<ScopeContext>> {\n\t\treturn ReadOnlyScope;\n\t}\n}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<T>) { }\n\tpause() {\n\t\tthis.observer.pause(this.propertyKey, this);\n\t}\n\tresume() {\n\t\tthis.observer.resume(this.propertyKey, this);\n\t}\n\tunsubscribe(): void {\n\t\tthis.observer.unsubscribe(this.propertyKey, this);\n\t}\n}\n\nexport type ValueChangedCallback = (newValue: any, oldValue?: any) => void;\n\ntype SubscriptionInfo = { callback: ValueChangedCallback, enable: boolean };\n\nexport class ValueChangeObserver<T> {\n\tprivate subscribers: Map<keyof T, Map<ScopeSubscription<T>, SubscriptionInfo>> = new Map();\n\tprivate propertiesLock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.propertiesLock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this.subscribers.get(propertyKey);\n\t\tif (!subscribers || subscribers.size == 0) {\n\t\t\treturn;\n\t\t}\n\t\tthis.propertiesLock.push(propertyKey);\n\t\tsubscribers?.forEach(subscriptionInfo => {\n\t\t\tif (!subscriptionInfo.enable) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tsubscriptionInfo.callback(newValue, oldValue);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e);\n\t\t\t}\n\t\t});\n\t\tif (this.propertiesLock.pop() !== propertyKey) {\n\t\t\tconsole.error('lock error');\n\t\t};\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\tconst subscription: ScopeSubscription<T> = new ScopeSubscription(propertyKey, this);\n\t\tlet propertySubscribers = this.subscribers.get(propertyKey);\n\t\tif (!propertySubscribers) {\n\t\t\tpropertySubscribers = new Map();\n\t\t\tthis.subscribers.set(propertyKey, propertySubscribers);\n\t\t}\n\t\tpropertySubscribers.set(subscription, { callback, enable: true });\n\t\treturn subscription;\n\t}\n\n\tunsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (subscription) {\n\t\t\tthis.subscribers.get(propertyKey)?.delete(subscription);\n\t\t} else {\n\t\t\tthis.subscribers.delete(propertyKey);\n\t\t}\n\t}\n\n\tpause(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = false);\n\t}\n\n\tresume(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = true);\n\t}\n\n\t/**\n\t * clear subscription maps\n\t */\n\tdestroy() {\n\t\tthis.subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScope({} as T, propertyKeys);\n\t}\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\tprotected name?: string;\n\n\tconstructor(context: T, propertyKeys?: (keyof T)[]);\n\tconstructor(context: T, name: string, parent: ReactiveScope<any>, propertyKeys?: (keyof T)[]);\n\tconstructor(context: T, name?: string | (keyof T)[], protected parent?: ReactiveScope<any>, propertyKeys?: (keyof T)[]) {\n\t\tsuper(context, Array.isArray(name) ? name : propertyKeys);\n\t\tif (typeof name == 'string') {\n\t\t\tthis.name = name;\n\t\t}\n\t\tif (Array.isArray(name)) {\n\t\t\tthis.propertyKeys = name;\n\t\t}\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst result = Reflect.set(this.context, propertyKey, newValue);\n\t\tif (result) {\n\t\t\tthis.emit(propertyKey, newValue, oldValue);\n\t\t}\n\t\treturn result;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this.context, propertyKey);\n\t\tif (isDelete && oldValue !== undefined) {\n\t\t\tthis.emit(propertyKey, undefined, oldValue);\n\t\t}\n\t\treturn isDelete;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tthis.observer.emit(propertyKey, newValue, oldValue);\n\t\tthis.parent?.emit(this.name!, this.context);\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\treturn this.observer.subscribe(propertyKey, callback);\n\t}\n\tunsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (propertyKey && subscription) {\n\t\t\tthis.observer.unsubscribe(propertyKey, subscription);\n\t\t} else if (propertyKey) {\n\t\t\tthis.observer.unsubscribe(propertyKey);\n\t\t} else {\n\t\t\tthis.observer.destroy();\n\t\t}\n\t}\n\tgetClass(): TypeOf<ReactiveScope<ScopeContext>> {\n\t\treturn ReactiveScope;\n\t}\n}\n\n/**\n * used control/notify/pause scope about changes in current context\n */\nexport interface ScopeControl<T extends ScopeContext> {\n\n\t/**\n\t * get current stacte of applying change detection.\n\t */\n\tisAttached(): boolean;\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * apply changes now,\n\t * will not effect the state of the detector wither if attached ot not.\n\t * \n\t * if a propertyKey is provided, will emit this property only \n\t * @param propertyKey \n\t */\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void;\n}\n\nexport class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl(context, propertyKeys);\n\t}\n\tstatic blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]) {\n\t\treturn new ReactiveScopeControl({} as T, propertyKeys);\n\t}\n\n\tprotected attached: boolean = true;\n\tprotected marked: ScopeContext = {};\n\toverride emit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.attached) {\n\t\t\tsuper.emit(propertyKey, newValue, oldValue);\n\t\t} else {\n\t\t\tthis.marked[propertyKey] = newValue;\n\t\t}\n\t}\n\tisAttached(): boolean {\n\t\treturn this.attached;\n\t}\n\tdetach(): void {\n\t\tthis.attached = false;\n\t}\n\treattach(): void {\n\t\tthis.attached = true;\n\t\tthis.emitChanges();\n\t}\n\temitChanges(propertyKey?: keyof T, propertyValue?: any): void {\n\t\tif (propertyKey) {\n\t\t\tsuper.emit(propertyKey, propertyValue);\n\t\t\tReflect.deleteProperty(this.marked, propertyKey);\n\t\t\treturn;\n\t\t}\n\t\tconst latestChanges = this.marked;\n\t\tthis.marked = {};\n\t\tObject.keys(latestChanges).forEach(propertyKey => {\n\t\t\tsuper.emit(propertyKey, latestChanges[propertyKey]);\n\t\t});\n\t}\n\tgetClass(): TypeOf<ReactiveScopeControl<ScopeContext>> {\n\t\treturn ReactiveScopeControl;\n\t}\n}\n\n\ninterface ImportMeta {\n\turl: URL;\n\t/**\n\t *\n\t * Provides a module-relative resolution function scoped to each module, returning\n\t * the URL string.\n\t *\n\t * @param specified The module specifier to resolve relative to `parent`.\n\t * @param parent The absolute parent module URL to resolve from. If none\n\t * is specified, the value of `import.meta.url` is used as the default.\n\t */\n\tresolve?(specified: string, parent?: string | URL): Promise<string>;\n}\n\nexport interface ModuleImport {\n\tmeta: ImportMeta\n}\n\nexport interface ModuleContext extends ScopeContext {\n\timport: ModuleImport & ((path: string) => Promise<any>);\n}\n\nexport class ModuleScope extends ReactiveScope<ModuleContext> {\n\tconstructor(context: ModuleContext, propertyKeys?: (keyof ModuleContext)[]) {\n\t\tsuper(context, propertyKeys);\n\t}\n\timportModule(propertyKey: keyof ModuleContext, scope: ModuleScope): void {\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t}\n}\nexport class WebModuleScope extends ModuleScope {\n\tconstructor() {\n\t\tsuper({} as ModuleContext);\n\t}\n\tupdateContext(context: any) {\n\t\tthis.context = context;\n\t}\n}\n"]}
|