@lionweb/class-core 0.7.0-beta.12 → 0.7.0-beta.14

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 (80) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/README.md +6 -6
  3. package/dist/LionCore_builtins.g.d.ts +2 -2
  4. package/dist/LionCore_builtins.g.d.ts.map +1 -1
  5. package/dist/LionCore_builtins.g.js +1 -1
  6. package/dist/LionCore_builtins.g.js.map +1 -1
  7. package/dist/base-types.d.ts +7 -11
  8. package/dist/base-types.d.ts.map +1 -1
  9. package/dist/base-types.js +3 -28
  10. package/dist/base-types.js.map +1 -1
  11. package/dist/convenience.d.ts +7 -7
  12. package/dist/convenience.d.ts.map +1 -1
  13. package/dist/convenience.js +7 -7
  14. package/dist/convenience.js.map +1 -1
  15. package/dist/deltas/appliers.d.ts +2 -2
  16. package/dist/deltas/appliers.d.ts.map +1 -1
  17. package/dist/deltas/appliers.js +5 -2
  18. package/dist/deltas/appliers.js.map +1 -1
  19. package/dist/deltas/compositor.d.ts +51 -0
  20. package/dist/deltas/compositor.d.ts.map +1 -0
  21. package/dist/deltas/compositor.js +95 -0
  22. package/dist/deltas/compositor.js.map +1 -0
  23. package/dist/deltas/index.d.ts +2 -1
  24. package/dist/deltas/index.d.ts.map +1 -1
  25. package/dist/deltas/index.js +2 -1
  26. package/dist/deltas/index.js.map +1 -1
  27. package/dist/deltas/inverters.d.ts.map +1 -1
  28. package/dist/deltas/inverters.js +33 -9
  29. package/dist/deltas/inverters.js.map +1 -1
  30. package/dist/deltas/receivers.d.ts +39 -0
  31. package/dist/deltas/receivers.d.ts.map +1 -0
  32. package/dist/deltas/receivers.js +60 -0
  33. package/dist/deltas/receivers.js.map +1 -0
  34. package/dist/deserializer.d.ts +5 -5
  35. package/dist/deserializer.d.ts.map +1 -1
  36. package/dist/deserializer.js +8 -19
  37. package/dist/deserializer.js.map +1 -1
  38. package/dist/factory.d.ts +10 -2
  39. package/dist/factory.d.ts.map +1 -1
  40. package/dist/factory.js +25 -16
  41. package/dist/factory.js.map +1 -1
  42. package/dist/id-mapping.d.ts +21 -3
  43. package/dist/id-mapping.d.ts.map +1 -1
  44. package/dist/id-mapping.js +37 -17
  45. package/dist/id-mapping.js.map +1 -1
  46. package/dist/textualizer.js +1 -1
  47. package/dist/textualizer.js.map +1 -1
  48. package/dist/value-managers/annotations.d.ts.map +1 -1
  49. package/dist/value-managers/annotations.js +1 -2
  50. package/dist/value-managers/annotations.js.map +1 -1
  51. package/dist/value-managers/base.d.ts +2 -2
  52. package/dist/value-managers/base.js +4 -4
  53. package/dist/value-managers/base.js.map +1 -1
  54. package/dist/value-managers/containments.d.ts +2 -2
  55. package/dist/value-managers/containments.d.ts.map +1 -1
  56. package/dist/value-managers/containments.js +89 -27
  57. package/dist/value-managers/containments.js.map +1 -1
  58. package/dist/value-managers/references.js +2 -2
  59. package/package.json +34 -34
  60. package/src/LionCore_builtins.g.ts +2 -2
  61. package/src/base-types.ts +6 -31
  62. package/src/convenience.ts +10 -10
  63. package/src/deltas/appliers.ts +5 -2
  64. package/src/deltas/compositor.ts +107 -0
  65. package/src/deltas/index.ts +3 -1
  66. package/src/deltas/inverters.ts +33 -9
  67. package/src/deltas/receivers.ts +92 -0
  68. package/src/deserializer.ts +9 -25
  69. package/src/factory.ts +31 -17
  70. package/src/id-mapping.ts +26 -5
  71. package/src/textualizer.ts +1 -1
  72. package/src/value-managers/annotations.ts +2 -2
  73. package/src/value-managers/base.ts +4 -4
  74. package/src/value-managers/containments.ts +87 -27
  75. package/src/value-managers/references.ts +2 -2
  76. package/dist/deltas/handlers.d.ts +0 -17
  77. package/dist/deltas/handlers.d.ts.map +0 -1
  78. package/dist/deltas/handlers.js +0 -43
  79. package/dist/deltas/handlers.js.map +0 -1
  80. package/src/deltas/handlers.ts +0 -64
package/src/id-mapping.ts CHANGED
@@ -30,35 +30,56 @@ type NodesById = { [id: LionWebId]: INodeBase }
30
30
  */
31
31
  export class IdMapping {
32
32
 
33
- nodesById: NodesById;
33
+ private nodesById: NodesById;
34
34
  constructor(nodesById: NodesById) {
35
35
  this.nodesById = {...nodesById};
36
36
  }
37
37
  // TODO consider using an instance of Map<Id, INodeBase> instead
38
38
 
39
- fromId(id: LionWebId): INodeBase {
39
+ /**
40
+ * @return the {@link INodeBase node} with the given {@link LionWebId `id`}, or
41
+ * @throws an Error if no node with the given ID was registered.
42
+ */
43
+ fromId = (id: LionWebId): INodeBase => {
40
44
  if (!(id in this.nodesById)) {
41
45
  throw new Error(`node with id=${id} not in ID mapping`);
42
46
  }
43
47
  return this.nodesById[id];
44
48
  }
45
49
 
50
+ /**
51
+ * @return the {@link INodeBase node} with the given {@link LionWebId `id`},
52
+ * or `undefined` if no node with the given ID was registered.
53
+ */
46
54
  tryFromId = (id: LionWebId): (INodeBase | undefined) =>
47
55
  this.nodesById[id];
48
56
 
57
+ /**
58
+ * @return the {@link INodeBase node} referenced from the given {@link LionWebId ID},
59
+ * or `unresolved` if `unresolved` was passed in or no node with the given ID was registered.
60
+ */
49
61
  fromRefId = (idOrUnresolved: IdOrUnresolved): SingleRef<INodeBase> =>
50
- idOrUnresolved === null
51
- ? null
62
+ idOrUnresolved === unresolved
63
+ ? unresolved
52
64
  : (this.nodesById[idOrUnresolved] ?? unresolved);
53
65
 
54
66
  /**
55
67
  * Updates this {@link IdMapping} with the given `node` *and all its descendants* (recursively).
56
68
  */
57
- updateWith(node: INodeBase) {
69
+ updateWith= (node: INodeBase) => {
58
70
  this.nodesById[node.id] = node;
59
71
  node.children // recurse into all children
60
72
  .forEach((child) => this.updateWith(child));
61
73
  }
62
74
 
75
+ /**
76
+ * Re-initializes this {@link IdMapping ID mapping} with the given nodes-by-ID.
77
+ * This completely removes all registrations of nodes,
78
+ * and should only be used by components which are in complete control of the nodes being passed to this method.
79
+ */
80
+ reinitializeWith = (nodesById: NodesById) => {
81
+ this.nodesById = nodesById
82
+ }
83
+
63
84
  }
64
85
 
@@ -54,7 +54,7 @@ export const asTreeTextWith = (identificationFor: (node: INodeBase) => string):
54
54
  const valueManager = node.getPropertyValueManager(feature)
55
55
  const displayValue = (() => {
56
56
  if (!valueManager.isSet()) {
57
- return `$<not set>`
57
+ return `<not set>`
58
58
  }
59
59
  const value = valueManager.getDirectly()
60
60
  if (feature.type === LionCore_builtinsBase.INSTANCE.String) {
@@ -17,7 +17,7 @@
17
17
 
18
18
  import { action, observable } from "mobx"
19
19
 
20
- import { INodeBase, removeFromParent } from "../base-types.js"
20
+ import { INodeBase } from "../base-types.js"
21
21
  import { checkIndex, ValueManager } from "./base.js"
22
22
  import {
23
23
  AnnotationAddedDelta,
@@ -67,7 +67,7 @@ export class AnnotationsValueManager extends ValueManager {
67
67
  newAnnotation.attachTo(this.container, null);
68
68
  return false;
69
69
  } else {
70
- const oldIndex = removeFromParent(oldParent, newAnnotation);
70
+ const oldIndex = oldParent.annotationsValueManager.removeDirectly(newAnnotation);
71
71
  newAnnotation.attachTo(this.container, null);
72
72
  return [oldParent, oldIndex];
73
73
  }
@@ -29,12 +29,12 @@ export abstract class ValueManager {
29
29
  }
30
30
 
31
31
  /**
32
- * Emits a delta if a {@link DeltaHandler} is registered with the container.
33
- * @param deltaThunk a thunk that generates the delta, and is only called when a delta handler is registered with the container.
32
+ * Emits a delta if a {@link DeltaReceiver} is registered with the container.
33
+ * @param deltaThunk a thunk that generates the delta, and is only called when a delta receiver is registered with the container.
34
34
  */
35
35
  emitDelta(deltaThunk: () => IDelta) {
36
- if (this.container.handleDelta) {
37
- this.container.handleDelta(deltaThunk());
36
+ if (this.container.receiveDelta) {
37
+ this.container.receiveDelta(deltaThunk());
38
38
  }
39
39
  }
40
40
 
@@ -18,12 +18,15 @@
18
18
  import { Containment } from "@lionweb/core"
19
19
  import { action, observable } from "mobx"
20
20
 
21
- import { INodeBase, removeFromParent } from "../base-types.js"
21
+ import { INodeBase } from "../base-types.js"
22
22
  import {
23
23
  ChildAddedDelta,
24
24
  ChildDeletedDelta,
25
- ChildMovedAndReplacedFromOtherContainmentInSameParentDelta, ChildMovedAndReplacedInSameContainmentDelta,
25
+ ChildMovedAndReplacedFromOtherContainmentDelta,
26
+ ChildMovedAndReplacedFromOtherContainmentInSameParentDelta,
27
+ ChildMovedAndReplacedInSameContainmentDelta,
26
28
  ChildMovedFromOtherContainmentDelta,
29
+ ChildMovedFromOtherContainmentInSameParentDelta,
27
30
  ChildMovedInSameContainmentDelta,
28
31
  ChildReplacedDelta
29
32
  } from "../deltas/index.js"
@@ -80,24 +83,38 @@ export abstract class SingleContainmentValueManager<T extends INodeBase> extends
80
83
  this.child.set(newChild);
81
84
  }
82
85
 
83
- @action replaceWith(newChild: T) {
84
- const oldChild = this.getDirectly();
85
- if (oldChild === undefined) {
86
+ @action replaceWith(movedChild: T) {
87
+ const replacedChild = this.getDirectly();
88
+ if (replacedChild === undefined) {
86
89
  // not a proper replace, but an add-set => delegate to regular setter (— unfortunately, through necessarily “unfolding the hierarchy”):
87
90
  if (this instanceof OptionalSingleContainmentValueManager) {
88
- this.set(newChild);
91
+ this.set(movedChild);
89
92
  }
90
93
  if (this instanceof RequiredSingleContainmentValueManager) {
91
- this.set(newChild);
94
+ this.set(movedChild);
92
95
  }
93
96
  } else {
94
- if (oldChild === newChild) {
97
+ if (replacedChild === movedChild) {
95
98
  // do nothing: nothing's changed
96
99
  } else {
97
- oldChild.detach();
98
- this.setDirectly(newChild);
99
- newChild.attachTo(this.container, this.feature);
100
- this.emitDelta(() => new ChildReplacedDelta(this.container, this.feature, 0, oldChild, newChild));
100
+ if (movedChild.parent === undefined) {
101
+ this.emitDelta(() => new ChildReplacedDelta(this.container, this.feature, 0, replacedChild, movedChild));
102
+ } else {
103
+ if (movedChild.parent === this.container) {
104
+ if (movedChild.containment === this.containment) {
105
+ this.emitDelta(() => new ChildMovedAndReplacedInSameContainmentDelta(this.container, this.containment, 0, 0, movedChild, replacedChild));
106
+ } else {
107
+ const oldIndex = removeFromContainment(replacedChild);
108
+ this.emitDelta(() => new ChildMovedAndReplacedFromOtherContainmentInSameParentDelta(this.container, movedChild.containment!, oldIndex, this.containment, 0, movedChild, replacedChild));
109
+ }
110
+ } else {
111
+ const oldIndex = removeFromContainment(replacedChild);
112
+ this.emitDelta(() => new ChildMovedAndReplacedFromOtherContainmentDelta(this.container, this.containment, 0, movedChild, movedChild.parent!, movedChild.containment!, oldIndex, replacedChild));
113
+ }
114
+ }
115
+ this.setDirectly(movedChild);
116
+ movedChild.attachTo(this.container, this.containment);
117
+ replacedChild.detach();
101
118
  }
102
119
  }
103
120
  }
@@ -124,7 +141,7 @@ export class OptionalSingleContainmentValueManager<T extends INodeBase> extends
124
141
  } else {
125
142
  if (newChild.parent && newChild.containment) {
126
143
  const oldParent = newChild.parent;
127
- removeFromParent(oldParent, newChild);
144
+ removeFromContainment(newChild);
128
145
  this.emitDelta(() => new ChildMovedFromOtherContainmentDelta(oldParent, newChild.containment!, 0, this.container, this.feature, 0, newChild));
129
146
  } else {
130
147
  this.emitDelta(() => new ChildAddedDelta(this.container, this.feature, 0, newChild));
@@ -141,13 +158,14 @@ export class OptionalSingleContainmentValueManager<T extends INodeBase> extends
141
158
  if (oldChild === newChild) {
142
159
  // do nothing: nothing's changed
143
160
  } else {
161
+ // FIXME this could emit 2 deltas where it should be a single ChildReplaced-delta
144
162
  if (oldChild.parent && oldChild.containment && oldChild.parent === this.container && oldChild.containment === this.feature) {
145
163
  // FIXME oldChild.parent COULD be this.container
146
164
  this.emitDelta(() => new ChildDeletedDelta(this.container, this.feature, 0, oldChild));
147
165
  }
148
166
  oldChild.detach();
149
167
  if (newChild.parent && newChild.containment) {
150
- removeFromParent(newChild.parent, newChild);
168
+ removeFromContainment(newChild);
151
169
  }
152
170
  this.setDirectly(newChild);
153
171
  newChild.attachTo(this.container, this.feature);
@@ -183,7 +201,7 @@ export class RequiredSingleContainmentValueManager<T extends INodeBase> extends
183
201
  } else {
184
202
  if (newChild.parent && newChild.containment) {
185
203
  const oldParent = newChild.parent;
186
- removeFromParent(oldParent, newChild);
204
+ removeFromContainment(newChild);
187
205
  this.emitDelta(() => new ChildMovedFromOtherContainmentDelta(oldParent, newChild.containment!, 0, this.container, this.feature, 0, newChild));
188
206
  } else {
189
207
  this.emitDelta(() => new ChildAddedDelta(this.container, this.feature, 0, newChild));
@@ -204,7 +222,7 @@ export class RequiredSingleContainmentValueManager<T extends INodeBase> extends
204
222
  }
205
223
  oldChild.detach();
206
224
  if (newChild.parent && newChild.containment) {
207
- removeFromParent(newChild.parent, newChild);
225
+ removeFromContainment(newChild);
208
226
  }
209
227
  this.setDirectly(newChild);
210
228
  newChild.attachTo(this.container, this.feature);
@@ -251,16 +269,31 @@ export abstract class MultiContainmentValueManager<T extends INodeBase> extends
251
269
  this.children.splice(index, 0, newChild);
252
270
  }
253
271
 
254
- @action insertAtIndex(newChild: T, index: number) {
255
- this.insertAtIndexDirectly(newChild, index);
256
- if (newChild.parent === undefined && newChild.containment === undefined) {
257
- this.emitDelta(() => new ChildAddedDelta(this.container, this.containment, index, newChild));
272
+ @action insertAtIndex(newChild: T, newIndex: number) {
273
+ if (newChild.parent === undefined) {
274
+ this.insertAtIndexDirectly(newChild, newIndex);
275
+ newChild.attachTo(this.container, this.containment);
276
+ this.emitDelta(() => new ChildAddedDelta(this.container, this.containment, newIndex, newChild));
258
277
  } else {
259
- const oldIndex = removeFromParent(newChild.parent, newChild);
260
- this.emitDelta(() => new ChildMovedFromOtherContainmentDelta(newChild.parent!, newChild.containment!, oldIndex, this.container, this.containment, index, newChild));
261
- newChild.detach();
278
+ if (newChild.parent === this.container) {
279
+ if (newChild.containment === this.containment) {
280
+ const oldIndex = this.children.indexOf(newChild);
281
+ this.moveDirectly(oldIndex, newIndex);
282
+ this.emitDelta(() => new ChildMovedInSameContainmentDelta(this.container, this.containment, oldIndex, newIndex, newChild));
283
+ } else {
284
+ const oldIndex = removeFromContainment(newChild);
285
+ checkIndex(newIndex, this.children.length, true);
286
+ this.insertAtIndexDirectly(newChild, newIndex);
287
+ this.emitDelta(() => new ChildMovedFromOtherContainmentInSameParentDelta(this.container, newChild.containment!, oldIndex, newChild, this.containment, newIndex));
288
+ newChild.attachTo(this.container, this.containment);
289
+ }
290
+ } else {
291
+ const oldIndex = removeFromContainment(newChild);
292
+ this.insertAtIndexDirectly(newChild, newIndex);
293
+ this.emitDelta(() => new ChildMovedFromOtherContainmentDelta(newChild.parent!, newChild.containment!, oldIndex, this.container, this.containment, newIndex, newChild));
294
+ newChild.attachTo(this.container, this.containment);
295
+ }
262
296
  }
263
- newChild.attachTo(this.container, this.containment);
264
297
  }
265
298
 
266
299
  @action removeDirectly(childToRemove: T): number {
@@ -298,18 +331,20 @@ export abstract class MultiContainmentValueManager<T extends INodeBase> extends
298
331
 
299
332
  @action replaceAtIndex(movedChild: T, newIndex: number) {
300
333
  checkIndex(newIndex, this.children.length, false);
334
+ if (movedChild.parent === undefined) {
335
+ throw new Error(`a child-to-move (id=${movedChild.id}) must already be contained`);
336
+ }
301
337
  const replacedChild = this.children[newIndex];
302
338
  if (replacedChild === movedChild) {
303
339
  // do nothing: nothing's changed
304
340
  } else {
305
341
  this.children.splice(newIndex, 1, movedChild);
306
- if (replacedChild.parent) {
342
+ if (replacedChild.parent !== undefined) {
307
343
  const oldValueManager = replacedChild.parent.getContainmentValueManager(replacedChild.containment!);
308
344
  const oldIndex = oldValueManager instanceof SingleContainmentValueManager
309
345
  ? 0
310
346
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
311
347
  : (oldValueManager as MultiContainmentValueManager<any>).children.indexOf(replacedChild);
312
- replacedChild.detach();
313
348
  if (replacedChild.parent === movedChild.parent) {
314
349
  if (replacedChild.containment === movedChild.containment) {
315
350
  this.emitDelta(() => new ChildMovedAndReplacedInSameContainmentDelta(this.container, this.containment, oldIndex, newIndex, movedChild, replacedChild));
@@ -317,8 +352,9 @@ export abstract class MultiContainmentValueManager<T extends INodeBase> extends
317
352
  this.emitDelta(() => new ChildMovedAndReplacedFromOtherContainmentInSameParentDelta(this.container, replacedChild.containment!, oldIndex, this.containment, newIndex, movedChild, replacedChild));
318
353
  }
319
354
  } else {
320
- this.emitDelta(() => new ChildMovedFromOtherContainmentDelta(replacedChild.parent!, replacedChild.containment!, oldIndex, this.container, this.containment, newIndex, movedChild));
355
+ this.emitDelta(() => new ChildMovedAndReplacedFromOtherContainmentDelta(this.container, this.containment, newIndex, movedChild, movedChild.parent!, movedChild.containment!, oldIndex, replacedChild));
321
356
  }
357
+ replacedChild.detach();
322
358
  } else {
323
359
  // not a move+replace, but a regular replace instead:
324
360
  this.emitDelta(() => new ChildReplacedDelta(this.container, this.containment, newIndex, replacedChild, movedChild));
@@ -380,3 +416,27 @@ export class RequiredMultiContainmentValueManager<T extends INodeBase> extends M
380
416
 
381
417
  }
382
418
 
419
+ /**
420
+ * Removes the given child node from its containment, and returns the containment index it had before removal.
421
+ */
422
+ const removeFromContainment = (child: INodeBase): number => {
423
+ if (child.parent === undefined) {
424
+ throw new Error(`can't remove an orphan from its parent`)
425
+ }
426
+ if (child.containment === undefined) {
427
+ throw new Error(`can't remove an orphan from its containing feature`)
428
+ }
429
+ if (child.containment === null) {
430
+ throw new Error(`can't remove an annotation`)
431
+ }
432
+ const valueManager = child.parent.getContainmentValueManager(child.containment)
433
+ if (valueManager instanceof SingleContainmentValueManager) {
434
+ valueManager.setDirectly(undefined)
435
+ return 0
436
+ } else if (valueManager instanceof MultiContainmentValueManager) {
437
+ return valueManager.removeDirectly(child)
438
+ } else {
439
+ throw new Error(`don't know how to remove a child that's contained through a value manager of type ${valueManager.constructor.name}`)
440
+ }
441
+ }
442
+
@@ -106,7 +106,7 @@ export class OptionalSingleReferenceValueManager<T extends INodeBase> extends Si
106
106
  if (oldTarget === undefined) {
107
107
  this.emitDelta(() => new ReferenceAddedDelta(this.container, this.reference, 0, newTarget));
108
108
  } else {
109
- this.emitDelta(() => new ReferenceChangedDelta(this.container, this.reference, 0, oldTarget, newTarget));
109
+ this.emitDelta(() => new ReferenceChangedDelta(this.container, this.reference, 0, newTarget, oldTarget));
110
110
  }
111
111
  }
112
112
  }
@@ -142,7 +142,7 @@ export class RequiredSingleReferenceValueManager<T extends INodeBase> extends Si
142
142
  if (oldTarget === undefined) {
143
143
  this.emitDelta(() => new ReferenceAddedDelta(this.container, this.reference, 0, newTarget));
144
144
  } else {
145
- this.emitDelta(() => new ReferenceChangedDelta(this.container, this.reference, 0, oldTarget, newTarget));
145
+ this.emitDelta(() => new ReferenceChangedDelta(this.container, this.reference, 0, newTarget, oldTarget));
146
146
  }
147
147
  }
148
148
  }
@@ -1,17 +0,0 @@
1
- import { IDelta } from "./base.js";
2
- /**
3
- * A type for functions that handle deltas.
4
- */
5
- export type DeltaHandler = (delta: IDelta) => void;
6
- export declare const collectingDeltaHandler: (printSerializations?: boolean) => [DeltaHandler, IDelta[]];
7
- /**
8
- * An interface for {@link DeltaHandler delta handlers} that can be switched on and off — “latching”.
9
- */
10
- export interface LatchingDeltaHandler extends DeltaHandler {
11
- latch(emitDeltas: boolean): void;
12
- }
13
- /**
14
- * @return a latching version of the given {@link DeltaHandler delta handler}.
15
- */
16
- export declare const latching: (handleDelta: DeltaHandler) => LatchingDeltaHandler;
17
- //# sourceMappingURL=handlers.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.d.ts","sourceRoot":"","sources":["../../src/deltas/handlers.ts"],"names":[],"mappings":"AAiBA,OAAO,EAAE,MAAM,EAAE,MAAM,WAAW,CAAA;AAIlC;;GAEG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;AAEnD,eAAO,MAAM,sBAAsB,GAAI,6BAA2B,KAAG,CAAC,YAAY,EAAE,MAAM,EAAE,CAS3F,CAAC;AAGF;;GAEG;AACH,MAAM,WAAW,oBAAqB,SAAQ,YAAY;IACtD,KAAK,CAAC,UAAU,EAAE,OAAO,GAAG,IAAI,CAAC;CACpC;AAED;;GAEG;AACH,eAAO,MAAM,QAAQ,GAAI,aAAa,YAAY,KAAG,oBAcpD,CAAC"}
@@ -1,43 +0,0 @@
1
- // Copyright 2025 TRUMPF Laser SE and other contributors
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License")
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- //
15
- // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
- // SPDX-License-Identifier: Apache-2.0
17
- import { serializeDelta } from "./serialization/index.js";
18
- export const collectingDeltaHandler = (printSerializations = false) => {
19
- const deltas = [];
20
- const handleDelta = (delta) => {
21
- deltas.push(delta);
22
- if (printSerializations) {
23
- console.log(JSON.stringify(serializeDelta(delta), null, 4));
24
- }
25
- };
26
- return [handleDelta, deltas];
27
- };
28
- /**
29
- * @return a latching version of the given {@link DeltaHandler delta handler}.
30
- */
31
- export const latching = (handleDelta) => {
32
- let emitDeltas = false;
33
- return Object.assign((delta) => {
34
- if (emitDeltas) {
35
- handleDelta(delta);
36
- }
37
- }, {
38
- latch(emitDeltas_) {
39
- emitDeltas = emitDeltas_;
40
- },
41
- });
42
- };
43
- //# sourceMappingURL=handlers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"handlers.js","sourceRoot":"","sources":["../../src/deltas/handlers.ts"],"names":[],"mappings":"AAAA,wDAAwD;AACxD,EAAE;AACF,iEAAiE;AACjE,mEAAmE;AACnE,0CAA0C;AAC1C,EAAE;AACF,iDAAiD;AACjD,EAAE;AACF,sEAAsE;AACtE,oEAAoE;AACpE,2EAA2E;AAC3E,sEAAsE;AACtE,iCAAiC;AACjC,EAAE;AACF,sEAAsE;AACtE,sCAAsC;AAGtC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAA;AAQzD,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,mBAAmB,GAAG,KAAK,EAA4B,EAAE;IAC5F,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,MAAM,WAAW,GAAiB,CAAC,KAAK,EAAE,EAAE;QACxC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACnB,IAAI,mBAAmB,EAAE,CAAC;YACtB,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,cAAc,CAAC,KAAK,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;QAChE,CAAC;IACL,CAAC,CAAC;IACF,OAAO,CAAC,WAAW,EAAE,MAAM,CAAC,CAAC;AACjC,CAAC,CAAC;AAUF;;GAEG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,WAAyB,EAAwB,EAAE;IACxE,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,OAAO,MAAM,CAAC,MAAM,CAChB,CAAC,KAAa,EAAE,EAAE;QACd,IAAI,UAAU,EAAE,CAAC;YACb,WAAW,CAAC,KAAK,CAAC,CAAC;QACvB,CAAC;IACL,CAAC,EACD;QACI,KAAK,CAAC,WAAoB;YACtB,UAAU,GAAG,WAAW,CAAC;QAC7B,CAAC;KACJ,CACJ,CAAC;AACN,CAAC,CAAC"}
@@ -1,64 +0,0 @@
1
- // Copyright 2025 TRUMPF Laser SE and other contributors
2
- //
3
- // Licensed under the Apache License, Version 2.0 (the "License")
4
- // you may not use this file except in compliance with the License.
5
- // You may obtain a copy of the License at
6
- //
7
- // http://www.apache.org/licenses/LICENSE-2.0
8
- //
9
- // Unless required by applicable law or agreed to in writing, software
10
- // distributed under the License is distributed on an "AS IS" BASIS,
11
- // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- // See the License for the specific language governing permissions and
13
- // limitations under the License.
14
- //
15
- // SPDX-FileCopyrightText: 2025 TRUMPF Laser SE and other contributors
16
- // SPDX-License-Identifier: Apache-2.0
17
-
18
- import { IDelta } from "./base.js"
19
- import { serializeDelta } from "./serialization/index.js"
20
-
21
-
22
- /**
23
- * A type for functions that handle deltas.
24
- */
25
- export type DeltaHandler = (delta: IDelta) => void;
26
-
27
- export const collectingDeltaHandler = (printSerializations = false): [DeltaHandler, IDelta[]] => {
28
- const deltas: IDelta[] = [];
29
- const handleDelta: DeltaHandler = (delta) => {
30
- deltas.push(delta);
31
- if (printSerializations) {
32
- console.log(JSON.stringify(serializeDelta(delta), null, 4));
33
- }
34
- };
35
- return [handleDelta, deltas];
36
- };
37
-
38
-
39
- /**
40
- * An interface for {@link DeltaHandler delta handlers} that can be switched on and off — “latching”.
41
- */
42
- export interface LatchingDeltaHandler extends DeltaHandler {
43
- latch(emitDeltas: boolean): void;
44
- }
45
-
46
- /**
47
- * @return a latching version of the given {@link DeltaHandler delta handler}.
48
- */
49
- export const latching = (handleDelta: DeltaHandler): LatchingDeltaHandler => {
50
- let emitDeltas = false;
51
- return Object.assign(
52
- (delta: IDelta) => {
53
- if (emitDeltas) {
54
- handleDelta(delta);
55
- }
56
- },
57
- {
58
- latch(emitDeltas_: boolean) {
59
- emitDeltas = emitDeltas_;
60
- },
61
- },
62
- );
63
- };
64
-