@ibyar/expressions 0.5.62 → 0.6.0

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/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,16 +1,10 @@
1
- import type { Scope, ScopeContext } from './scope.js';
2
- export declare class FunctionProxyHandler<T extends Function> implements ProxyHandler<T> {
3
- private thisContext;
4
- constructor(thisContext: object);
5
- apply(targetFunc: T, targetThisArg: any, argArray: any[]): any;
6
- private computeThisArg;
7
- }
1
+ import type { Scope, Context } from './scope.js';
2
+ export declare function hasBindingHook<T>(ctx: T): boolean;
8
3
  /**
9
4
  * crete new proxy handler object as scoped context
10
5
  */
11
- export declare class ScopeProxyHandler<T extends ScopeContext> implements ProxyHandler<ScopeContext> {
6
+ export declare class ScopeProxyHandler<T extends Context> implements ProxyHandler<Context> {
12
7
  private scope;
13
- private functionHandler;
14
8
  constructor(scope: Scope<T>);
15
9
  has(model: T, propertyKey: PropertyKey): boolean;
16
10
  get(model: T, propertyKey: PropertyKey, receiver: any): any;
package/scope/proxy.js CHANGED
@@ -1,30 +1,23 @@
1
- export class FunctionProxyHandler {
2
- constructor(thisContext) {
3
- this.thisContext = thisContext;
4
- }
5
- apply(targetFunc, targetThisArg, argArray) {
6
- return targetFunc.apply(this.computeThisArg(targetThisArg), argArray);
7
- }
8
- computeThisArg(targetThisArg) {
9
- switch (true) {
10
- // exclude classes that have binding hook
11
- case this.thisContext instanceof Map:
12
- case this.thisContext instanceof Set:
13
- case this.thisContext instanceof Date:
14
- case this.thisContext instanceof WeakMap:
15
- case this.thisContext instanceof WeakSet:
16
- case this.thisContext instanceof Promise:
17
- case this.thisContext instanceof HTMLElement:
18
- return this.thisContext;
19
- default:
20
- return targetThisArg;
21
- }
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;
22
14
  }
23
15
  }
24
16
  /**
25
17
  * crete new proxy handler object as scoped context
26
18
  */
27
19
  export class ScopeProxyHandler {
20
+ // private functionHandler: FunctionProxyHandler<Function>;
28
21
  constructor(scope) {
29
22
  this.scope = scope;
30
23
  }
@@ -33,20 +26,14 @@ export class ScopeProxyHandler {
33
26
  }
34
27
  get(model, propertyKey, receiver) {
35
28
  const value = this.scope.get(propertyKey);
36
- if (value == null) {
29
+ if (!(value && typeof value === 'object')) {
37
30
  return value;
38
31
  }
39
- if (typeof value === 'object') {
40
- const scope = this.scope.getScope(propertyKey);
41
- if (scope) {
42
- return new Proxy(value, new ScopeProxyHandler(scope));
43
- }
44
- }
45
- else if (typeof value === 'function') {
46
- return new Proxy(value, this.functionHandler
47
- ?? (this.functionHandler = new FunctionProxyHandler(this.scope.getContext())));
32
+ const scope = this.scope.getInnerScope(propertyKey);
33
+ if (!scope) {
34
+ return value;
48
35
  }
49
- return value;
36
+ return createProxyForContext(scope);
50
37
  }
51
38
  set(model, propertyKey, value, receiver) {
52
39
  return this.scope.set(propertyKey, value);
@@ -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,cAAc,CAAC,aAAa,CAAC,EAAE,QAAQ,CAA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,KAAK,EAAE,IAAI,CAAC,eAAe;mBACxC,CAAC,IAAI,CAAC,eAAe,GAAG,IAAI,oBAAoB,CAAC,IAAI,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAC7E,CAAC;SACF;QACD,OAAO,KAAK,CAAC;IACd,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, 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"]}
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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AAC,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,8 +1,6 @@
1
1
  import { TypeOf } from '../api/utils.js';
2
- export declare type ScopeContext = {
3
- [key: PropertyKey]: ScopeContext | any;
4
- };
5
- export interface Scope<T = ScopeContext> {
2
+ export declare type Context = Record<PropertyKey, any>;
3
+ export interface Scope<T = Context> {
6
4
  /**
7
5
  * get value of `propertyKey` in current context
8
6
  * @param propertyKey
@@ -39,30 +37,53 @@ export interface Scope<T = ScopeContext> {
39
37
  * if the current value is not type od `object`, will return `undefined`.
40
38
  * @param propertyKey the name of the property
41
39
  */
42
- getScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;
40
+ getInnerScope<S extends Scope<Context>>(propertyKey: keyof T): S | undefined;
43
41
  /**
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.
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
47
  * @param propertyKey
48
+ * @param scope
48
49
  */
49
- getScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;
50
- getClass(): TypeOf<Scope<ScopeContext>>;
50
+ setInnerScope<S extends Scope<Context>>(propertyKey: keyof T, scope?: S): S;
51
+ getClass(): TypeOf<Scope<Context>>;
51
52
  }
52
- export declare class Scope<T extends ScopeContext> implements Scope<T> {
53
- protected context: 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>;
56
- protected scopeMap: Map<keyof T, Scope<any>>;
57
- protected propertyKeys?: (keyof T)[];
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>>;
58
59
  constructor(context: T, propertyKeys?: (keyof T)[]);
59
60
  }
60
- export declare class ReadOnlyScope<T extends ScopeContext> extends Scope<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>;
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>;
63
84
  set(propertyKey: keyof T, value: any, receiver?: any): boolean;
64
85
  delete(propertyKey: keyof T): boolean;
65
- getClass(): TypeOf<ReadOnlyScope<ScopeContext>>;
86
+ getClass(): TypeOf<ReadOnlyScope<Context>>;
66
87
  }
67
88
  export declare class ScopeSubscription<T> {
68
89
  private propertyKey;
@@ -74,39 +95,56 @@ export declare class ScopeSubscription<T> {
74
95
  }
75
96
  export declare type ValueChangedCallback = (newValue: any, oldValue?: any) => void;
76
97
  export declare class ValueChangeObserver<T> {
77
- private subscribers;
78
- private propertiesLock;
98
+ private _subscribers;
99
+ private _lock;
79
100
  emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
80
101
  subscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T>;
81
102
  unsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>): void;
82
103
  pause(propertyKey: keyof T, subscription: ScopeSubscription<T>): void;
83
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;
84
115
  /**
85
116
  * clear subscription maps
86
117
  */
87
118
  destroy(): void;
88
119
  }
89
- export declare class ReactiveScope<T extends ScopeContext> extends Scope<T> {
90
- protected parent?: ReactiveScope<any> | undefined;
91
- static for<T extends ScopeContext>(context: T, propertyKeys?: (keyof T)[]): ReactiveScope<T>;
92
- static blockScope<T extends ScopeContext>(propertyKeys?: (keyof T)[]): ReactiveScope<T>;
93
- protected observer: ValueChangeObserver<T>;
94
- protected name?: string;
95
- constructor(context: T, propertyKeys?: (keyof T)[]);
96
- constructor(context: T, name: string, parent: ReactiveScope<any>, propertyKeys?: (keyof T)[]);
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);
97
135
  set(propertyKey: keyof T, newValue: any, receiver?: any): boolean;
98
136
  delete(propertyKey: keyof T): boolean;
99
- getScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined;
100
- getScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V>;
101
137
  emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
102
138
  subscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T>;
103
139
  unsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>): void;
104
- getClass(): TypeOf<ReactiveScope<ScopeContext>>;
140
+ detectChanges(): void;
141
+ protected getPropertyKeys<V extends Record<PropertyKey, any>>(...objs: V[]): (keyof V)[];
142
+ getClass(): TypeOf<ReactiveScope<Context>>;
105
143
  }
106
144
  /**
107
145
  * used control/notify/pause scope about changes in current context
108
146
  */
109
- export interface ScopeControl<T extends ScopeContext> {
147
+ export interface ScopeControl<T extends Context> {
110
148
  /**
111
149
  * get current stacte of applying change detection.
112
150
  */
@@ -128,18 +166,35 @@ export interface ScopeControl<T extends ScopeContext> {
128
166
  * @param propertyKey
129
167
  */
130
168
  emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
169
+ /**
170
+ * throw error if any changes has been made
171
+ */
172
+ checkNoChanges(): void;
131
173
  }
132
- export declare class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<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>;
135
- protected attached: boolean;
136
- protected marked: ScopeContext;
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
+ };
137
190
  emit(propertyKey: keyof T, newValue: any, oldValue?: any): void;
138
191
  isAttached(): boolean;
139
192
  detach(): void;
140
193
  reattach(): void;
141
194
  emitChanges(propertyKey?: keyof T, propertyValue?: any): void;
142
- getClass(): TypeOf<ReactiveScopeControl<ScopeContext>>;
195
+ detectChanges(): void;
196
+ checkNoChanges(): void;
197
+ getClass(): TypeOf<ReactiveScopeControl<Context>>;
143
198
  }
144
199
  interface ImportMeta {
145
200
  url: URL;
@@ -157,7 +212,7 @@ interface ImportMeta {
157
212
  export interface ModuleImport {
158
213
  meta: ImportMeta;
159
214
  }
160
- export interface ModuleContext extends ScopeContext {
215
+ export interface ModuleContext extends Context {
161
216
  import: ModuleImport & ((path: string) => Promise<any>);
162
217
  }
163
218
  export declare class ModuleScope extends ReactiveScope<ModuleContext> {