@ibyar/expressions 0.5.1 → 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (187) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +5 -4
  3. package/api/abstract.d.ts +5 -6
  4. package/api/abstract.js +3 -3
  5. package/api/abstract.js.map +1 -1
  6. package/api/class/class.d.ts +202 -0
  7. package/api/class/class.js +635 -0
  8. package/api/class/class.js.map +1 -0
  9. package/api/class/decorator.d.ts +20 -0
  10. package/api/class/decorator.js +48 -0
  11. package/api/class/decorator.js.map +1 -0
  12. package/api/computing/call.d.ts +3 -1
  13. package/api/computing/call.js +16 -4
  14. package/api/computing/call.js.map +1 -1
  15. package/api/computing/debugger.d.ts +15 -0
  16. package/api/computing/debugger.js +35 -0
  17. package/api/computing/debugger.js.map +1 -0
  18. package/api/computing/new.d.ts +2 -1
  19. package/api/computing/new.js +4 -0
  20. package/api/computing/new.js.map +1 -1
  21. package/api/computing/rest.d.ts +6 -6
  22. package/api/computing/rest.js +5 -2
  23. package/api/computing/rest.js.map +1 -1
  24. package/api/computing/return.d.ts +2 -1
  25. package/api/computing/return.js +3 -0
  26. package/api/computing/return.js.map +1 -1
  27. package/api/computing/spread.d.ts +2 -1
  28. package/api/computing/spread.js +5 -2
  29. package/api/computing/spread.js.map +1 -1
  30. package/api/computing/throw.d.ts +2 -1
  31. package/api/computing/throw.js +3 -0
  32. package/api/computing/throw.js.map +1 -1
  33. package/api/computing/yield.d.ts +2 -1
  34. package/api/computing/yield.js +3 -0
  35. package/api/computing/yield.js.map +1 -1
  36. package/api/definition/array.d.ts +12 -12
  37. package/api/definition/array.js +31 -25
  38. package/api/definition/array.js.map +1 -1
  39. package/api/definition/bind.d.ts +2 -2
  40. package/api/definition/bind.js +1 -1
  41. package/api/definition/bind.js.map +1 -1
  42. package/api/definition/function.d.ts +40 -51
  43. package/api/definition/function.js +291 -309
  44. package/api/definition/function.js.map +1 -1
  45. package/api/definition/member.d.ts +2 -2
  46. package/api/definition/member.js +1 -1
  47. package/api/definition/member.js.map +1 -1
  48. package/api/definition/object.d.ts +15 -12
  49. package/api/definition/object.js +43 -13
  50. package/api/definition/object.js.map +1 -1
  51. package/api/definition/statement.d.ts +2 -2
  52. package/api/definition/statement.js +7 -3
  53. package/api/definition/statement.js.map +1 -1
  54. package/api/definition/values.d.ts +35 -50
  55. package/api/definition/values.js +66 -149
  56. package/api/definition/values.js.map +1 -1
  57. package/api/deserialize/deserialize.d.ts +2 -1
  58. package/api/deserialize/deserialize.js +4 -1
  59. package/api/deserialize/deserialize.js.map +1 -1
  60. package/api/deserialize/type-store.d.ts +2 -2
  61. package/api/deserialize/type-store.js.map +1 -1
  62. package/api/expression.d.ts +13 -18
  63. package/api/expression.js.map +1 -1
  64. package/api/index.d.ts +2 -0
  65. package/api/index.js +2 -0
  66. package/api/index.js.map +1 -1
  67. package/api/module/common.d.ts +29 -0
  68. package/api/module/common.js +71 -0
  69. package/api/module/common.js.map +1 -0
  70. package/api/module/export.d.ts +66 -25
  71. package/api/module/export.js +270 -58
  72. package/api/module/export.js.map +1 -1
  73. package/api/module/import.d.ts +61 -25
  74. package/api/module/import.js +226 -68
  75. package/api/module/import.js.map +1 -1
  76. package/api/operators/assignment.d.ts +2 -2
  77. package/api/operators/assignment.js +1 -1
  78. package/api/operators/assignment.js.map +1 -1
  79. package/api/operators/await.d.ts +2 -2
  80. package/api/operators/await.js +1 -1
  81. package/api/operators/await.js.map +1 -1
  82. package/api/operators/binary.d.ts +2 -2
  83. package/api/operators/binary.js +1 -1
  84. package/api/operators/binary.js.map +1 -1
  85. package/api/operators/chaining.d.ts +2 -2
  86. package/api/operators/chaining.js +1 -1
  87. package/api/operators/chaining.js.map +1 -1
  88. package/api/operators/comma.d.ts +2 -2
  89. package/api/operators/comma.js +2 -2
  90. package/api/operators/comma.js.map +1 -1
  91. package/api/operators/grouping.d.ts +2 -2
  92. package/api/operators/grouping.js +1 -1
  93. package/api/operators/grouping.js.map +1 -1
  94. package/api/operators/logical.d.ts +2 -2
  95. package/api/operators/logical.js +1 -1
  96. package/api/operators/logical.js.map +1 -1
  97. package/api/operators/pipeline.d.ts +2 -2
  98. package/api/operators/pipeline.js +1 -1
  99. package/api/operators/pipeline.js.map +1 -1
  100. package/api/operators/ternary.d.ts +2 -2
  101. package/api/operators/ternary.js +1 -1
  102. package/api/operators/ternary.js.map +1 -1
  103. package/api/operators/unary.d.ts +3 -3
  104. package/api/operators/unary.js +4 -3
  105. package/api/operators/unary.js.map +1 -1
  106. package/api/operators/update.d.ts +2 -2
  107. package/api/operators/update.js +1 -1
  108. package/api/operators/update.js.map +1 -1
  109. package/api/{app/program.d.ts → program.d.ts} +8 -9
  110. package/api/program.js +45 -0
  111. package/api/program.js.map +1 -0
  112. package/api/statement/control/block.d.ts +4 -5
  113. package/api/statement/control/block.js +22 -23
  114. package/api/statement/control/block.js.map +1 -1
  115. package/api/statement/control/empty.d.ts +1 -1
  116. package/api/statement/control/empty.js.map +1 -1
  117. package/api/statement/control/if.d.ts +2 -2
  118. package/api/statement/control/if.js +1 -1
  119. package/api/statement/control/if.js.map +1 -1
  120. package/api/statement/control/switch.d.ts +4 -5
  121. package/api/statement/control/switch.js +13 -9
  122. package/api/statement/control/switch.js.map +1 -1
  123. package/api/statement/control/terminate.d.ts +38 -13
  124. package/api/statement/control/terminate.js +81 -20
  125. package/api/statement/control/terminate.js.map +1 -1
  126. package/api/statement/declarations/declares.d.ts +17 -16
  127. package/api/statement/declarations/declares.js +24 -19
  128. package/api/statement/declarations/declares.js.map +1 -1
  129. package/api/statement/iterations/for.d.ts +5 -5
  130. package/api/statement/iterations/for.js +29 -23
  131. package/api/statement/iterations/for.js.map +1 -1
  132. package/api/statement/iterations/while.d.ts +3 -3
  133. package/api/statement/iterations/while.js +17 -13
  134. package/api/statement/iterations/while.js.map +1 -1
  135. package/api/utils.d.ts +5 -0
  136. package/api/utils.js +4 -0
  137. package/api/utils.js.map +1 -0
  138. package/package.json +5 -5
  139. package/scope/event.d.ts +2 -2
  140. package/scope/event.js +8 -14
  141. package/scope/event.js.map +1 -1
  142. package/scope/finalizer.d.ts +4 -0
  143. package/scope/finalizer.js +11 -0
  144. package/scope/finalizer.js.map +1 -0
  145. package/scope/proxy.d.ts +2 -3
  146. package/scope/proxy.js +22 -26
  147. package/scope/proxy.js.map +1 -1
  148. package/scope/scope.d.ts +42 -53
  149. package/scope/scope.js +73 -143
  150. package/scope/scope.js.map +1 -1
  151. package/scope/stack.d.ts +43 -26
  152. package/scope/stack.js +148 -102
  153. package/scope/stack.js.map +1 -1
  154. package/v8/enums.d.ts +204 -0
  155. package/v8/enums.js +375 -0
  156. package/v8/enums.js.map +1 -0
  157. package/v8/index.d.ts +2 -1
  158. package/v8/index.js +2 -1
  159. package/v8/index.js.map +1 -1
  160. package/v8/inline.d.ts +177 -0
  161. package/v8/inline.js +1973 -0
  162. package/v8/inline.js.map +1 -0
  163. package/v8/nodes.d.ts +8 -7
  164. package/v8/nodes.js +37 -63
  165. package/v8/nodes.js.map +1 -1
  166. package/v8/parser.d.ts +41 -151
  167. package/v8/parser.js +507 -1578
  168. package/v8/parser.js.map +1 -1
  169. package/v8/stream.d.ts +35 -3
  170. package/v8/stream.js +616 -164
  171. package/v8/stream.js.map +1 -1
  172. package/v8/token.d.ts +15 -9
  173. package/v8/token.js +79 -46
  174. package/v8/token.js.map +1 -1
  175. package/visit/visitor.js +4 -7
  176. package/visit/visitor.js.map +1 -1
  177. package/api/app/class.d.ts +0 -117
  178. package/api/app/class.js +0 -292
  179. package/api/app/class.js.map +0 -1
  180. package/api/app/program.js +0 -39
  181. package/api/app/program.js.map +0 -1
  182. package/api/module/module.d.ts +0 -26
  183. package/api/module/module.js +0 -63
  184. package/api/module/module.js.map +0 -1
  185. package/v8/app.d.ts +0 -0
  186. package/v8/app.js +0 -2
  187. package/v8/app.js.map +0 -1
package/scope/scope.js CHANGED
@@ -1,41 +1,19 @@
1
1
  export class Scope {
2
- constructor(context, type) {
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, type) {
8
- return new Scope(context, type);
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 globalScope() {
38
- return new Scope({}, 'global');
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 Scope(scopeContext, 'block');
43
+ scope = new (this.getClass())(scopeContext);
66
44
  this.scopeMap.set(propertyKey, scope);
67
45
  return scope;
68
46
  }
@@ -73,44 +51,20 @@ export class Scope {
73
51
  scope.context = scopeContext;
74
52
  return scope;
75
53
  }
76
- scope = new Scope(scopeContext, 'block');
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, type) {
83
- return new ReadOnlyScope(context, type);
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 moduleScopeFor(context) {
95
- return new ReadOnlyScope(context, 'module');
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) {
116
70
  return false;
@@ -118,6 +72,9 @@ export class ReadOnlyScope extends Scope {
118
72
  delete(propertyKey) {
119
73
  return false;
120
74
  }
75
+ getClass() {
76
+ return ReadOnlyScope;
77
+ }
121
78
  }
122
79
  export class ScopeSubscription {
123
80
  constructor(propertyKey, observer) {
@@ -144,7 +101,7 @@ export class ValueChangeObserver {
144
101
  return;
145
102
  }
146
103
  const subscribers = this.subscribers.get(propertyKey);
147
- if (!subscribers) {
104
+ if (!subscribers || subscribers.size == 0) {
148
105
  return;
149
106
  }
150
107
  this.propertiesLock.push(propertyKey);
@@ -195,44 +152,22 @@ export class ValueChangeObserver {
195
152
  }
196
153
  }
197
154
  export class ReactiveScope extends Scope {
198
- constructor(context, type, name, parent) {
199
- super(context, type);
200
- this.name = name;
155
+ constructor(context, name, parent, propertyKeys) {
156
+ super(context, Array.isArray(name) ? name : propertyKeys);
201
157
  this.parent = parent;
202
158
  this.observer = new ValueChangeObserver();
159
+ if (typeof name == 'string') {
160
+ this.name = name;
161
+ }
162
+ if (Array.isArray(name)) {
163
+ this.propertyKeys = name;
164
+ }
203
165
  }
204
- static for(context, type) {
205
- return new ReactiveScope(context, type);
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');
166
+ static for(context, propertyKeys) {
167
+ return new ReactiveScope(context, propertyKeys);
233
168
  }
234
- static globalScope() {
235
- return new ReactiveScope({}, 'global');
169
+ static blockScope(propertyKeys) {
170
+ return new ReactiveScope({}, propertyKeys);
236
171
  }
237
172
  set(propertyKey, newValue, receiver) {
238
173
  const oldValue = Reflect.get(this.context, propertyKey);
@@ -260,7 +195,7 @@ export class ReactiveScope extends Scope {
260
195
  if (typeof scopeContext !== 'object') {
261
196
  return;
262
197
  }
263
- scope = new ReactiveScope(scopeContext, 'block', propertyKey, this);
198
+ scope = new ReactiveScope(scopeContext, propertyKey, this);
264
199
  this.scopeMap.set(propertyKey, scope);
265
200
  return scope;
266
201
  }
@@ -271,7 +206,7 @@ export class ReactiveScope extends Scope {
271
206
  scope.context = scopeContext;
272
207
  return scope;
273
208
  }
274
- scope = new ReactiveScope(scopeContext, 'block', propertyKey, this);
209
+ scope = new ReactiveScope(scopeContext, propertyKey, this);
275
210
  this.scopeMap.set(propertyKey, scope);
276
211
  return scope;
277
212
  }
@@ -293,6 +228,9 @@ export class ReactiveScope extends Scope {
293
228
  this.observer.destroy();
294
229
  }
295
230
  }
231
+ getClass() {
232
+ return ReactiveScope;
233
+ }
296
234
  }
297
235
  export class ReactiveScopeControl extends ReactiveScope {
298
236
  constructor() {
@@ -300,38 +238,11 @@ export class ReactiveScopeControl extends ReactiveScope {
300
238
  this.attached = true;
301
239
  this.marked = {};
302
240
  }
303
- static for(context, type) {
304
- return new ReactiveScopeControl(context, type);
305
- }
306
- static blockScopeFor(context) {
307
- return new ReactiveScopeControl(context, 'block');
308
- }
309
- static functionScopeFor(context) {
310
- return new ReactiveScopeControl(context, 'function');
311
- }
312
- static classScopeFor(context) {
313
- return new ReactiveScopeControl(context, 'class');
314
- }
315
- static moduleScopeFor(context) {
316
- return new ReactiveScopeControl(context, 'module');
317
- }
318
- static globalScopeFor(context) {
319
- return new ReactiveScopeControl(context, 'global');
320
- }
321
- static blockScope() {
322
- return new ReactiveScopeControl({}, 'block');
323
- }
324
- static functionScope() {
325
- return new ReactiveScopeControl({}, 'function');
326
- }
327
- static classScope() {
328
- return new ReactiveScopeControl({}, 'class');
241
+ static for(context, propertyKeys) {
242
+ return new ReactiveScopeControl(context, propertyKeys);
329
243
  }
330
- static moduleScope() {
331
- return new ReactiveScopeControl({}, 'module');
332
- }
333
- static globalScope() {
334
- return new ReactiveScopeControl({}, 'global');
244
+ static blockScope(propertyKeys) {
245
+ return new ReactiveScopeControl({}, propertyKeys);
335
246
  }
336
247
  emit(propertyKey, newValue, oldValue) {
337
248
  if (this.attached) {
@@ -341,6 +252,9 @@ export class ReactiveScopeControl extends ReactiveScope {
341
252
  this.marked[propertyKey] = newValue;
342
253
  }
343
254
  }
255
+ isAttached() {
256
+ return this.attached;
257
+ }
344
258
  detach() {
345
259
  this.attached = false;
346
260
  }
@@ -348,20 +262,36 @@ export class ReactiveScopeControl extends ReactiveScope {
348
262
  this.attached = true;
349
263
  this.emitChanges();
350
264
  }
351
- emitChanges(propertyKey) {
265
+ emitChanges(propertyKey, propertyValue) {
352
266
  if (propertyKey) {
353
- if (propertyKey in this.marked) {
354
- const lastValue = this.marked[propertyKey];
355
- Reflect.deleteProperty(this.marked, propertyKey);
356
- super.emit(propertyKey, lastValue);
357
- }
267
+ super.emit(propertyKey, propertyValue);
268
+ Reflect.deleteProperty(this.marked, propertyKey);
358
269
  return;
359
270
  }
360
- const oldChanges = this.marked;
271
+ const latestChanges = this.marked;
361
272
  this.marked = {};
362
- Object.keys(oldChanges).forEach(propertyKey => {
363
- super.emit(propertyKey, oldChanges[propertyKey]);
273
+ Object.keys(latestChanges).forEach(propertyKey => {
274
+ super.emit(propertyKey, latestChanges[propertyKey]);
364
275
  });
365
276
  }
277
+ getClass() {
278
+ return ReactiveScopeControl;
279
+ }
280
+ }
281
+ export class ModuleScope extends ReactiveScope {
282
+ constructor(context, propertyKeys) {
283
+ super(context, propertyKeys);
284
+ }
285
+ importModule(propertyKey, scope) {
286
+ this.scopeMap.set(propertyKey, scope);
287
+ }
288
+ }
289
+ export class WebModuleScope extends ModuleScope {
290
+ constructor() {
291
+ super({});
292
+ }
293
+ updateContext(context) {
294
+ this.context = context;
295
+ }
366
296
  }
367
297
  //# sourceMappingURL=scope.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"scope.js","sourceRoot":"","sources":["../../../src/expressions/scope/scope.ts"],"names":[],"mappings":"AA2DA,MAAM,OAAO,KAAK;IAmCjB,YAAsB,OAAU,EAAS,IAAe;QAAlC,YAAO,GAAP,OAAO,CAAG;QAAS,SAAI,GAAJ,IAAI,CAAW;QAD9C,aAAQ,GAAG,IAAI,GAAG,EAAuB,CAAC;IACQ,CAAC;IAlC7D,MAAM,CAAC,GAAG,CAAyB,OAAU,EAAE,IAAe;QAC7D,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IACjC,CAAC;IACD,MAAM,CAAC,aAAa,CAAyB,OAAU;QACtD,OAAO,IAAI,KAAK,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;IACpC,CAA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CAAC,MAAM,CAAC;QAC/B,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,MAAM,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE;YAC7C,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,CAAC,CAAC;QAClD,CAAC,CAAC,CAAC;IACJ,CAAC;CACD","sourcesContent":["\nexport type ScopeType = 'block' | 'function' | 'class' | 'module' | 'global';\n\nexport type ScopeContext = { [key: PropertyKey]: ScopeContext | any };\nexport interface Scope<T = ScopeContext> {\n\n\t/**\n\t * scope type\n\t */\n\ttype: ScopeType;\n\n\t/**\n\t * get value of `propertyKey` in current context\n\t * @param propertyKey \n\t */\n\tget(propertyKey: keyof T): any;\n\n\t/**\n\t * set the value of `propertyKey` in current context, could be instilled with `value`.\n\t * @param propertyKey \n\t * @param value \n\t * @param receiver \n\t */\n\tset(propertyKey: keyof T, value?: any, receiver?: any): boolean;\n\n\t/**\n\t * is current context has `propertyKey` in hash map keys\n\t * @param propertyKey \n\t */\n\thas(propertyKey: keyof T): boolean;\n\n\t/**\n\t * delete property from context\n\t * @param propertyKey \n\t */\n\tdelete(propertyKey: keyof T): boolean;\n\n\t/**\n\t * get current context object of this scope\n\t */\n\tgetContext(): T;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if the current value is not type od `object`, will return `undefined`.\n\t * @param propertyKey the name of the property\n\t */\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined;\n\n\t/**\n\t * get a scope for an object named as `propertyKey` from cache map,\n\t * \n\t * if no scope found in the cache, will create a new one, add this one to the map, return a reference.\n\t * @param propertyKey\n\t */\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V>;\n}\n\nexport class Scope<T extends ScopeContext> implements Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new Scope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new Scope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new Scope({} as T, 'global');\n\t}\n\tprotected scopeMap = new Map<keyof T, Scope<any>>();\n\tconstructor(protected context: T, public type: ScopeType) { }\n\tget(propertyKey: keyof T): any {\n\t\treturn Reflect.get(this.context, propertyKey);\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\treturn Reflect.set(this.context, propertyKey, value);\n\t}\n\thas(propertyKey: keyof T): boolean {\n\t\treturn propertyKey in this.context;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\treturn Reflect.deleteProperty(this.context, propertyKey);\n\t}\n\tgetContext(): T {\n\t\treturn this.context;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): Scope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): Scope<V> {\n\t\tconst scopeContext = this.get(propertyKey);\n\t\tlet scope = this.scopeMap.get(propertyKey);\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new Scope(scopeContext, 'block');\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n}\n\nexport class ReadOnlyScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReadOnlyScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReadOnlyScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReadOnlyScope({} as T, 'global');\n\t}\n\tset(propertyKey: keyof T, value: any, receiver?: any): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\t// do nothing\n\t\treturn false;\n\t}\n}\n\nexport class ScopeSubscription<T> {\n\tconstructor(private propertyKey: keyof T, private observer: ValueChangeObserver<T>) { }\n\tpause() {\n\t\tthis.observer.pause(this.propertyKey, this);\n\t}\n\tresume() {\n\t\tthis.observer.resume(this.propertyKey, this);\n\t}\n\tunsubscribe(): void {\n\t\tthis.observer.unsubscribe(this.propertyKey, this);\n\t}\n}\n\nexport type ValueChangedCallback = (newValue: any, oldValue?: any) => void;\n\ntype SubscriptionInfo = { callback: ValueChangedCallback, enable: boolean };\n\nexport class ValueChangeObserver<T> {\n\tprivate subscribers: Map<keyof T, Map<ScopeSubscription<T>, SubscriptionInfo>> = new Map();\n\tprivate propertiesLock: (keyof T)[] = [];\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.propertiesLock.includes(propertyKey)) {\n\t\t\treturn;\n\t\t}\n\t\tconst subscribers = this.subscribers.get(propertyKey);\n\t\tif (!subscribers) {\n\t\t\treturn;\n\t\t}\n\t\tthis.propertiesLock.push(propertyKey);\n\t\tsubscribers?.forEach(subscriptionInfo => {\n\t\t\tif (!subscriptionInfo.enable) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\ttry {\n\t\t\t\tsubscriptionInfo.callback(newValue, oldValue);\n\t\t\t} catch (e) {\n\t\t\t\tconsole.error(e);\n\t\t\t}\n\t\t});\n\t\tif (this.propertiesLock.pop() !== propertyKey) {\n\t\t\tconsole.error('lock error');\n\t\t};\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\tconst subscription: ScopeSubscription<T> = new ScopeSubscription(propertyKey, this);\n\t\tlet propertySubscribers = this.subscribers.get(propertyKey);\n\t\tif (!propertySubscribers) {\n\t\t\tpropertySubscribers = new Map();\n\t\t\tthis.subscribers.set(propertyKey, propertySubscribers);\n\t\t}\n\t\tpropertySubscribers.set(subscription, { callback, enable: true });\n\t\treturn subscription;\n\t}\n\n\tunsubscribe(propertyKey: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (subscription) {\n\t\t\tthis.subscribers.get(propertyKey)?.delete(subscription);\n\t\t} else {\n\t\t\tthis.subscribers.delete(propertyKey);\n\t\t}\n\t}\n\n\tpause(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = false);\n\t}\n\n\tresume(propertyKey: keyof T, subscription: ScopeSubscription<T>) {\n\t\tconst subscriptionInfo = this.subscribers.get(propertyKey)?.get(subscription);\n\t\tsubscriptionInfo && (subscriptionInfo.enable = true);\n\t}\n\n\t/**\n\t * clear subscription maps\n\t */\n\tdestroy() {\n\t\tthis.subscribers.clear();\n\t}\n}\n\nexport class ReactiveScope<T extends ScopeContext> extends Scope<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReactiveScope(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScope(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScope({} as T, 'global');\n\t}\n\n\tprotected observer: ValueChangeObserver<T> = new ValueChangeObserver<T>();\n\n\tconstructor(context: T, type: ScopeType);\n\tconstructor(context: T, type: ScopeType, name: string, parent: ReactiveScope<any>);\n\tconstructor(context: T, type: ScopeType, protected name?: string, protected parent?: ReactiveScope<any>) {\n\t\tsuper(context, type);\n\t}\n\n\tset(propertyKey: keyof T, newValue: any, receiver?: any): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst result = Reflect.set(this.context, propertyKey, newValue);\n\t\tif (result) {\n\t\t\tthis.emit(propertyKey, newValue, oldValue);\n\t\t}\n\t\treturn result;\n\t}\n\tdelete(propertyKey: keyof T): boolean {\n\t\tconst oldValue = Reflect.get(this.context, propertyKey);\n\t\tconst isDelete = Reflect.deleteProperty(this.context, propertyKey);\n\t\tif (isDelete && oldValue !== undefined) {\n\t\t\tthis.emit(propertyKey, undefined, oldValue);\n\t\t}\n\t\treturn isDelete;\n\t}\n\tgetScope<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> | undefined {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tif (typeof scopeContext !== 'object') {\n\t\t\treturn;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, 'block', propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\tgetScopeOrCreat<V extends ScopeContext>(propertyKey: keyof T): ReactiveScope<V> {\n\t\tconst scopeContext = this.get(propertyKey) as V;\n\t\tlet scope = this.scopeMap.get(propertyKey) as ReactiveScope<any> | undefined;\n\t\tif (scope) {\n\t\t\tscope.context = scopeContext;\n\t\t\treturn scope;\n\t\t}\n\t\tscope = new ReactiveScope<V>(scopeContext, 'block', propertyKey as string, this);\n\t\tthis.scopeMap.set(propertyKey, scope);\n\t\treturn scope;\n\t}\n\temit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tthis.observer.emit(propertyKey, newValue, oldValue);\n\t\tthis.parent?.emit(this.name!, this.context);\n\t}\n\tsubscribe(propertyKey: keyof T, callback: ValueChangedCallback): ScopeSubscription<T> {\n\t\treturn this.observer.subscribe(propertyKey, callback);\n\t}\n\tunsubscribe(propertyKey?: keyof T, subscription?: ScopeSubscription<T>) {\n\t\tif (propertyKey && subscription) {\n\t\t\tthis.observer.unsubscribe(propertyKey, subscription);\n\t\t} else if (propertyKey) {\n\t\t\tthis.observer.unsubscribe(propertyKey);\n\t\t} else {\n\t\t\tthis.observer.destroy();\n\t\t}\n\t}\n}\n\n/**\n * used control/notify/pause scope about changes in current context\n */\nexport interface ScopeControl<T extends ScopeContext> {\n\n\t/**\n\t * used when want to update ui-view like, you want to replace an array with another \n\t * without reflect changes on view until reattached again.\n\t */\n\tdetach(): void;\n\n\t/**\n\t * apply all the not emitted changes, and continue emit in time.\n\t */\n\treattach(): void;\n\n\t/**\n\t * apply changes now,\n\t * will not effect the state of the detector wither if attached ot not.\n\t * \n\t * if a propertyKey is provided, will emit this property only \n\t * @param propertyKey \n\t */\n\temitChanges(propertyKey?: keyof T): void;\n}\n\nexport class ReactiveScopeControl<T extends ScopeContext> extends ReactiveScope<T> implements ScopeControl<T> {\n\tstatic for<T extends ScopeContext>(context: T, type: ScopeType) {\n\t\treturn new ReactiveScopeControl(context, type);\n\t}\n\tstatic blockScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'block');\n\t}\n\tstatic functionScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'function');\n\t}\n\tstatic classScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'class');\n\t}\n\tstatic moduleScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'module');\n\t}\n\tstatic globalScopeFor<T extends ScopeContext>(context: T) {\n\t\treturn new ReactiveScopeControl(context, 'global');\n\t}\n\tstatic blockScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'block');\n\t}\n\tstatic functionScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'function');\n\t}\n\tstatic classScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'class');\n\t}\n\tstatic moduleScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'module');\n\t}\n\tstatic globalScope<T extends ScopeContext>() {\n\t\treturn new ReactiveScopeControl({} as T, 'global');\n\t}\n\n\tprotected attached: boolean = true;\n\tprotected marked: ScopeContext = {};\n\toverride emit(propertyKey: keyof T, newValue: any, oldValue?: any): void {\n\t\tif (this.attached) {\n\t\t\tsuper.emit(propertyKey, newValue, oldValue);\n\t\t} else {\n\t\t\tthis.marked[propertyKey] = newValue;\n\t\t}\n\t}\n\tdetach(): void {\n\t\tthis.attached = false;\n\t}\n\treattach(): void {\n\t\tthis.attached = true;\n\t\tthis.emitChanges();\n\t}\n\temitChanges(propertyKey?: keyof T): void {\n\t\tif (propertyKey) {\n\t\t\tif (propertyKey in this.marked) {\n\t\t\t\tconst lastValue = this.marked[propertyKey];\n\t\t\t\tReflect.deleteProperty(this.marked, propertyKey);\n\t\t\t\tsuper.emit(propertyKey, lastValue);\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\t\tconst oldChanges = this.marked;\n\t\tthis.marked = {};\n\t\tObject.keys(oldChanges).forEach(propertyKey => {\n\t\t\tsuper.emit(propertyKey, oldChanges[propertyKey]);\n\t\t});\n\t}\n}\n"]}
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,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B,CAAC;CACD;AAyBD,MAAM,OAAO,WAAY,SAAQ,aAA4B;IAC5D,YAAY,OAAsB,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"]}
package/scope/stack.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import type { CanDeclareExpression } from '../api/expression.js';
2
- import { ReactiveScope, Scope, ScopeContext, ScopeType } from './scope.js';
1
+ import type { DeclarationExpression } from '../api/expression.js';
2
+ import { ModuleScope, ReactiveScope, Scope, ScopeContext, WebModuleScope } from './scope.js';
3
3
  export interface AwaitPromiseInfo {
4
4
  promise: Promise<any>;
5
- node: CanDeclareExpression;
5
+ node: DeclarationExpression;
6
6
  declareVariable: boolean;
7
- scopeType: ScopeType;
8
7
  }
9
8
  export interface AsyncIterableInfo {
10
9
  iterable: AsyncIterable<any>;
@@ -16,7 +15,7 @@ export interface Stack {
16
15
  has(propertyKey: PropertyKey): boolean;
17
16
  get(propertyKey: PropertyKey): any;
18
17
  set(propertyKey: PropertyKey, value: any, receiver?: any): boolean;
19
- declareVariable(scopeType: ScopeType, propertyKey: PropertyKey, propertyValue?: any): any;
18
+ declareVariable(propertyKey: PropertyKey, propertyValue?: any): any;
20
19
  findScope<T extends ScopeContext>(propertyKey: PropertyKey): Scope<T>;
21
20
  resolveAwait(value: AwaitPromiseInfo): void;
22
21
  lastScope<T extends ScopeContext>(): Scope<T>;
@@ -26,32 +25,50 @@ export interface Stack {
26
25
  removeScope<T extends ScopeContext>(scope: Scope<T>): void;
27
26
  pushScope<T extends ScopeContext>(scope: Scope<T>): void;
28
27
  pushBlockScope<T extends ScopeContext>(): Scope<T>;
29
- pushFunctionScope<T extends ScopeContext>(): Scope<T>;
30
28
  pushBlockScopeFor<T extends ScopeContext>(context: T): Scope<T>;
31
- pushFunctionScopeFor<T extends ScopeContext>(context: T): Scope<T>;
32
- pushBlockReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
33
- pushFunctionReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
34
- pushBlockReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
35
- pushFunctionReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
29
+ pushReactiveScope<T extends ScopeContext>(): ReactiveScope<T>;
30
+ pushReactiveScopeFor<T extends ScopeContext>(context: T): ReactiveScope<T>;
36
31
  copyStack(): Stack;
32
+ detach(): void;
33
+ reattach(): void;
34
+ importModule(source: string, importCallOptions?: ImportCallOptions): ModuleScope;
35
+ getModule(): ModuleScope | undefined;
36
+ onDestroy(action: () => void): void;
37
37
  }
38
38
  export declare class Stack implements Stack {
39
- static for(...contexts: Scope<any>[]): Stack;
40
- static forScopes(...scopes: Scope<any>[]): Stack;
39
+ static for(...contexts: Scope<ScopeContext>[]): Stack;
40
+ static forScopes(...scopes: Scope<ScopeContext>[]): Stack;
41
+ static moduleScope(resolver: ModuleScopeResolver, moduleSource: string, ...globalScopes: Scope<ScopeContext>[]): Stack;
41
42
  awaitPromise: AwaitPromiseInfo[];
42
43
  forAwaitAsyncIterable?: AsyncIterableInfo | undefined;
43
44
  protected readonly stack: Array<Scope<any>>;
44
- constructor(stack?: Array<Scope<any>>);
45
- pushClassScope<T extends ScopeContext>(): Scope<T>;
46
- pushModuleScope<T extends ScopeContext>(): Scope<T>;
47
- pushGlobalScope<T extends ScopeContext>(): Scope<T>;
48
- pushClassScopeFor<T extends ScopeContext>(context: T): Scope<T>;
49
- pushModuleScopeFor<T extends ScopeContext>(context: T): Scope<T>;
50
- pushGlobalScopeFor<T extends ScopeContext>(context: T): Scope<T>;
51
- pushClassReactiveScope<T extends ScopeContext>(): Scope<T>;
52
- pushModuleReactiveScope<T extends ScopeContext>(): Scope<T>;
53
- pushGlobalReactiveScope<T extends ScopeContext>(): Scope<T>;
54
- pushClassReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
55
- pushModuleReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
56
- pushGlobalReactiveScopeFor<T extends ScopeContext>(context: T): Scope<T>;
45
+ protected readonly moduleScope?: ModuleScope;
46
+ protected readonly moduleSource?: string;
47
+ protected readonly resolver?: ModuleScopeResolver;
48
+ protected readonly onDestroyActions: (() => void)[];
49
+ constructor();
50
+ constructor(globalScope: Scope<ScopeContext>);
51
+ constructor(globalScope: Scope<ScopeContext>, resolver: ModuleScopeResolver, moduleSource: string);
52
+ constructor(stack: Array<Scope<ScopeContext>>);
53
+ constructor(stack: Array<Scope<ScopeContext>>, resolver: ModuleScopeResolver, moduleSource: string);
54
+ private initModuleContext;
55
+ private getReactiveScopeControls;
56
+ }
57
+ export interface ModuleScopeResolver {
58
+ resolve(source: string, moduleScope: ModuleScope, importCallOptions?: ImportCallOptions): ModuleScope;
59
+ resolveURL(specified: string, parent: string | URL): string;
60
+ }
61
+ export declare function createRootURL(source: string): URL;
62
+ export interface ResolverConfig {
63
+ allowImportExternal?: boolean;
64
+ }
65
+ export declare class ModuleScopeResolver implements ModuleScopeResolver {
66
+ protected config?: ResolverConfig | undefined;
67
+ protected modules: [string, ModuleScope][];
68
+ constructor(config?: ResolverConfig | undefined);
69
+ register(source: string, moduleScope: ModuleScope): void;
70
+ protected findScopeBySource(source: string, importCallOptions?: ImportCallOptions): ModuleScope;
71
+ protected findSourceByScope(moduleScope: ModuleScope): string;
72
+ protected resolveExternalModule(source: string, importCallOptions?: ImportCallOptions): WebModuleScope;
73
+ protected readonly isValidHTTPUrl: (string: string) => boolean;
57
74
  }