@spearwolf/shadow-objects 0.33.0 → 0.34.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.
Files changed (210) hide show
  1. package/CHANGELOG.md +320 -61
  2. package/README.md +57 -13
  3. package/bundle.js +5 -54
  4. package/package.json +7 -3
  5. package/src/ChangeTrailRefusedError.d.ts +27 -0
  6. package/src/ChangeTrailRefusedError.d.ts.map +1 -0
  7. package/src/ChangeTrailRefusedError.js +12 -0
  8. package/src/ChangeTrailRefusedError.js.map +7 -0
  9. package/src/EntityUuidInUseError.d.ts +19 -0
  10. package/src/EntityUuidInUseError.d.ts.map +1 -0
  11. package/src/EntityUuidInUseError.js +11 -0
  12. package/src/EntityUuidInUseError.js.map +7 -0
  13. package/src/WorkerTimeoutError.d.ts +25 -0
  14. package/src/WorkerTimeoutError.d.ts.map +1 -0
  15. package/src/WorkerTimeoutError.js +12 -0
  16. package/src/WorkerTimeoutError.js.map +7 -0
  17. package/src/bundle.d.ts +1 -1
  18. package/src/bundle.d.ts.map +1 -1
  19. package/src/bundle.js +1 -1
  20. package/src/bundle.js.map +2 -2
  21. package/src/constants.d.ts +9 -2
  22. package/src/constants.d.ts.map +1 -1
  23. package/src/constants.js +1 -1
  24. package/src/constants.js.map +2 -2
  25. package/src/create-worker.bundle.d.ts +1 -1
  26. package/src/create-worker.bundle.d.ts.map +1 -1
  27. package/src/create-worker.bundle.js.map +1 -1
  28. package/src/create-worker.d.ts +1 -1
  29. package/src/create-worker.d.ts.map +1 -1
  30. package/src/create-worker.js.map +1 -1
  31. package/src/elements/ShaeElement.d.ts +70 -2
  32. package/src/elements/ShaeElement.d.ts.map +1 -1
  33. package/src/elements/ShaeElement.js +129 -25
  34. package/src/elements/ShaeElement.js.map +3 -3
  35. package/src/elements/ShaeEntElement.d.ts +39 -1
  36. package/src/elements/ShaeEntElement.d.ts.map +1 -1
  37. package/src/elements/ShaeEntElement.js +397 -167
  38. package/src/elements/ShaeEntElement.js.map +2 -2
  39. package/src/elements/ShaeLifecycleElement.d.ts +71 -0
  40. package/src/elements/ShaeLifecycleElement.d.ts.map +1 -0
  41. package/src/elements/ShaeLifecycleElement.js +83 -0
  42. package/src/elements/ShaeLifecycleElement.js.map +7 -0
  43. package/src/elements/ShaePropElement.d.ts +52 -2
  44. package/src/elements/ShaePropElement.d.ts.map +1 -1
  45. package/src/elements/ShaePropElement.js +240 -219
  46. package/src/elements/ShaePropElement.js.map +2 -2
  47. package/src/elements/ShaeWorkerElement.d.ts +49 -5
  48. package/src/elements/ShaeWorkerElement.d.ts.map +1 -1
  49. package/src/elements/ShaeWorkerElement.js +204 -73
  50. package/src/elements/ShaeWorkerElement.js.map +2 -2
  51. package/src/elements/constants.d.ts +6 -0
  52. package/src/elements/constants.d.ts.map +1 -1
  53. package/src/elements/constants.js +12 -0
  54. package/src/elements/constants.js.map +2 -2
  55. package/src/elements/deferredTeardown.d.ts +24 -0
  56. package/src/elements/deferredTeardown.d.ts.map +1 -0
  57. package/src/elements/deferredTeardown.js +30 -0
  58. package/src/elements/deferredTeardown.js.map +7 -0
  59. package/src/elements/displayContentsRule.d.ts +25 -0
  60. package/src/elements/displayContentsRule.d.ts.map +1 -0
  61. package/src/elements/displayContentsRule.js +37 -0
  62. package/src/elements/displayContentsRule.js.map +7 -0
  63. package/src/elements/events.d.ts +10 -7
  64. package/src/elements/events.d.ts.map +1 -1
  65. package/src/elements/forwardCustomEvents.d.ts +19 -0
  66. package/src/elements/forwardCustomEvents.d.ts.map +1 -0
  67. package/src/elements/forwardCustomEvents.js +47 -0
  68. package/src/elements/forwardCustomEvents.js.map +7 -0
  69. package/src/elements/hostedSlots.d.ts +36 -0
  70. package/src/elements/hostedSlots.d.ts.map +1 -0
  71. package/src/elements/hostedSlots.js +118 -0
  72. package/src/elements/hostedSlots.js.map +7 -0
  73. package/src/elements/parentRemoval.d.ts +18 -0
  74. package/src/elements/parentRemoval.d.ts.map +1 -0
  75. package/src/elements/parentRemoval.js +60 -0
  76. package/src/elements/parentRemoval.js.map +7 -0
  77. package/src/elements/propValueConverters.d.ts +3 -0
  78. package/src/elements/propValueConverters.d.ts.map +1 -0
  79. package/src/elements/propValueConverters.js +54 -0
  80. package/src/elements/propValueConverters.js.map +7 -0
  81. package/src/elements/requestEntAncestor.d.ts +32 -0
  82. package/src/elements/requestEntAncestor.d.ts.map +1 -0
  83. package/src/elements/requestEntAncestor.js +16 -0
  84. package/src/elements/requestEntAncestor.js.map +7 -0
  85. package/src/elements.js.map +1 -1
  86. package/src/in-the-dark/Entity.d.ts +113 -3
  87. package/src/in-the-dark/Entity.d.ts.map +1 -1
  88. package/src/in-the-dark/Entity.js +292 -63
  89. package/src/in-the-dark/Entity.js.map +3 -3
  90. package/src/in-the-dark/Kernel.d.ts +76 -17
  91. package/src/in-the-dark/Kernel.d.ts.map +1 -1
  92. package/src/in-the-dark/Kernel.js +410 -378
  93. package/src/in-the-dark/Kernel.js.map +3 -3
  94. package/src/in-the-dark/Registry.d.ts.map +1 -1
  95. package/src/in-the-dark/Registry.js +83 -14
  96. package/src/in-the-dark/Registry.js.map +2 -2
  97. package/src/in-the-dark/ShadowObject.d.ts.map +1 -1
  98. package/src/in-the-dark/ShadowObject.js +1 -0
  99. package/src/in-the-dark/ShadowObject.js.map +2 -2
  100. package/src/in-the-dark/ShadowObjectCreationScope.d.ts +126 -0
  101. package/src/in-the-dark/ShadowObjectCreationScope.d.ts.map +1 -0
  102. package/src/in-the-dark/ShadowObjectCreationScope.js +596 -0
  103. package/src/in-the-dark/ShadowObjectCreationScope.js.map +7 -0
  104. package/src/in-the-dark/SignalsPath.d.ts.map +1 -1
  105. package/src/in-the-dark/SignalsPath.js +2 -2
  106. package/src/in-the-dark/SignalsPath.js.map +2 -2
  107. package/src/in-the-dark/events.js.map +1 -1
  108. package/src/in-the-dark/importModule.d.ts +7 -0
  109. package/src/in-the-dark/importModule.d.ts.map +1 -1
  110. package/src/in-the-dark/importModule.js +5 -2
  111. package/src/in-the-dark/importModule.js.map +2 -2
  112. package/src/index.d.ts +7 -1
  113. package/src/index.d.ts.map +1 -1
  114. package/src/index.js +5 -1
  115. package/src/index.js.map +2 -2
  116. package/src/shadow-objects.d.ts +2 -0
  117. package/src/shadow-objects.d.ts.map +1 -1
  118. package/src/shadow-objects.js +2 -0
  119. package/src/shadow-objects.js.map +2 -2
  120. package/src/shadow-objects.worker.js +0 -1
  121. package/src/shadow-objects.worker.js.map +2 -2
  122. package/src/shae-ent.js.map +1 -1
  123. package/src/shae-prop.js +2 -2
  124. package/src/shae-prop.js.map +2 -2
  125. package/src/shae-worker.js.map +1 -1
  126. package/src/types.d.ts +35 -4
  127. package/src/types.d.ts.map +1 -1
  128. package/src/utils/ConsoleLogger.d.ts +45 -10
  129. package/src/utils/ConsoleLogger.d.ts.map +1 -1
  130. package/src/utils/ConsoleLogger.js +51 -26
  131. package/src/utils/ConsoleLogger.js.map +2 -2
  132. package/src/utils/FrameLoop.d.ts +42 -3
  133. package/src/utils/FrameLoop.d.ts.map +1 -1
  134. package/src/utils/FrameLoop.js +71 -10
  135. package/src/utils/FrameLoop.js.map +2 -2
  136. package/src/utils/MicrotaskCollector.d.ts +45 -0
  137. package/src/utils/MicrotaskCollector.d.ts.map +1 -0
  138. package/src/utils/MicrotaskCollector.js +33 -0
  139. package/src/utils/MicrotaskCollector.js.map +7 -0
  140. package/src/utils/MicrotaskGate.d.ts +17 -0
  141. package/src/utils/MicrotaskGate.d.ts.map +1 -0
  142. package/src/utils/MicrotaskGate.js +20 -0
  143. package/src/utils/MicrotaskGate.js.map +7 -0
  144. package/src/utils/array-utils.js.map +1 -1
  145. package/src/utils/attr-utils.d.ts +6 -0
  146. package/src/utils/attr-utils.d.ts.map +1 -1
  147. package/src/utils/attr-utils.js +3 -1
  148. package/src/utils/attr-utils.js.map +2 -2
  149. package/src/utils/constants.js.map +1 -1
  150. package/src/utils/generateUUID.d.ts +11 -0
  151. package/src/utils/generateUUID.d.ts.map +1 -1
  152. package/src/utils/generateUUID.js +31 -266
  153. package/src/utils/generateUUID.js.map +2 -2
  154. package/src/utils/props-utils.d.ts +3 -2
  155. package/src/utils/props-utils.d.ts.map +1 -1
  156. package/src/utils/props-utils.js +13 -24
  157. package/src/utils/props-utils.js.map +2 -2
  158. package/src/utils/runGuarded.d.ts +27 -0
  159. package/src/utils/runGuarded.d.ts.map +1 -0
  160. package/src/utils/runGuarded.js +11 -0
  161. package/src/utils/runGuarded.js.map +7 -0
  162. package/src/utils/toMaybe.d.ts.map +1 -1
  163. package/src/utils/toMaybe.js.map +1 -1
  164. package/src/utils/toNamespace.d.ts.map +1 -1
  165. package/src/utils/toNamespace.js.map +1 -1
  166. package/src/utils/toUrlString.d.ts +12 -0
  167. package/src/utils/toUrlString.d.ts.map +1 -1
  168. package/src/utils/toUrlString.js.map +2 -2
  169. package/src/utils/waitForMessageOfType.d.ts +12 -1
  170. package/src/utils/waitForMessageOfType.d.ts.map +1 -1
  171. package/src/utils/waitForMessageOfType.js +16 -1
  172. package/src/utils/waitForMessageOfType.js.map +2 -2
  173. package/src/view/ComponentChanges.d.ts +88 -1
  174. package/src/view/ComponentChanges.d.ts.map +1 -1
  175. package/src/view/ComponentChanges.js +243 -73
  176. package/src/view/ComponentChanges.js.map +2 -2
  177. package/src/view/ComponentContext.d.ts +206 -16
  178. package/src/view/ComponentContext.d.ts.map +1 -1
  179. package/src/view/ComponentContext.js +548 -91
  180. package/src/view/ComponentContext.js.map +2 -2
  181. package/src/view/ComponentMemory.d.ts +3 -3
  182. package/src/view/ComponentMemory.d.ts.map +1 -1
  183. package/src/view/ComponentMemory.js.map +1 -1
  184. package/src/view/IShadowObjectEnvProxy.d.ts +29 -3
  185. package/src/view/IShadowObjectEnvProxy.d.ts.map +1 -1
  186. package/src/view/LocalShadowObjectEnv.d.ts +1 -1
  187. package/src/view/LocalShadowObjectEnv.d.ts.map +1 -1
  188. package/src/view/LocalShadowObjectEnv.js +8 -6
  189. package/src/view/LocalShadowObjectEnv.js.map +2 -2
  190. package/src/view/RemoteWorkerEnv.d.ts +89 -5
  191. package/src/view/RemoteWorkerEnv.d.ts.map +1 -1
  192. package/src/view/RemoteWorkerEnv.js +195 -77
  193. package/src/view/RemoteWorkerEnv.js.map +2 -2
  194. package/src/view/ShadowEnv.d.ts +49 -2
  195. package/src/view/ShadowEnv.d.ts.map +1 -1
  196. package/src/view/ShadowEnv.js +223 -60
  197. package/src/view/ShadowEnv.js.map +2 -2
  198. package/src/view/ViewComponent.d.ts +78 -14
  199. package/src/view/ViewComponent.d.ts.map +1 -1
  200. package/src/view/ViewComponent.js +90 -14
  201. package/src/view/ViewComponent.js.map +2 -2
  202. package/src/view/cloneChangeTrail.js.map +2 -2
  203. package/src/worker/MessageRouter.d.ts +14 -0
  204. package/src/worker/MessageRouter.d.ts.map +1 -1
  205. package/src/worker/MessageRouter.js +75 -15
  206. package/src/worker/MessageRouter.js.map +2 -2
  207. package/src/worker/WorkerRuntime.d.ts +22 -1
  208. package/src/worker/WorkerRuntime.d.ts.map +1 -1
  209. package/src/worker/WorkerRuntime.js +60 -8
  210. package/src/worker/WorkerRuntime.js.map +2 -2
@@ -1,4 +1,4 @@
1
- import { emit, off, on, once, Priority } from "@spearwolf/eventize";
1
+ import { emitStrict, off, on, once, Priority } from "@spearwolf/eventize";
2
2
  import {
3
3
  batch,
4
4
  createSignal,
@@ -7,24 +7,31 @@ import {
7
7
  SignalAutoMap,
8
8
  value
9
9
  } from "@spearwolf/signalize";
10
+ import { MicrotaskCollector } from "../utils/MicrotaskCollector.js";
11
+ import { runGuarded } from "../utils/runGuarded.js";
10
12
  import { onDestroy, onViewEvent } from "./events.js";
11
13
  import { Kernel } from "./Kernel.js";
12
14
  import { SignalsPath } from "./SignalsPath.js";
13
- const updateContextValues = /* @__PURE__ */ new Map();
14
- let requestedContextValueBatchUpdate = false;
15
- const deferContextValueUpdate = (sig, val) => {
16
- updateContextValues.set(sig, val);
17
- if (!requestedContextValueBatchUpdate) {
18
- requestedContextValueBatchUpdate = true;
19
- queueMicrotask(() => {
20
- requestedContextValueBatchUpdate = false;
21
- const contextValues = Array.from(updateContextValues.entries());
22
- updateContextValues.clear();
23
- for (const [sig2, val2] of contextValues) {
24
- sig2.set(val2);
15
+ const contextValueCollectors = /* @__PURE__ */ new WeakMap();
16
+ const collectorOf = (kernel) => {
17
+ let collector = contextValueCollectors.get(kernel);
18
+ if (collector == null) {
19
+ collector = new MicrotaskCollector((contextValues) => {
20
+ for (const [contextSignal, entry] of contextValues) {
21
+ runGuarded(
22
+ kernel.logger,
23
+ () => contextSignal.set(entry.value),
24
+ `an effect of a context value failed (${String(entry.name)}):`,
25
+ entry.uuid
26
+ );
25
27
  }
26
28
  });
29
+ contextValueCollectors.set(kernel, collector);
27
30
  }
31
+ return collector;
32
+ };
33
+ const deferContextValueUpdate = (kernel, signal, val, name, uuid) => {
34
+ collectorOf(kernel).add(signal, { value: val, name, uuid });
28
35
  };
29
36
  class Entity {
30
37
  #kernel;
@@ -32,11 +39,14 @@ class Entity {
32
39
  #props = new SignalAutoMap();
33
40
  #context = /* @__PURE__ */ new Map();
34
41
  #rootContexts = /* @__PURE__ */ new Map();
35
- #parentUuid;
42
+ // There is one place the parent is kept: `parentUuid` answers from `#parent.uuid`, so a half-set
43
+ // link -- a uuid with no matching entity, or an entity with no uuid to show for it -- has no field
44
+ // left to hold it in.
36
45
  #parent;
37
46
  #childrenUuids = /* @__PURE__ */ new Set();
38
47
  #children = [];
39
48
  #order = 0;
49
+ #isReleased = false;
40
50
  get kernel() {
41
51
  return this.#kernel;
42
52
  }
@@ -49,37 +59,40 @@ class Entity {
49
59
  set order(value2) {
50
60
  if (this.#order !== value2) {
51
61
  this.#order = value2;
52
- if (this.#parentUuid) {
53
- this.parent.resortChildren();
62
+ if (this.#parent) {
63
+ this.#parent.resortChildren();
54
64
  }
65
+ this.#kernel.noteEntityTreeChange(this.#uuid);
55
66
  }
56
67
  }
57
68
  get parentUuid() {
58
- return this.#parentUuid || void 0;
69
+ return this.#parent?.uuid;
59
70
  }
60
71
  set parentUuid(parentUuid) {
61
- if (this.#parentUuid !== parentUuid) {
72
+ if (this.#parent?.uuid !== parentUuid) {
62
73
  const nextParent = parentUuid ? this.#kernel.getEntity(parentUuid) : void 0;
63
- this.removeFromParent();
64
- this.#parentUuid = parentUuid || void 0;
74
+ if (nextParent != null) {
75
+ this.assertAttachableTo(nextParent);
76
+ }
77
+ this.#detachFromParent(nextParent == null);
65
78
  this.#parent = nextParent;
66
79
  if (this.#parent) {
67
80
  this.#parent.addChild(this);
68
81
  }
69
82
  this.#updateAutoDestructionSubscription();
83
+ this.#kernel.noteEntityTreeChange(this.#uuid);
70
84
  }
71
85
  }
72
86
  get parent() {
73
- if (!this.#parent && this.#parentUuid) {
74
- this.#parent = this.#kernel.getEntity(this.#parentUuid);
75
- }
76
87
  return this.#parent;
77
88
  }
78
89
  set parent(parent) {
79
90
  this.parentUuid = parent?.uuid;
80
91
  }
92
+ // Reads the same field `parent` and `parentUuid` do, so `Kernel.noteEntityTreeChange()` -- which
93
+ // reads `hasParent` to decide whether the uuid belongs in the root set -- sees what they see.
81
94
  get hasParent() {
82
- return !!this.#parentUuid;
95
+ return !!this.#parent;
83
96
  }
84
97
  get children() {
85
98
  return this.#children;
@@ -87,74 +100,166 @@ class Entity {
87
100
  constructor(kernel, uuid) {
88
101
  this.#kernel = kernel;
89
102
  this.#uuid = uuid;
90
- once(this, onDestroy, Priority.Min, this);
91
103
  }
92
104
  traverse(callback) {
105
+ this.#traverse(callback, /* @__PURE__ */ new Set());
106
+ }
107
+ // The visited set guards the one traversal an outside shadow object drives, over a tree it did not
108
+ // build. `addChild()` writes a children list without touching the parent link, so no ancestor check
109
+ // can cover it.
110
+ #traverse(callback, visited) {
111
+ if (visited.has(this)) return;
112
+ visited.add(this);
93
113
  callback(this);
94
114
  for (const child of this.#children) {
95
- child.traverse(callback);
115
+ child.#traverse(callback, visited);
96
116
  }
97
117
  }
118
+ /**
119
+ * Releases everything the entity holds: its properties, its subscriptions, its contexts and its place
120
+ * in the entity tree.
121
+ *
122
+ * It runs once, whichever way it is reached. The kernel reaches it directly, right behind the
123
+ * destruction notification it sends on the entity, so that every listener on that notification has
124
+ * had its turn first -- down to `Priority.Min`, which is nobody's but the caller's. The entity is
125
+ * not a listener on its own notification: registering it in the constructor would put it ahead of
126
+ * anything registered at the same priority, because eventize breaks a tie by order of registration,
127
+ * and the bulk `off(this)` below would then take the listeners still waiting in that delivery with
128
+ * it. The flag makes a second call cost nothing and keeps every step below written for a
129
+ * single run: `kernel.getEntity()` hands the entity to anyone, and this method is as reachable as
130
+ * the rest of it.
131
+ *
132
+ * The flag is raised before the first step rather than after the last, because that is what a release
133
+ * running twice would cost: the steps below are written for one pass, not for a repeat.
134
+ *
135
+ * Every step below runs behind a guard of its own, the way `ShadowObjectCreationScope.tearDown()`
136
+ * gives each of its steps one: a step that throws is reported through the kernel's logger, named by
137
+ * the step and by the uuid of this entity, and costs only itself -- the steps behind it still run.
138
+ * The method therefore never throws to its own caller. The plain resets at the end -- clearing a
139
+ * collection, overwriting a field -- cannot throw and run unguarded, exactly as `tearDown()` empties
140
+ * its own sets at the end.
141
+ */
98
142
  [onDestroy]() {
99
- this.#props.clear();
100
- off(this);
101
- this.#autoDestructionSubscription?.();
143
+ if (this.#isReleased) return;
144
+ this.#isReleased = true;
145
+ this.#runGuarded("properties", () => this.#props.clear());
146
+ this.#runGuarded("listeners", () => off(this));
147
+ this.#runGuarded("auto-destruction subscription", () => this.#autoDestructionSubscription?.());
102
148
  for (const rootCtx of this.#rootContexts.values()) {
103
- rootCtx.cleanup();
104
- rootCtx.signal.destroy();
149
+ this.#runGuarded("global context cleanup", () => rootCtx.cleanup());
150
+ this.#runGuarded("global context signal", () => rootCtx.signal.destroy());
105
151
  }
106
- this.#rootContexts.clear();
107
152
  for (const ctx of this.#context.values()) {
108
- ctx.context.set(void 0);
109
- ctx.unsubscribePathValue();
110
- ctx.unsubscribeFromParent?.();
111
- ctx.valuePath.dispose();
112
- ctx.inherited.destroy();
113
- ctx.provide.destroy();
114
- ctx.context.destroy();
153
+ this.#runGuarded("context value reset", () => ctx.context.set(void 0));
154
+ this.#runGuarded("context value subscription", () => ctx.unsubscribePathValue());
155
+ this.#runGuarded("context parent subscription", () => ctx.unsubscribeFromParent?.());
156
+ this.#runGuarded("context value path", () => ctx.valuePath.dispose());
157
+ this.#runGuarded("inherited context signal", () => ctx.inherited.destroy());
158
+ this.#runGuarded("provided context signal", () => ctx.provide.destroy());
159
+ this.#runGuarded("context signal", () => ctx.context.destroy());
115
160
  }
116
- this.#parentUuid = void 0;
161
+ this.#rootContexts.clear();
162
+ this.#context.clear();
117
163
  this.#parent = void 0;
118
164
  this.#childrenUuids.clear();
119
165
  this.#children.length = 0;
120
166
  }
121
- addChild(child) {
122
- if (this.#children.length === 0) {
123
- this.#childrenUuids.add(child.uuid);
124
- this.#children.push(child);
125
- return;
167
+ /**
168
+ * Isolates one release step from the ones around it: a step that throws is reported through the
169
+ * kernel's logger and does not stop `[onDestroy]()` from reaching the steps that follow. The
170
+ * report goes out through the shared `runGuarded()`; what this wrapper adds is the label of the
171
+ * step and the uuid of the entity it belongs to.
172
+ */
173
+ #runGuarded(step, run) {
174
+ runGuarded(this.#kernel.logger, run, `entity teardown step failed (${step}):`, this.#uuid);
175
+ }
176
+ /**
177
+ * Refuses a parent that would close the entity tree into a ring: the entity itself, or an entity that
178
+ * already sits below it. The walk follows the parent chain upwards, which is a chain exactly because
179
+ * this guard keeps it one.
180
+ *
181
+ * `Kernel.setParent()` calls it before it detaches, and the `parentUuid` setter before it resolves the
182
+ * link, so a refused attachment leaves the entity where it was instead of orphaned halfway through.
183
+ * `ViewComponent.addChild()` guards the same thing on the view side.
184
+ */
185
+ assertAttachableTo(nextParent) {
186
+ for (let e = nextParent; e != null; e = e.parent) {
187
+ if (e === this) {
188
+ throw new Error(
189
+ `entity "${nextParent.uuid}" cannot become the parent of "${this.uuid}": it is the entity itself or one of its descendants`
190
+ );
191
+ }
126
192
  }
193
+ }
194
+ /**
195
+ * Puts `child` into the children list, at its place among the siblings.
196
+ *
197
+ * Nothing here notifies. Neither this method nor {@link Entity.removeChild} nor a detachment
198
+ * sends anything to a listener on the entity -- the one notification over a moved entity is
199
+ * `onParentChanged`, and `Kernel.setParent()` is the call that sends it.
200
+ */
201
+ addChild(child) {
127
202
  if (this.#childrenUuids.has(child.uuid)) {
128
203
  throw new Error(`child with uuid: ${child.uuid} already exists! parentUuid: ${this.uuid}`);
129
204
  }
130
205
  this.#childrenUuids.add(child.uuid);
131
- this.#children.push(child);
132
- this.resortChildren();
206
+ this.#insertChildInOrder(child);
133
207
  for (const [, ctx] of child.#context) {
134
208
  child.#subscribeToParent(ctx);
135
209
  }
136
210
  }
211
+ /**
212
+ * Puts a child at its place among the siblings, so building a subtree costs one insertion per
213
+ * child. The scan runs from the end because children usually arrive with an equal or rising
214
+ * `order`, which makes the common case a plain append. A child lands behind every sibling that
215
+ * shares its `order` -- the same place a stable sort would give it.
216
+ *
217
+ * The result only matches a full sort while `#children` is already sorted when the insertion
218
+ * starts, so name what keeps it that way: the insertion here preserves the order, `removeChild()`
219
+ * cuts an element out with `splice`, the destroy handler empties the list, and the `order` setter
220
+ * re-sorts through the parent. That last one is the condition worth stating, because it needs the
221
+ * child to know its parent -- the parent link has to be established. Every way an entity is
222
+ * attached inside this class goes through the `parentUuid` setter, which sets the parent before it
223
+ * calls `addChild()`. A caller that reaches for `addChild()` on its own leaves the child without a
224
+ * parent link, and a later `order` on such a child never reaches this list.
225
+ */
226
+ #insertChildInOrder(child) {
227
+ let i = this.#children.length;
228
+ while (i > 0 && child.order < this.#children[i - 1].order) i--;
229
+ this.#children.splice(i, 0, child);
230
+ }
137
231
  resortChildren() {
138
232
  this.#children.sort((a, b) => a.order - b.order);
139
233
  }
140
234
  removeChild(child) {
141
- if (this.#childrenUuids.has(child.uuid)) {
235
+ const idx = this.#children.indexOf(child);
236
+ if (idx !== -1) {
142
237
  this.#childrenUuids.delete(child.uuid);
143
- this.#children.splice(this.#children.indexOf(child), 1);
238
+ this.#children.splice(idx, 1);
144
239
  }
145
240
  }
146
- removeFromParent() {
241
+ /**
242
+ * @param rebindContexts bind every context back to the root of the entity context tree. An entity
243
+ * that carries a context out of a subtree keeps following the value it can still see, rather
244
+ * than freezing on the last one the former parent held. Only a caller that attaches the entity
245
+ * to the next parent in the same breath passes `false` -- that parent binds the contexts itself,
246
+ * and the detour over the root would be visible to `useParentContext()`, which hands out the
247
+ * inherited value without the microtask collector `useContext()` has in front of it.
248
+ */
249
+ removeFromParent(rebindContexts = true) {
250
+ this.#detachFromParent(rebindContexts);
251
+ }
252
+ #detachFromParent(rebindContexts) {
147
253
  if (this.#parent) {
148
254
  this.#parent.removeChild(this);
149
255
  this.#parent = void 0;
150
- this.#parentUuid = void 0;
151
- for (const [, ctx] of this.#context) {
152
- if (ctx.unsubscribeFromParent) {
153
- ctx.unsubscribeFromParent();
154
- ctx.unsubscribeFromParent = void 0;
256
+ if (rebindContexts) {
257
+ for (const [, ctx] of this.#context) {
258
+ this.#subscribeToParent(ctx);
155
259
  }
156
260
  }
157
261
  this.#unsubscribeAutoDestruction();
262
+ this.#kernel.noteEntityTreeChange(this.#uuid);
158
263
  }
159
264
  }
160
265
  #autoDestructionEnabled = false;
@@ -182,6 +287,15 @@ class Entity {
182
287
  });
183
288
  }
184
289
  }
290
+ /**
291
+ * Binds every context of this entity to its current position in the entity tree -- to the parent
292
+ * if there is one, to the root otherwise. `addChild()` and `removeFromParent()` each do this for
293
+ * the entity they move, so a caller needs this only when it changed the position by other means
294
+ * or wants the binding re-established without knowing which of the two ran.
295
+ *
296
+ * Moving an entity through the kernel is not such a case: both directions bring their own binding,
297
+ * and a third one would reach every `useParentContext()` reader as another change.
298
+ */
185
299
  reSubscribeToParentContexts() {
186
300
  for (const [, ctx] of this.#context) {
187
301
  this.#subscribeToParent(ctx);
@@ -190,9 +304,28 @@ class Entity {
190
304
  dispatchMessageToView(type, data, transferables, traverseChildren = false) {
191
305
  this.#kernel.dispatchMessageToView({ uuid: this.#uuid, type, data, transferables, traverseChildren });
192
306
  }
307
+ /**
308
+ * Hands the events the view sent to whoever listens on this entity, one delivery per event.
309
+ *
310
+ * Each delivery is guarded, and the reason is where this call sits: the kernel makes it from
311
+ * inside a change trail, on a path that builds. Unguarded, a single shadow-object that cannot cope
312
+ * with a single view event would leave through `Kernel.run()` and refuse the whole trail -- the
313
+ * same argument that puts a guard around the `onParentChanged` notification, which is a delivery
314
+ * on a building path as well. The guard is per event, so one that fails costs neither the events
315
+ * behind it nor the caller anything; `emitStrict()` inside it makes the same promise one level
316
+ * down, to the listeners of one event.
317
+ */
193
318
  dispatchViewEvents(events) {
194
319
  for (const { type, data } of events) {
195
- emit(this, onViewEvent, type, data);
320
+ runGuarded(
321
+ this.#kernel.logger,
322
+ // the concrete class is needed here: eventize cannot reduce its emitter conditional
323
+ // (`NonTypedEmitter<this>`) over the polymorphic `this` type, and no overload then matches
324
+ () => emitStrict(this, onViewEvent, type, data),
325
+ "entity view event delivery failed:",
326
+ type,
327
+ this.#uuid
328
+ );
196
329
  }
197
330
  }
198
331
  dispatchViewEvent(type, data) {
@@ -204,11 +337,30 @@ class Entity {
204
337
  getPropertyReader(key) {
205
338
  return this.#getPropSignal(key).get;
206
339
  }
340
+ /**
341
+ * A write head for one property. Every write through it drops the cache behind
342
+ * `truthyProps()`: that cache answers `Kernel.#updateShadowObjects()`, which picks the shadow
343
+ * objects of this entity along the property routes of the registry, and a write the cache does
344
+ * not see routes the entity to a state it no longer has.
345
+ *
346
+ * What comes back is a function of the entity, not the `set` of the signal behind the property.
347
+ * The signalize helpers that take a signal-like -- `isSignal()`, `destroySignal()`, `touch()` --
348
+ * do not recognise it; `getPropertyReader()` hands out the signal's own reader for that.
349
+ *
350
+ * A fresh closure is handed out on every call rather than one cached per key: `SignalAutoMap`
351
+ * hands out "a fresh, live" signal for a key whose signal was destroyed from the outside, so a
352
+ * writer cached against the signal captured on an earlier call could end up closing over a corpse.
353
+ * The call sites this feeds -- `setProperty()` from a change-trail application, at most once per
354
+ * property that actually changed -- do not turn this into a hot path.
355
+ */
207
356
  getPropertyWriter(key) {
208
- return this.#getPropSignal(key).set;
357
+ const signal = this.#getPropSignal(key);
358
+ return (value2, params) => {
359
+ this.clearTruthyPropsCache();
360
+ signal.set(value2, params);
361
+ };
209
362
  }
210
363
  setProperties(properties) {
211
- this.clearTruthyPropsCache();
212
364
  batch(() => {
213
365
  for (const [key, val] of properties) {
214
366
  this.setProperty(key, val);
@@ -260,14 +412,91 @@ class Entity {
260
412
  return this.#findOrCreateContext(name).provide;
261
413
  }
262
414
  provideGlobalContext(name) {
415
+ return this.#findOrCreateGlobalContext(name).signal;
416
+ }
417
+ /**
418
+ * Attaches a provider signal to the context of `name` on this entity and answers with the release
419
+ * that detaches it again.
420
+ *
421
+ * Every provider of one name writes into the single signal that `provideContext()` hands out, so
422
+ * what a consumer reads is what was written last. The release therefore does two things: it cuts
423
+ * this feed, and it then lets a provider that is still attached write its value once more. Without
424
+ * that second step the context would keep whatever the departure left standing -- the `undefined`
425
+ * of a clearing provider, or the last value of one that opted out of it -- even though this entity
426
+ * still has a provider of the name that says otherwise.
427
+ *
428
+ * A value written straight into the signal from `provideContext()` is not a feed and is therefore
429
+ * overwritten by the next release. Feeding a value in through this method is what makes it survive
430
+ * one.
431
+ */
432
+ attachContextProvider(name, provider) {
433
+ const ctx = this.#findOrCreateContext(name);
434
+ return Entity.#attachProviderFeed(provider, ctx.provide, ctx.providerFeeds);
435
+ }
436
+ /**
437
+ * The counterpart of {@link Entity.attachContextProvider} for the global context of `name`.
438
+ *
439
+ * Within one entity the situation is the same one: every provider feeds the single signal this
440
+ * entity contributes to the kernel-wide chain of that name, and a release hands the name back to a
441
+ * provider that stays. Across entities the chain decides on its own -- it resolves to the first
442
+ * entry that holds something, so an entity whose signal falls empty lets the next one through.
443
+ */
444
+ attachGlobalContextProvider(name, provider) {
445
+ const rootCtx = this.#findOrCreateGlobalContext(name);
446
+ return Entity.#attachProviderFeed(provider, rootCtx.signal, rootCtx.providerFeeds);
447
+ }
448
+ static #attachProviderFeed(provider, target, feeds) {
449
+ const feed = link(provider, target);
450
+ feeds.add(feed);
451
+ return () => {
452
+ if (!feeds.delete(feed)) return;
453
+ feed.destroy();
454
+ Entity.#handOverToRemainingProvider(feeds);
455
+ };
456
+ }
457
+ /**
458
+ * Lets the provider that stays write its value into the context signal again.
459
+ *
460
+ * The set iterates in the order the providers were attached and the loop keeps the last hit, so the
461
+ * winner is the one attached last that still holds a value. Attachment order is the order in which the
462
+ * providers took the name: attaching feeds the value straight through, so a later attachment writes
463
+ * over an earlier one, and the hand-over falls back on that order instead of inventing one of its own.
464
+ * It is not the order of the writes -- a provider that writes to its signal after attaching carries
465
+ * the name until the next departure, and the hand-over does not restore that write, because what this
466
+ * entity keeps on file is its providers and not the sequence in which they wrote. Providers holding
467
+ * nothing are passed over -- by the same `!= null` rule with which `SignalsPath` resolves a context
468
+ * chain, and for the same reason: a provider without a value has nothing to say about the name, and
469
+ * electing it would clear a name that is still being provided.
470
+ *
471
+ * A feed whose link is destroyed is passed over as well. A shadow-object owns the signal it was
472
+ * handed and may end it early, which destroys the link without the release ever having run: such a
473
+ * feed still reports a value through its source while its writes go nowhere, so electing it would
474
+ * leave the write of the departure standing, silently and over a provider that is alive.
475
+ *
476
+ * `touch()` is what makes the winner write, because `SignalLink.write()` is protected: touching is
477
+ * the only public way to push the current value of a source through its link again, and the source
478
+ * of a provider that merely stays has no reason to change.
479
+ *
480
+ * Where no remaining feed qualifies, nothing is written: then what the departure left stands,
481
+ * which is the `undefined` of a clearing provider or the last value of one that opted out.
482
+ */
483
+ static #handOverToRemainingProvider(feeds) {
484
+ let winner;
485
+ for (const feed of feeds) {
486
+ if (!feed.isDestroyed && feed.source.value != null) winner = feed;
487
+ }
488
+ winner?.touch();
489
+ }
490
+ #findOrCreateGlobalContext(name) {
263
491
  if (this.#rootContexts.has(name)) {
264
- return this.#rootContexts.get(name).signal;
492
+ return this.#rootContexts.get(name);
265
493
  }
266
494
  const rootCtx = this.#kernel.findOrCreateRootContext(name);
267
495
  const signal = createSignal();
268
496
  const cleanup = rootCtx.add(signal);
269
- this.#rootContexts.set(name, { cleanup, signal });
270
- return signal;
497
+ const ctx = { cleanup, signal, providerFeeds: /* @__PURE__ */ new Set() };
498
+ this.#rootContexts.set(name, ctx);
499
+ return ctx;
271
500
  }
272
501
  #findOrCreateContext(name) {
273
502
  if (this.#context.has(name)) {
@@ -278,9 +507,9 @@ class Entity {
278
507
  const context = createSignal();
279
508
  const valuePath = new SignalsPath([provide, inherited]);
280
509
  const unsubscribePathValue = on(valuePath, SignalsPath.Value, (val) => {
281
- deferContextValueUpdate(context, val);
510
+ deferContextValueUpdate(this.#kernel, context, val, name, this.#uuid);
282
511
  });
283
- const ctx = { name, inherited, provide, context, valuePath, unsubscribePathValue };
512
+ const ctx = { name, inherited, provide, context, valuePath, providerFeeds: /* @__PURE__ */ new Set(), unsubscribePathValue };
284
513
  this.#context.set(name, ctx);
285
514
  this.#subscribeToParent(ctx);
286
515
  return ctx;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/in-the-dark/Entity.ts"],
4
- "sourcesContent": ["import {emit, off, on, once, Priority} from '@spearwolf/eventize';\nimport {\n batch,\n createSignal,\n link,\n Signal,\n SignalAutoMap,\n type SignalReader,\n type SignalWriter,\n value,\n} from '@spearwolf/signalize';\nimport type {IComponentEvent} from '../types.js';\nimport {onDestroy, onViewEvent} from './events.js';\nimport {Kernel} from './Kernel.js';\nimport {SignalsPath} from './SignalsPath.js';\n\ntype ContextNameType = string | symbol;\n\ninterface IContextValue {\n name: ContextNameType;\n inherited: Signal<unknown>;\n provide: Signal<unknown>;\n context: Signal<unknown>;\n valuePath: SignalsPath;\n\n unsubscribePathValue: () => void;\n unsubscribeFromParent?: () => void;\n}\n\nconst updateContextValues: Map<Signal<unknown>, unknown> = new Map();\nlet requestedContextValueBatchUpdate = false;\n\nconst deferContextValueUpdate = (sig: Signal<unknown>, val: unknown) => {\n updateContextValues.set(sig, val);\n if (!requestedContextValueBatchUpdate) {\n requestedContextValueBatchUpdate = true;\n queueMicrotask(() => {\n requestedContextValueBatchUpdate = false;\n const contextValues = Array.from(updateContextValues.entries());\n updateContextValues.clear();\n for (const [sig, val] of contextValues) {\n sig.set(val);\n }\n });\n }\n};\n\n/**\n * An entity has a parent and children, replicating the hierarchy of view-components.\n *\n * A signal is created for each view-component property.\n *\n * Shadow-objects can use the signal properties via the entity.\n */\nexport class Entity {\n #kernel: Kernel;\n #uuid: string;\n\n #props = new SignalAutoMap();\n #context: Map<ContextNameType, IContextValue> = new Map();\n\n #rootContexts: Map<ContextNameType, {cleanup: () => void; signal: Signal<any>}> = new Map();\n\n #parentUuid?: string;\n #parent?: Entity;\n\n #childrenUuids: Set<string> = new Set();\n #children: Entity[] = [];\n\n #order = 0;\n\n get kernel(): Kernel {\n return this.#kernel;\n }\n\n get uuid(): string {\n return this.#uuid;\n }\n\n get order(): number {\n return this.#order;\n }\n\n set order(value: number) {\n if (this.#order !== value) {\n this.#order = value;\n if (this.#parentUuid) {\n this.parent!.resortChildren();\n }\n }\n }\n\n get parentUuid(): string | undefined {\n return this.#parentUuid || undefined;\n }\n\n set parentUuid(parentUuid: string | undefined) {\n if (this.#parentUuid !== parentUuid) {\n // Resolve the new parent FIRST so an unknown-uuid throw doesn't orphan us mid-mutation.\n const nextParent = parentUuid ? this.#kernel.getEntity(parentUuid) : undefined;\n\n this.removeFromParent();\n\n this.#parentUuid = parentUuid || undefined;\n this.#parent = nextParent;\n\n if (this.#parent) {\n this.#parent.addChild(this);\n }\n\n this.#updateAutoDestructionSubscription();\n }\n }\n\n get parent(): Entity | undefined {\n if (!this.#parent && this.#parentUuid) {\n this.#parent = this.#kernel.getEntity(this.#parentUuid);\n }\n return this.#parent;\n }\n\n set parent(parent: Entity | undefined) {\n this.parentUuid = parent?.uuid;\n }\n\n get hasParent(): boolean {\n return !!this.#parentUuid;\n }\n\n get children(): readonly Entity[] {\n return this.#children;\n }\n\n constructor(kernel: Kernel, uuid: string) {\n this.#kernel = kernel;\n this.#uuid = uuid;\n once(this as Entity, onDestroy, Priority.Min, this);\n }\n\n traverse(callback: (entity: Entity) => void) {\n callback(this);\n for (const child of this.#children) {\n child.traverse(callback);\n }\n }\n\n [onDestroy]() {\n this.#props.clear();\n off(this);\n\n this.#autoDestructionSubscription?.();\n\n for (const rootCtx of this.#rootContexts.values()) {\n rootCtx.cleanup();\n rootCtx.signal.destroy();\n }\n this.#rootContexts.clear();\n\n for (const ctx of this.#context.values()) {\n ctx.context.set(undefined);\n ctx.unsubscribePathValue();\n ctx.unsubscribeFromParent?.();\n ctx.valuePath.dispose();\n ctx.inherited.destroy();\n ctx.provide.destroy();\n ctx.context.destroy();\n }\n\n this.#parentUuid = undefined;\n this.#parent = undefined;\n\n this.#childrenUuids.clear();\n this.#children.length = 0;\n }\n\n addChild(child: Entity) {\n if (this.#children.length === 0) {\n this.#childrenUuids.add(child.uuid);\n this.#children.push(child);\n // this.emit(onAddChild, this, child);\n // child.emit(onAddToParent, child, this);\n return;\n }\n\n if (this.#childrenUuids.has(child.uuid)) {\n throw new Error(`child with uuid: ${child.uuid} already exists! parentUuid: ${this.uuid}`);\n }\n\n this.#childrenUuids.add(child.uuid);\n this.#children.push(child);\n\n this.resortChildren();\n\n for (const [, ctx] of child.#context) {\n child.#subscribeToParent(ctx);\n }\n\n // this.emit(onAddChild, this, child);\n // child.emit(onAddToParent, child, this);\n }\n\n resortChildren() {\n this.#children.sort((a, b) => a.order - b.order);\n }\n\n removeChild(child: Entity) {\n if (this.#childrenUuids.has(child.uuid)) {\n this.#childrenUuids.delete(child.uuid);\n this.#children.splice(this.#children.indexOf(child), 1);\n // this.emit(onRemoveChild, this, child);\n }\n }\n\n removeFromParent() {\n if (this.#parent) {\n // const prevParent = this.#parent;\n\n this.#parent.removeChild(this);\n\n this.#parent = undefined;\n this.#parentUuid = undefined;\n\n for (const [, ctx] of this.#context) {\n if (ctx.unsubscribeFromParent) {\n ctx.unsubscribeFromParent();\n ctx.unsubscribeFromParent = undefined;\n }\n }\n\n this.#unsubscribeAutoDestruction();\n\n // this.emit(onRemoveFromParent, this, prevParent);\n }\n }\n\n #autoDestructionEnabled = false;\n #autoDestructionSubscription?: () => void;\n\n get autoDestructionOnParentRemoval(): boolean {\n return this.#autoDestructionEnabled;\n }\n\n set autoDestructionOnParentRemoval(autoDestruct: boolean) {\n if (this.#autoDestructionEnabled === autoDestruct) return;\n this.#autoDestructionEnabled = autoDestruct;\n this.#updateAutoDestructionSubscription();\n }\n\n #unsubscribeAutoDestruction() {\n if (this.#autoDestructionSubscription) {\n this.#autoDestructionSubscription();\n this.#autoDestructionSubscription = undefined;\n }\n }\n\n #updateAutoDestructionSubscription() {\n this.#unsubscribeAutoDestruction();\n if (this.#autoDestructionEnabled && this.#parent) {\n this.#autoDestructionSubscription = once(this.#parent, onDestroy, Priority.Max, () => {\n this.#autoDestructionSubscription = undefined;\n this.#kernel.destroyEntity(this.#uuid);\n });\n }\n }\n\n reSubscribeToParentContexts() {\n for (const [, ctx] of this.#context) {\n this.#subscribeToParent(ctx);\n }\n }\n\n dispatchMessageToView(type: string, data?: unknown, transferables?: Transferable[], traverseChildren = false) {\n this.#kernel.dispatchMessageToView({uuid: this.#uuid, type, data, transferables, traverseChildren});\n }\n\n dispatchViewEvents(events: IComponentEvent[]) {\n for (const {type, data} of events) {\n emit(this as Entity, onViewEvent, type, data);\n }\n }\n\n dispatchViewEvent(type: string, data: unknown) {\n this.dispatchViewEvents([{type, data}]);\n }\n\n #getPropSignal<T = unknown>(key: string): Signal<T> {\n return this.#props.get<T>(key);\n }\n\n getPropertyReader<T = unknown>(key: string): SignalReader<T> {\n return this.#getPropSignal<T>(key).get;\n }\n\n getPropertyWriter<T = unknown>(key: string): SignalWriter<T> {\n return this.#getPropSignal<T>(key).set;\n }\n\n setProperties(properties: [string, unknown][]) {\n this.clearTruthyPropsCache();\n batch(() => {\n for (const [key, val] of properties) {\n this.setProperty(key, val);\n }\n });\n }\n\n setProperty(key: string, value: unknown) {\n this.getPropertyWriter(key)(value);\n }\n\n getProperty<T = unknown>(key: string): T {\n return value(this.getPropertyReader<T>(key));\n }\n\n propKeys(): string[] {\n return Array.from(this.#props.keys()) as string[];\n }\n\n propEntries(): [string, unknown][] {\n return Array.from(this.#props.entries()).map(([key, sig]) => [key, sig.value]) as [string, unknown][];\n }\n\n #truthyPropsCache: Set<string> | undefined;\n\n clearTruthyPropsCache() {\n this.#truthyPropsCache = undefined;\n }\n\n truthyProps(): Set<string> | undefined {\n if (this.#truthyPropsCache) {\n return this.#truthyPropsCache.size ? this.#truthyPropsCache : undefined;\n }\n const truthyProps = new Set<string>();\n for (const [key, sig] of this.#props.entries()) {\n if (typeof key === 'string') {\n const val = sig.value;\n if (val != null && val !== false && val !== '') {\n truthyProps.add(key);\n }\n }\n }\n this.#truthyPropsCache = truthyProps;\n return truthyProps.size ? truthyProps : undefined;\n }\n\n hasContext(name: ContextNameType): boolean {\n return this.#context.has(name);\n }\n\n useContext<T = unknown>(name: ContextNameType): SignalReader<T> {\n return this.#findOrCreateContext(name).context.get as SignalReader<T>;\n }\n\n useParentContext<T = unknown>(name: ContextNameType): SignalReader<T> {\n return this.#findOrCreateContext(name).inherited.get as SignalReader<T>;\n }\n\n provideContext<T = unknown>(name: ContextNameType): Signal<T> {\n return this.#findOrCreateContext(name).provide as Signal<T>;\n }\n\n provideGlobalContext<T = unknown>(name: ContextNameType): Signal<T> {\n if (this.#rootContexts.has(name)) {\n return this.#rootContexts.get(name)!.signal as Signal<T>;\n }\n const rootCtx = this.#kernel.findOrCreateRootContext(name);\n const signal = createSignal<T>();\n const cleanup = rootCtx.add(signal);\n this.#rootContexts.set(name, {cleanup, signal});\n return signal;\n }\n\n #findOrCreateContext(name: ContextNameType): IContextValue {\n if (this.#context.has(name)) {\n return this.#context.get(name)!;\n }\n\n const inherited = createSignal();\n const provide = createSignal();\n const context = createSignal();\n\n const valuePath = new SignalsPath([provide, inherited]);\n\n const unsubscribePathValue = on(valuePath, SignalsPath.Value, (val) => {\n deferContextValueUpdate(context, val);\n });\n\n const ctx: IContextValue = {name, inherited, provide, context, valuePath, unsubscribePathValue};\n this.#context.set(name, ctx);\n\n this.#subscribeToParent(ctx);\n\n return ctx;\n }\n\n #subscribeToParent(ctx: IContextValue) {\n ctx.unsubscribeFromParent?.();\n ctx.unsubscribeFromParent = undefined;\n if (this.parent) {\n const parentCtx = this.parent.#findOrCreateContext(ctx.name);\n const linkToParent = link(parentCtx.context, ctx.inherited);\n ctx.unsubscribeFromParent = linkToParent.destroy.bind(linkToParent);\n } else {\n const rootCtx = this.#kernel.findOrCreateRootContext(ctx.name);\n const linkToRoot = link(rootCtx.value$, ctx.inherited);\n ctx.unsubscribeFromParent = linkToRoot.destroy.bind(linkToRoot);\n }\n }\n}"],
5
- "mappings": "AAAA,SAAQ,MAAM,KAAK,IAAI,MAAM,gBAAe;AAC5C;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAGA;AAAA,OACK;AAEP,SAAQ,WAAW,mBAAkB;AACrC,SAAQ,cAAa;AACrB,SAAQ,mBAAkB;AAe1B,MAAM,sBAAqD,oBAAI,IAAI;AACnE,IAAI,mCAAmC;AAEvC,MAAM,0BAA0B,CAAC,KAAsB,QAAiB;AACtE,sBAAoB,IAAI,KAAK,GAAG;AAChC,MAAI,CAAC,kCAAkC;AACrC,uCAAmC;AACnC,mBAAe,MAAM;AACnB,yCAAmC;AACnC,YAAM,gBAAgB,MAAM,KAAK,oBAAoB,QAAQ,CAAC;AAC9D,0BAAoB,MAAM;AAC1B,iBAAW,CAACA,MAAKC,IAAG,KAAK,eAAe;AACtC,QAAAD,KAAI,IAAIC,IAAG;AAAA,MACb;AAAA,IACF,CAAC;AAAA,EACH;AACF;AASO,MAAM,OAAO;AAAA,EAClB;AAAA,EACA;AAAA,EAEA,SAAS,IAA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K,SAAS,IAAI,IAAI;AAAA,IAC/B;AAEA,UAAM,YAAY,aAAa;AAC/B,UAAM,UAAU,aAAa;AAC7B,UAAM,UAAU,aAAa;AAE7B,UAAM,YAAY,IAAI,YAAY,CAAC,SAAS,SAAS,CAAC;AAEtD,UAAM,uBAAuB,GAAG,WAAW,YAAY,OAAO,CAAC,QAAQ;AACrE,8BAAwB,SAAS,GAAG;AAAA,IACtC,CAAC;AAED,UAAM,MAAqB,EAAC,MAAM,WAAW,SAAS,SAAS,WAAW,qBAAoB;AAC9F,SAAK,SAAS,IAAI,MAAM,GAAG;AAE3B,SAAK,mBAAmB,GAAG;AAE3B,WAAO;AAAA,EACT;AAAA,EAEA,mBAAmB,KAAoB;AACrC,QAAI,wBAAwB;AAC5B,QAAI,wBAAwB;AAC5B,QAAI,KAAK,QAAQ;AACf,YAAM,YAAY,KAAK,OAAO,qBAAqB,IAAI,IAAI;AAC3D,YAAM,eAAe,KAAK,UAAU,SAAS,IAAI,SAAS;AAC1D,UAAI,wBAAwB,aAAa,QAAQ,KAAK,YAAY;AAAA,IACpE,OAAO;AACL,YAAM,UAAU,KAAK,QAAQ,wBAAwB,IAAI,IAAI;AAC7D,YAAM,aAAa,KAAK,QAAQ,QAAQ,IAAI,SAAS;AACrD,UAAI,wBAAwB,WAAW,QAAQ,KAAK,UAAU;AAAA,IAChE;AAAA,EACF;AACF;",
6
- "names": ["sig", "val", "value"]
4
+ "sourcesContent": ["import {emitStrict, off, on, once, Priority} from '@spearwolf/eventize';\nimport {\n batch,\n createSignal,\n link,\n Signal,\n SignalAutoMap,\n type SignalLink,\n type SignalReader,\n type SignalWriter,\n type SignalWriterParams,\n value,\n} from '@spearwolf/signalize';\nimport type {ComponentPropertiesType, IComponentEvent} from '../types.js';\nimport {MicrotaskCollector} from '../utils/MicrotaskCollector.js';\nimport {runGuarded} from '../utils/runGuarded.js';\nimport {onDestroy, onViewEvent} from './events.js';\nimport {Kernel} from './Kernel.js';\nimport {SignalsPath} from './SignalsPath.js';\n\ntype ContextNameType = string | symbol;\n\ninterface IContextValue {\n name: ContextNameType;\n inherited: Signal<unknown>;\n provide: Signal<unknown>;\n context: Signal<unknown>;\n valuePath: SignalsPath;\n\n /**\n * The links that feed `provide`, one per provider of this name on this entity. They all write\n * into that one signal, so the value standing there is the one written last -- and the set is\n * what makes it possible to ask a provider that is still here for its value once another one\n * lets go. See {@link Entity.attachContextProvider}.\n */\n providerFeeds: Set<SignalLink<any>>;\n\n unsubscribePathValue: () => void;\n unsubscribeFromParent?: (() => void) | undefined;\n}\n\ninterface IRootContextValue {\n signal: Signal<any>;\n\n /** The links that feed `signal`, exactly as {@link IContextValue.providerFeeds} feeds `provide`. */\n providerFeeds: Set<SignalLink<any>>;\n\n /** Takes the entity's signal back out of the kernel-wide chain of this name. */\n cleanup: () => void;\n}\n\n/** One context value an entity has waiting for its readers in the current round. */\ninterface IDeferredContextValue {\n value: unknown;\n name: ContextNameType;\n uuid: string;\n}\n\n/**\n * The context values waiting to reach their readers, one collector per kernel.\n *\n * Per kernel rather than per module for two reasons that are the same one: a write below can fail,\n * and what it is reported to is a logger, of which there is one per kernel; and an application\n * running two shadow environments in one realm would otherwise hand the values of one to a round\n * the other started. The kernel is the key, so a collector reaches no further than the kernel it\n * belongs to and needs no teardown of its own -- every round empties it, and the last one is\n * emptied by the kernel going out of reach.\n */\nconst contextValueCollectors = new WeakMap<Kernel, MicrotaskCollector<Signal<unknown>, IDeferredContextValue>>();\n\nconst collectorOf = (kernel: Kernel): MicrotaskCollector<Signal<unknown>, IDeferredContextValue> => {\n let collector = contextValueCollectors.get(kernel);\n if (collector == null) {\n collector = new MicrotaskCollector<Signal<unknown>, IDeferredContextValue>((contextValues) => {\n for (const [contextSignal, entry] of contextValues) {\n // one hand-over is one context value: `set()` runs the effects that read it synchronously\n // and throws what one of them threw\n runGuarded(\n kernel.logger,\n () => contextSignal.set(entry.value),\n `an effect of a context value failed (${String(entry.name)}):`,\n entry.uuid,\n );\n }\n });\n contextValueCollectors.set(kernel, collector);\n }\n return collector;\n};\n\n/**\n * Collects the context values written in one task and hands them to their readers a microtask\n * later, one at a time. A second value for the same signal replaces the one waiting, so a name\n * written twice in a task reaches its readers once, with the value that stood at the end of it.\n */\nconst deferContextValueUpdate = (kernel: Kernel, signal: Signal<unknown>, val: unknown, name: ContextNameType, uuid: string) => {\n collectorOf(kernel).add(signal, {value: val, name, uuid});\n};\n\n/**\n * An entity has a parent and children, replicating the hierarchy of view-components.\n *\n * A signal is created for each view-component property.\n *\n * Shadow-objects can use the signal properties via the entity.\n */\nexport class Entity {\n #kernel: Kernel;\n #uuid: string;\n\n #props = new SignalAutoMap();\n #context: Map<ContextNameType, IContextValue> = new Map();\n\n #rootContexts: Map<ContextNameType, IRootContextValue> = new Map();\n\n // There is one place the parent is kept: `parentUuid` answers from `#parent.uuid`, so a half-set\n // link -- a uuid with no matching entity, or an entity with no uuid to show for it -- has no field\n // left to hold it in.\n #parent?: Entity | undefined;\n\n #childrenUuids: Set<string> = new Set();\n #children: Entity[] = [];\n\n #order = 0;\n\n #isReleased = false;\n\n get kernel(): Kernel {\n return this.#kernel;\n }\n\n get uuid(): string {\n return this.#uuid;\n }\n\n get order(): number {\n return this.#order;\n }\n\n set order(value: number) {\n if (this.#order !== value) {\n this.#order = value;\n if (this.#parent) {\n this.#parent.resortChildren();\n }\n // The place among the siblings is part of the traversal order the kernel caches.\n this.#kernel.noteEntityTreeChange(this.#uuid);\n }\n }\n\n get parentUuid(): string | undefined {\n return this.#parent?.uuid;\n }\n\n set parentUuid(parentUuid: string | undefined) {\n if (this.#parent?.uuid !== parentUuid) {\n // Resolve the new parent FIRST so an unknown-uuid throw doesn't orphan us mid-mutation.\n const nextParent = parentUuid ? this.#kernel.getEntity(parentUuid) : undefined;\n\n if (nextParent != null) {\n this.assertAttachableTo(nextParent);\n }\n\n // A parent that follows right away binds the contexts itself, so the detachment skips it. The\n // entity keeps reading the parent it leaves until the one it joins takes over.\n this.#detachFromParent(nextParent == null);\n\n this.#parent = nextParent;\n\n if (this.#parent) {\n this.#parent.addChild(this);\n }\n\n this.#updateAutoDestructionSubscription();\n\n // The link is written; the kernel writes down where the entity stands now. This is the route\n // a shadow-object takes when it moves an entity without going through `Kernel.setParent()`,\n // and the report is the only thing the two share -- the `onParentChanged` notification stays\n // with `setParent()`.\n this.#kernel.noteEntityTreeChange(this.#uuid);\n }\n }\n\n get parent(): Entity | undefined {\n return this.#parent;\n }\n\n set parent(parent: Entity | undefined) {\n this.parentUuid = parent?.uuid;\n }\n\n // Reads the same field `parent` and `parentUuid` do, so `Kernel.noteEntityTreeChange()` -- which\n // reads `hasParent` to decide whether the uuid belongs in the root set -- sees what they see.\n get hasParent(): boolean {\n return !!this.#parent;\n }\n\n get children(): readonly Entity[] {\n return this.#children;\n }\n\n constructor(kernel: Kernel, uuid: string) {\n this.#kernel = kernel;\n this.#uuid = uuid;\n }\n\n traverse(callback: (entity: Entity) => void) {\n this.#traverse(callback, new Set());\n }\n\n // The visited set guards the one traversal an outside shadow object drives, over a tree it did not\n // build. `addChild()` writes a children list without touching the parent link, so no ancestor check\n // can cover it.\n #traverse(callback: (entity: Entity) => void, visited: Set<Entity>) {\n if (visited.has(this)) return;\n visited.add(this);\n\n callback(this);\n\n for (const child of this.#children) {\n child.#traverse(callback, visited);\n }\n }\n\n /**\n * Releases everything the entity holds: its properties, its subscriptions, its contexts and its place\n * in the entity tree.\n *\n * It runs once, whichever way it is reached. The kernel reaches it directly, right behind the\n * destruction notification it sends on the entity, so that every listener on that notification has\n * had its turn first -- down to `Priority.Min`, which is nobody's but the caller's. The entity is\n * not a listener on its own notification: registering it in the constructor would put it ahead of\n * anything registered at the same priority, because eventize breaks a tie by order of registration,\n * and the bulk `off(this)` below would then take the listeners still waiting in that delivery with\n * it. The flag makes a second call cost nothing and keeps every step below written for a\n * single run: `kernel.getEntity()` hands the entity to anyone, and this method is as reachable as\n * the rest of it.\n *\n * The flag is raised before the first step rather than after the last, because that is what a release\n * running twice would cost: the steps below are written for one pass, not for a repeat.\n *\n * Every step below runs behind a guard of its own, the way `ShadowObjectCreationScope.tearDown()`\n * gives each of its steps one: a step that throws is reported through the kernel's logger, named by\n * the step and by the uuid of this entity, and costs only itself -- the steps behind it still run.\n * The method therefore never throws to its own caller. The plain resets at the end -- clearing a\n * collection, overwriting a field -- cannot throw and run unguarded, exactly as `tearDown()` empties\n * its own sets at the end.\n */\n [onDestroy]() {\n if (this.#isReleased) return;\n this.#isReleased = true;\n\n // `SignalAutoMap.clear()` destroys every property signal and only then re-raises whatever a\n // dependent effect's cleanup threw along the way, so it belongs behind a guard of its own like\n // every other step here -- it is not the plain reset it looks like.\n this.#runGuarded('properties', () => this.#props.clear());\n this.#runGuarded('listeners', () => off(this));\n this.#runGuarded('auto-destruction subscription', () => this.#autoDestructionSubscription?.());\n\n for (const rootCtx of this.#rootContexts.values()) {\n this.#runGuarded('global context cleanup', () => rootCtx.cleanup());\n this.#runGuarded('global context signal', () => rootCtx.signal.destroy());\n }\n\n for (const ctx of this.#context.values()) {\n this.#runGuarded('context value reset', () => ctx.context.set(undefined));\n this.#runGuarded('context value subscription', () => ctx.unsubscribePathValue());\n this.#runGuarded('context parent subscription', () => ctx.unsubscribeFromParent?.());\n this.#runGuarded('context value path', () => ctx.valuePath.dispose());\n this.#runGuarded('inherited context signal', () => ctx.inherited.destroy());\n this.#runGuarded('provided context signal', () => ctx.provide.destroy());\n this.#runGuarded('context signal', () => ctx.context.destroy());\n }\n\n this.#rootContexts.clear();\n this.#context.clear();\n\n this.#parent = undefined;\n\n this.#childrenUuids.clear();\n this.#children.length = 0;\n }\n\n /**\n * Isolates one release step from the ones around it: a step that throws is reported through the\n * kernel's logger and does not stop `[onDestroy]()` from reaching the steps that follow. The\n * report goes out through the shared `runGuarded()`; what this wrapper adds is the label of the\n * step and the uuid of the entity it belongs to.\n */\n #runGuarded(step: string, run: () => void): void {\n runGuarded(this.#kernel.logger, run, `entity teardown step failed (${step}):`, this.#uuid);\n }\n\n /**\n * Refuses a parent that would close the entity tree into a ring: the entity itself, or an entity that\n * already sits below it. The walk follows the parent chain upwards, which is a chain exactly because\n * this guard keeps it one.\n *\n * `Kernel.setParent()` calls it before it detaches, and the `parentUuid` setter before it resolves the\n * link, so a refused attachment leaves the entity where it was instead of orphaned halfway through.\n * `ViewComponent.addChild()` guards the same thing on the view side.\n */\n assertAttachableTo(nextParent: Entity) {\n for (let e: Entity | undefined = nextParent; e != null; e = e.parent) {\n if (e === this) {\n throw new Error(\n `entity \"${nextParent.uuid}\" cannot become the parent of \"${this.uuid}\": it is the entity itself or one of its descendants`,\n );\n }\n }\n }\n\n /**\n * Puts `child` into the children list, at its place among the siblings.\n *\n * Nothing here notifies. Neither this method nor {@link Entity.removeChild} nor a detachment\n * sends anything to a listener on the entity -- the one notification over a moved entity is\n * `onParentChanged`, and `Kernel.setParent()` is the call that sends it.\n */\n addChild(child: Entity) {\n if (this.#childrenUuids.has(child.uuid)) {\n throw new Error(`child with uuid: ${child.uuid} already exists! parentUuid: ${this.uuid}`);\n }\n\n this.#childrenUuids.add(child.uuid);\n this.#insertChildInOrder(child);\n\n // the child may have created its contexts while it was still unattached: they hang on the root\n // of the entity context tree until something binds them to the parent they now have\n for (const [, ctx] of child.#context) {\n child.#subscribeToParent(ctx);\n }\n }\n\n /**\n * Puts a child at its place among the siblings, so building a subtree costs one insertion per\n * child. The scan runs from the end because children usually arrive with an equal or rising\n * `order`, which makes the common case a plain append. A child lands behind every sibling that\n * shares its `order` -- the same place a stable sort would give it.\n *\n * The result only matches a full sort while `#children` is already sorted when the insertion\n * starts, so name what keeps it that way: the insertion here preserves the order, `removeChild()`\n * cuts an element out with `splice`, the destroy handler empties the list, and the `order` setter\n * re-sorts through the parent. That last one is the condition worth stating, because it needs the\n * child to know its parent -- the parent link has to be established. Every way an entity is\n * attached inside this class goes through the `parentUuid` setter, which sets the parent before it\n * calls `addChild()`. A caller that reaches for `addChild()` on its own leaves the child without a\n * parent link, and a later `order` on such a child never reaches this list.\n */\n #insertChildInOrder(child: Entity) {\n let i = this.#children.length;\n while (i > 0 && child.order < this.#children[i - 1]!.order) i--;\n this.#children.splice(i, 0, child);\n }\n\n resortChildren() {\n this.#children.sort((a, b) => a.order - b.order);\n }\n\n removeChild(child: Entity) {\n // The identity decides here, not the uuid: `indexOf` answers -1 for an entity this list\n // does not hold, and a `splice(-1, 1)` on that answer would cut the last child out\n // instead of none. The ordered uuid lists of `ComponentContext` carry the same guard where\n // they cut a uuid out.\n const idx = this.#children.indexOf(child);\n if (idx !== -1) {\n this.#childrenUuids.delete(child.uuid);\n this.#children.splice(idx, 1);\n }\n }\n\n /**\n * @param rebindContexts bind every context back to the root of the entity context tree. An entity\n * that carries a context out of a subtree keeps following the value it can still see, rather\n * than freezing on the last one the former parent held. Only a caller that attaches the entity\n * to the next parent in the same breath passes `false` -- that parent binds the contexts itself,\n * and the detour over the root would be visible to `useParentContext()`, which hands out the\n * inherited value without the microtask collector `useContext()` has in front of it.\n */\n removeFromParent(rebindContexts = true) {\n this.#detachFromParent(rebindContexts);\n }\n\n #detachFromParent(rebindContexts: boolean) {\n // The field `parent` and `parentUuid` both answer from: clearing it here clears what either\n // getter would report, with nothing left over for a second check to find.\n if (this.#parent) {\n this.#parent.removeChild(this);\n\n this.#parent = undefined;\n\n if (rebindContexts) {\n for (const [, ctx] of this.#context) {\n this.#subscribeToParent(ctx);\n }\n }\n\n this.#unsubscribeAutoDestruction();\n\n // Detached is a place too: an entity with no parent is a root, and the root set is where\n // every traversal starts.\n this.#kernel.noteEntityTreeChange(this.#uuid);\n }\n }\n\n #autoDestructionEnabled = false;\n #autoDestructionSubscription?: (() => void) | undefined;\n\n get autoDestructionOnParentRemoval(): boolean {\n return this.#autoDestructionEnabled;\n }\n\n set autoDestructionOnParentRemoval(autoDestruct: boolean) {\n if (this.#autoDestructionEnabled === autoDestruct) return;\n this.#autoDestructionEnabled = autoDestruct;\n this.#updateAutoDestructionSubscription();\n }\n\n #unsubscribeAutoDestruction() {\n if (this.#autoDestructionSubscription) {\n this.#autoDestructionSubscription();\n this.#autoDestructionSubscription = undefined;\n }\n }\n\n #updateAutoDestructionSubscription() {\n this.#unsubscribeAutoDestruction();\n if (this.#autoDestructionEnabled && this.#parent) {\n this.#autoDestructionSubscription = once(this.#parent, onDestroy, Priority.Max, () => {\n this.#autoDestructionSubscription = undefined;\n this.#kernel.destroyEntity(this.#uuid);\n });\n }\n }\n\n /**\n * Binds every context of this entity to its current position in the entity tree -- to the parent\n * if there is one, to the root otherwise. `addChild()` and `removeFromParent()` each do this for\n * the entity they move, so a caller needs this only when it changed the position by other means\n * or wants the binding re-established without knowing which of the two ran.\n *\n * Moving an entity through the kernel is not such a case: both directions bring their own binding,\n * and a third one would reach every `useParentContext()` reader as another change.\n */\n reSubscribeToParentContexts() {\n for (const [, ctx] of this.#context) {\n this.#subscribeToParent(ctx);\n }\n }\n\n dispatchMessageToView(type: string, data?: unknown, transferables?: Transferable[], traverseChildren = false) {\n this.#kernel.dispatchMessageToView({uuid: this.#uuid, type, data, transferables, traverseChildren});\n }\n\n /**\n * Hands the events the view sent to whoever listens on this entity, one delivery per event.\n *\n * Each delivery is guarded, and the reason is where this call sits: the kernel makes it from\n * inside a change trail, on a path that builds. Unguarded, a single shadow-object that cannot cope\n * with a single view event would leave through `Kernel.run()` and refuse the whole trail -- the\n * same argument that puts a guard around the `onParentChanged` notification, which is a delivery\n * on a building path as well. The guard is per event, so one that fails costs neither the events\n * behind it nor the caller anything; `emitStrict()` inside it makes the same promise one level\n * down, to the listeners of one event.\n */\n dispatchViewEvents(events: IComponentEvent[]) {\n for (const {type, data} of events) {\n runGuarded(\n this.#kernel.logger,\n // the concrete class is needed here: eventize cannot reduce its emitter conditional\n // (`NonTypedEmitter<this>`) over the polymorphic `this` type, and no overload then matches\n () => emitStrict(this as Entity, onViewEvent, type, data),\n 'entity view event delivery failed:',\n type,\n this.#uuid,\n );\n }\n }\n\n dispatchViewEvent(type: string, data: unknown) {\n this.dispatchViewEvents([{type, data}]);\n }\n\n #getPropSignal<T = unknown>(key: string): Signal<T> {\n return this.#props.get<T>(key);\n }\n\n getPropertyReader<T = unknown>(key: string): SignalReader<T> {\n return this.#getPropSignal<T>(key).get;\n }\n\n /**\n * A write head for one property. Every write through it drops the cache behind\n * `truthyProps()`: that cache answers `Kernel.#updateShadowObjects()`, which picks the shadow\n * objects of this entity along the property routes of the registry, and a write the cache does\n * not see routes the entity to a state it no longer has.\n *\n * What comes back is a function of the entity, not the `set` of the signal behind the property.\n * The signalize helpers that take a signal-like -- `isSignal()`, `destroySignal()`, `touch()` --\n * do not recognise it; `getPropertyReader()` hands out the signal's own reader for that.\n *\n * A fresh closure is handed out on every call rather than one cached per key: `SignalAutoMap`\n * hands out \"a fresh, live\" signal for a key whose signal was destroyed from the outside, so a\n * writer cached against the signal captured on an earlier call could end up closing over a corpse.\n * The call sites this feeds -- `setProperty()` from a change-trail application, at most once per\n * property that actually changed -- do not turn this into a hot path.\n */\n getPropertyWriter<T = unknown>(key: string): SignalWriter<T> {\n const signal = this.#getPropSignal<T>(key);\n return (value: unknown, params?: SignalWriterParams<T>) => {\n this.clearTruthyPropsCache();\n signal.set(value as T, params);\n };\n }\n\n setProperties(properties: ComponentPropertiesType) {\n batch(() => {\n // an entry that names only the key sets the property to `undefined` \u2014 the key is there, the value is not\n for (const [key, val] of properties) {\n this.setProperty(key, val);\n }\n });\n }\n\n setProperty(key: string, value: unknown) {\n this.getPropertyWriter(key)(value);\n }\n\n getProperty<T = unknown>(key: string): T {\n return value(this.getPropertyReader<T>(key));\n }\n\n propKeys(): string[] {\n return Array.from(this.#props.keys()) as string[];\n }\n\n propEntries(): [string, unknown][] {\n return Array.from(this.#props.entries()).map(([key, sig]) => [key, sig.value]) as [string, unknown][];\n }\n\n #truthyPropsCache: Set<string> | undefined;\n\n clearTruthyPropsCache() {\n this.#truthyPropsCache = undefined;\n }\n\n truthyProps(): Set<string> | undefined {\n if (this.#truthyPropsCache) {\n return this.#truthyPropsCache.size ? this.#truthyPropsCache : undefined;\n }\n const truthyProps = new Set<string>();\n for (const [key, sig] of this.#props.entries()) {\n if (typeof key === 'string') {\n const val = sig.value;\n if (val != null && val !== false && val !== '') {\n truthyProps.add(key);\n }\n }\n }\n this.#truthyPropsCache = truthyProps;\n return truthyProps.size ? truthyProps : undefined;\n }\n\n hasContext(name: ContextNameType): boolean {\n return this.#context.has(name);\n }\n\n useContext<T = unknown>(name: ContextNameType): SignalReader<T> {\n return this.#findOrCreateContext(name).context.get as SignalReader<T>;\n }\n\n useParentContext<T = unknown>(name: ContextNameType): SignalReader<T> {\n return this.#findOrCreateContext(name).inherited.get as SignalReader<T>;\n }\n\n provideContext<T = unknown>(name: ContextNameType): Signal<T> {\n return this.#findOrCreateContext(name).provide as Signal<T>;\n }\n\n provideGlobalContext<T = unknown>(name: ContextNameType): Signal<T> {\n // The signal behind it is created without an initial value \u2014 a context signal does start out\n // empty and holds no `T` until a provider writes one. The cast keeps the same contract\n // `provideContext()` hands out; callers see the `undefined` through `Maybe<T>` in the\n // shadow-object API.\n return this.#findOrCreateGlobalContext(name).signal as Signal<T>;\n }\n\n /**\n * Attaches a provider signal to the context of `name` on this entity and answers with the release\n * that detaches it again.\n *\n * Every provider of one name writes into the single signal that `provideContext()` hands out, so\n * what a consumer reads is what was written last. The release therefore does two things: it cuts\n * this feed, and it then lets a provider that is still attached write its value once more. Without\n * that second step the context would keep whatever the departure left standing -- the `undefined`\n * of a clearing provider, or the last value of one that opted out of it -- even though this entity\n * still has a provider of the name that says otherwise.\n *\n * A value written straight into the signal from `provideContext()` is not a feed and is therefore\n * overwritten by the next release. Feeding a value in through this method is what makes it survive\n * one.\n */\n attachContextProvider(name: ContextNameType, provider: Signal<any>): () => void {\n const ctx = this.#findOrCreateContext(name);\n return Entity.#attachProviderFeed(provider, ctx.provide, ctx.providerFeeds);\n }\n\n /**\n * The counterpart of {@link Entity.attachContextProvider} for the global context of `name`.\n *\n * Within one entity the situation is the same one: every provider feeds the single signal this\n * entity contributes to the kernel-wide chain of that name, and a release hands the name back to a\n * provider that stays. Across entities the chain decides on its own -- it resolves to the first\n * entry that holds something, so an entity whose signal falls empty lets the next one through.\n */\n attachGlobalContextProvider(name: ContextNameType, provider: Signal<any>): () => void {\n const rootCtx = this.#findOrCreateGlobalContext(name);\n return Entity.#attachProviderFeed(provider, rootCtx.signal, rootCtx.providerFeeds);\n }\n\n static #attachProviderFeed(provider: Signal<any>, target: Signal<any>, feeds: Set<SignalLink<any>>): () => void {\n const feed = link(provider, target);\n feeds.add(feed);\n\n return () => {\n // A release called a second time finds nothing of its own left and leaves the context to\n // whoever holds it by then.\n if (!feeds.delete(feed)) return;\n feed.destroy();\n Entity.#handOverToRemainingProvider(feeds);\n };\n }\n\n /**\n * Lets the provider that stays write its value into the context signal again.\n *\n * The set iterates in the order the providers were attached and the loop keeps the last hit, so the\n * winner is the one attached last that still holds a value. Attachment order is the order in which the\n * providers took the name: attaching feeds the value straight through, so a later attachment writes\n * over an earlier one, and the hand-over falls back on that order instead of inventing one of its own.\n * It is not the order of the writes -- a provider that writes to its signal after attaching carries\n * the name until the next departure, and the hand-over does not restore that write, because what this\n * entity keeps on file is its providers and not the sequence in which they wrote. Providers holding\n * nothing are passed over -- by the same `!= null` rule with which `SignalsPath` resolves a context\n * chain, and for the same reason: a provider without a value has nothing to say about the name, and\n * electing it would clear a name that is still being provided.\n *\n * A feed whose link is destroyed is passed over as well. A shadow-object owns the signal it was\n * handed and may end it early, which destroys the link without the release ever having run: such a\n * feed still reports a value through its source while its writes go nowhere, so electing it would\n * leave the write of the departure standing, silently and over a provider that is alive.\n *\n * `touch()` is what makes the winner write, because `SignalLink.write()` is protected: touching is\n * the only public way to push the current value of a source through its link again, and the source\n * of a provider that merely stays has no reason to change.\n *\n * Where no remaining feed qualifies, nothing is written: then what the departure left stands,\n * which is the `undefined` of a clearing provider or the last value of one that opted out.\n */\n static #handOverToRemainingProvider(feeds: Set<SignalLink<any>>): void {\n let winner: SignalLink<any> | undefined;\n for (const feed of feeds) {\n if (!feed.isDestroyed && feed.source.value != null) winner = feed;\n }\n winner?.touch();\n }\n\n #findOrCreateGlobalContext(name: ContextNameType): IRootContextValue {\n if (this.#rootContexts.has(name)) {\n return this.#rootContexts.get(name)!;\n }\n const rootCtx = this.#kernel.findOrCreateRootContext(name);\n const signal = createSignal() as Signal<any>;\n const cleanup = rootCtx.add(signal);\n const ctx: IRootContextValue = {cleanup, signal, providerFeeds: new Set()};\n this.#rootContexts.set(name, ctx);\n return ctx;\n }\n\n #findOrCreateContext(name: ContextNameType): IContextValue {\n if (this.#context.has(name)) {\n return this.#context.get(name)!;\n }\n\n const inherited = createSignal();\n const provide = createSignal();\n const context = createSignal();\n\n const valuePath = new SignalsPath([provide, inherited]);\n\n const unsubscribePathValue = on(valuePath, SignalsPath.Value, (val) => {\n deferContextValueUpdate(this.#kernel, context, val, name, this.#uuid);\n });\n\n const ctx: IContextValue = {name, inherited, provide, context, valuePath, providerFeeds: new Set(), unsubscribePathValue};\n this.#context.set(name, ctx);\n\n this.#subscribeToParent(ctx);\n\n return ctx;\n }\n\n #subscribeToParent(ctx: IContextValue) {\n ctx.unsubscribeFromParent?.();\n ctx.unsubscribeFromParent = undefined;\n if (this.parent) {\n const parentCtx = this.parent.#findOrCreateContext(ctx.name);\n const linkToParent = link(parentCtx.context, ctx.inherited);\n ctx.unsubscribeFromParent = linkToParent.destroy.bind(linkToParent);\n } else {\n const rootCtx = this.#kernel.findOrCreateRootContext(ctx.name);\n const linkToRoot = link(rootCtx.value$, ctx.inherited);\n ctx.unsubscribeFromParent = linkToRoot.destroy.bind(linkToRoot);\n }\n }\n}\n"],
5
+ "mappings": "AAAA,SAAQ,YAAY,KAAK,IAAI,MAAM,gBAAe;AAClD;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EAKA;AAAA,OACK;AAEP,SAAQ,0BAAyB;AACjC,SAAQ,kBAAiB;AACzB,SAAQ,WAAW,mBAAkB;AACrC,SA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