@wardic/dom 1.1.0 → 1.1.2

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 (253) hide show
  1. package/dist/DomProjectionSystem.js +3 -3
  2. package/dist/DomProjectionSystem.js.map +1 -1
  3. package/dist/FlushGate.d.ts +6 -6
  4. package/dist/FlushGate.d.ts.map +1 -1
  5. package/dist/FlushGate.js +7 -5
  6. package/dist/FlushGate.js.map +1 -1
  7. package/dist/ReorderController.js +3 -3
  8. package/dist/ReorderController.js.map +1 -1
  9. package/dist/Report.d.ts +1 -1
  10. package/dist/Report.d.ts.map +1 -1
  11. package/dist/Report.js +3 -2
  12. package/dist/Report.js.map +1 -1
  13. package/dist/Style.d.ts +2 -1
  14. package/dist/Style.d.ts.map +1 -1
  15. package/dist/Style.js +3 -1
  16. package/dist/Style.js.map +1 -1
  17. package/dist/index.d.ts +1 -1
  18. package/dist/index.js +1 -1
  19. package/dist/internal/batch-handoff.d.ts +25 -0
  20. package/dist/internal/batch-handoff.d.ts.map +1 -0
  21. package/dist/internal/batch-handoff.js +64 -0
  22. package/dist/internal/batch-handoff.js.map +1 -0
  23. package/dist/internal/gate-environment.d.ts +4 -0
  24. package/dist/internal/gate-environment.d.ts.map +1 -0
  25. package/dist/internal/gate-environment.js +21 -0
  26. package/dist/internal/gate-environment.js.map +1 -0
  27. package/dist/internal/projection.js +14 -14
  28. package/dist/internal/projection.js.map +1 -1
  29. package/dist/internal/reorder.d.ts +2 -2
  30. package/dist/internal/reorder.d.ts.map +1 -1
  31. package/dist/internal/reorder.js +2 -2
  32. package/dist/internal/reorder.js.map +1 -1
  33. package/dist/internal/starting-style.d.ts +0 -83
  34. package/dist/internal/starting-style.d.ts.map +1 -1
  35. package/dist/internal/starting-style.js +16 -143
  36. package/dist/internal/starting-style.js.map +1 -1
  37. package/dist/unstable/AppearAnimations.d.ts +191 -0
  38. package/dist/unstable/AppearAnimations.d.ts.map +1 -0
  39. package/dist/unstable/AppearAnimations.js +561 -0
  40. package/dist/unstable/AppearAnimations.js.map +1 -0
  41. package/dist/unstable/BatchMembers.d.ts +513 -0
  42. package/dist/unstable/BatchMembers.d.ts.map +1 -0
  43. package/dist/unstable/BatchMembers.js +2490 -0
  44. package/dist/unstable/BatchMembers.js.map +1 -0
  45. package/dist/unstable/DomValues.d.ts +25 -0
  46. package/dist/unstable/DomValues.d.ts.map +1 -0
  47. package/dist/unstable/DomValues.js +45 -0
  48. package/dist/unstable/DomValues.js.map +1 -0
  49. package/dist/unstable/DragConstraints.d.ts +48 -0
  50. package/dist/unstable/DragConstraints.d.ts.map +1 -0
  51. package/dist/unstable/DragConstraints.js +49 -0
  52. package/dist/unstable/DragConstraints.js.map +1 -0
  53. package/dist/unstable/DragControls.d.ts +50 -0
  54. package/dist/unstable/DragControls.d.ts.map +1 -0
  55. package/dist/unstable/DragControls.js +55 -0
  56. package/dist/unstable/DragControls.js.map +1 -0
  57. package/dist/unstable/DragDefaults.d.ts +34 -0
  58. package/dist/unstable/DragDefaults.d.ts.map +1 -0
  59. package/dist/unstable/DragDefaults.js +47 -0
  60. package/dist/unstable/DragDefaults.js.map +1 -0
  61. package/dist/unstable/DragTrack.d.ts +236 -0
  62. package/dist/unstable/DragTrack.d.ts.map +1 -0
  63. package/dist/unstable/DragTrack.js +646 -0
  64. package/dist/unstable/DragTrack.js.map +1 -0
  65. package/dist/unstable/DragTransition.d.ts +22 -0
  66. package/dist/unstable/DragTransition.d.ts.map +1 -0
  67. package/dist/unstable/DragTransition.js +31 -0
  68. package/dist/unstable/DragTransition.js.map +1 -0
  69. package/dist/unstable/ElementSetup.d.ts +144 -0
  70. package/dist/unstable/ElementSetup.d.ts.map +1 -0
  71. package/dist/unstable/ElementSetup.js +297 -0
  72. package/dist/unstable/ElementSetup.js.map +1 -0
  73. package/dist/unstable/Feature.d.ts +221 -0
  74. package/dist/unstable/Feature.d.ts.map +1 -0
  75. package/dist/unstable/Feature.js +281 -0
  76. package/dist/unstable/Feature.js.map +1 -0
  77. package/dist/unstable/GestureFeatures.d.ts +30 -0
  78. package/dist/unstable/GestureFeatures.d.ts.map +1 -0
  79. package/dist/unstable/GestureFeatures.js +32 -0
  80. package/dist/unstable/GestureFeatures.js.map +1 -0
  81. package/dist/unstable/GestureInfo.d.ts +61 -0
  82. package/dist/unstable/GestureInfo.d.ts.map +1 -0
  83. package/dist/unstable/GestureInfo.js +23 -0
  84. package/dist/unstable/GestureInfo.js.map +1 -0
  85. package/dist/unstable/Imperative.d.ts +214 -0
  86. package/dist/unstable/Imperative.d.ts.map +1 -0
  87. package/dist/unstable/Imperative.js +768 -0
  88. package/dist/unstable/Imperative.js.map +1 -0
  89. package/dist/unstable/Instant.d.ts +46 -0
  90. package/dist/unstable/Instant.d.ts.map +1 -0
  91. package/dist/unstable/Instant.js +49 -0
  92. package/dist/unstable/Instant.js.map +1 -0
  93. package/dist/unstable/LayoutGroup.d.ts +14 -0
  94. package/dist/unstable/LayoutGroup.d.ts.map +1 -0
  95. package/dist/unstable/LayoutGroup.js +31 -0
  96. package/dist/unstable/LayoutGroup.js.map +1 -0
  97. package/dist/unstable/LayoutMember.d.ts +127 -0
  98. package/dist/unstable/LayoutMember.d.ts.map +1 -0
  99. package/dist/unstable/LayoutMember.js +176 -0
  100. package/dist/unstable/LayoutMember.js.map +1 -0
  101. package/dist/unstable/LiveStyle.d.ts +171 -0
  102. package/dist/unstable/LiveStyle.d.ts.map +1 -0
  103. package/dist/unstable/LiveStyle.js +329 -0
  104. package/dist/unstable/LiveStyle.js.map +1 -0
  105. package/dist/unstable/MemberHold.d.ts +3 -0
  106. package/dist/unstable/MemberHold.d.ts.map +1 -0
  107. package/dist/unstable/MemberHold.js +223 -0
  108. package/dist/unstable/MemberHold.js.map +1 -0
  109. package/dist/unstable/OwnerScope.d.ts +16 -0
  110. package/dist/unstable/OwnerScope.d.ts.map +1 -0
  111. package/dist/unstable/OwnerScope.js +35 -0
  112. package/dist/unstable/OwnerScope.js.map +1 -0
  113. package/dist/unstable/PresenceController.d.ts +128 -0
  114. package/dist/unstable/PresenceController.d.ts.map +1 -0
  115. package/dist/unstable/PresenceController.js +1427 -0
  116. package/dist/unstable/PresenceController.js.map +1 -0
  117. package/dist/unstable/Press.d.ts +26 -0
  118. package/dist/unstable/Press.d.ts.map +1 -0
  119. package/dist/unstable/Press.js +19 -0
  120. package/dist/unstable/Press.js.map +1 -0
  121. package/dist/unstable/ServerInterpolators.d.ts +17 -0
  122. package/dist/unstable/ServerInterpolators.d.ts.map +1 -0
  123. package/dist/unstable/ServerInterpolators.js +20 -0
  124. package/dist/unstable/ServerInterpolators.js.map +1 -0
  125. package/dist/unstable/WardConfig.d.ts +567 -0
  126. package/dist/unstable/WardConfig.d.ts.map +1 -0
  127. package/dist/unstable/WardConfig.js +2 -0
  128. package/dist/unstable/WardConfig.js.map +1 -0
  129. package/dist/unstable/features/All.d.ts +24 -0
  130. package/dist/unstable/features/All.d.ts.map +1 -0
  131. package/dist/unstable/features/All.js +20 -0
  132. package/dist/unstable/features/All.js.map +1 -0
  133. package/dist/unstable/features/Colors.d.ts +12 -0
  134. package/dist/unstable/features/Colors.d.ts.map +1 -0
  135. package/dist/unstable/features/Colors.js +38 -0
  136. package/dist/unstable/features/Colors.js.map +1 -0
  137. package/dist/unstable/features/DomAnimation.d.ts +16 -0
  138. package/dist/unstable/features/DomAnimation.d.ts.map +1 -0
  139. package/dist/unstable/features/DomAnimation.js +19 -0
  140. package/dist/unstable/features/DomAnimation.js.map +1 -0
  141. package/dist/unstable/features/DomMax.d.ts +12 -0
  142. package/dist/unstable/features/DomMax.d.ts.map +1 -0
  143. package/dist/unstable/features/DomMax.js +14 -0
  144. package/dist/unstable/features/DomMax.js.map +1 -0
  145. package/dist/unstable/features/Drag.d.ts +5 -0
  146. package/dist/unstable/features/Drag.d.ts.map +1 -0
  147. package/dist/unstable/features/Drag.js +32 -0
  148. package/dist/unstable/features/Drag.js.map +1 -0
  149. package/dist/unstable/features/Focus.d.ts +5 -0
  150. package/dist/unstable/features/Focus.d.ts.map +1 -0
  151. package/dist/unstable/features/Focus.js +20 -0
  152. package/dist/unstable/features/Focus.js.map +1 -0
  153. package/dist/unstable/features/Hover.d.ts +5 -0
  154. package/dist/unstable/features/Hover.d.ts.map +1 -0
  155. package/dist/unstable/features/Hover.js +20 -0
  156. package/dist/unstable/features/Hover.js.map +1 -0
  157. package/dist/unstable/features/InView.d.ts +5 -0
  158. package/dist/unstable/features/InView.d.ts.map +1 -0
  159. package/dist/unstable/features/InView.js +20 -0
  160. package/dist/unstable/features/InView.js.map +1 -0
  161. package/dist/unstable/features/Input.d.ts +28 -0
  162. package/dist/unstable/features/Input.d.ts.map +1 -0
  163. package/dist/unstable/features/Input.js +31 -0
  164. package/dist/unstable/features/Input.js.map +1 -0
  165. package/dist/unstable/features/Keys.d.ts +95 -0
  166. package/dist/unstable/features/Keys.d.ts.map +1 -0
  167. package/dist/unstable/features/Keys.js +44 -0
  168. package/dist/unstable/features/Keys.js.map +1 -0
  169. package/dist/unstable/features/Layout.d.ts +43 -0
  170. package/dist/unstable/features/Layout.d.ts.map +1 -0
  171. package/dist/unstable/features/Layout.js +44 -0
  172. package/dist/unstable/features/Layout.js.map +1 -0
  173. package/dist/unstable/features/Pan.d.ts +5 -0
  174. package/dist/unstable/features/Pan.d.ts.map +1 -0
  175. package/dist/unstable/features/Pan.js +20 -0
  176. package/dist/unstable/features/Pan.js.map +1 -0
  177. package/dist/unstable/features/Press.d.ts +13 -0
  178. package/dist/unstable/features/Press.d.ts.map +1 -0
  179. package/dist/unstable/features/Press.js +10 -0
  180. package/dist/unstable/features/Press.js.map +1 -0
  181. package/dist/unstable/features/Scroll.d.ts +20 -0
  182. package/dist/unstable/features/Scroll.d.ts.map +1 -0
  183. package/dist/unstable/features/Scroll.js +34 -0
  184. package/dist/unstable/features/Scroll.js.map +1 -0
  185. package/dist/unstable/features/TimelineKeys.d.ts +7 -0
  186. package/dist/unstable/features/TimelineKeys.d.ts.map +1 -0
  187. package/dist/unstable/features/TimelineKeys.js +103 -0
  188. package/dist/unstable/features/TimelineKeys.js.map +1 -0
  189. package/package.json +4 -3
  190. package/src/DomProjectionSystem.ts +3 -3
  191. package/src/FlushGate.ts +11 -9
  192. package/src/ReorderController.ts +3 -3
  193. package/src/Report.ts +3 -7
  194. package/src/Style.ts +4 -1
  195. package/src/index.ts +1 -1
  196. package/src/internal/batch-handoff.ts +75 -0
  197. package/src/internal/gate-environment.ts +21 -0
  198. package/src/internal/projection.ts +14 -14
  199. package/src/internal/reorder.ts +4 -4
  200. package/src/internal/starting-style.ts +5 -204
  201. package/src/unstable/AppearAnimations.ts +837 -0
  202. package/src/unstable/BatchMembers.ts +3085 -0
  203. package/src/unstable/DomValues.ts +53 -0
  204. package/src/unstable/DragConstraints.ts +107 -0
  205. package/src/unstable/DragControls.ts +98 -0
  206. package/src/unstable/DragDefaults.ts +57 -0
  207. package/src/unstable/DragTrack.ts +959 -0
  208. package/src/unstable/DragTransition.ts +46 -0
  209. package/src/unstable/ElementSetup.ts +411 -0
  210. package/src/unstable/Feature.ts +494 -0
  211. package/src/unstable/GestureFeatures.ts +38 -0
  212. package/src/unstable/GestureInfo.ts +85 -0
  213. package/src/unstable/Imperative.ts +1037 -0
  214. package/src/unstable/Instant.ts +93 -0
  215. package/src/unstable/LayoutGroup.ts +36 -0
  216. package/src/unstable/LayoutMember.ts +319 -0
  217. package/src/unstable/LiveStyle.ts +497 -0
  218. package/src/unstable/MemberHold.ts +211 -0
  219. package/src/unstable/OwnerScope.ts +35 -0
  220. package/src/unstable/PresenceController.ts +1747 -0
  221. package/src/unstable/Press.ts +43 -0
  222. package/src/unstable/ServerInterpolators.ts +39 -0
  223. package/src/unstable/WardConfig.ts +704 -0
  224. package/src/unstable/features/All.ts +39 -0
  225. package/src/unstable/features/Colors.ts +40 -0
  226. package/src/unstable/features/DomAnimation.ts +19 -0
  227. package/src/unstable/features/DomMax.ts +14 -0
  228. package/src/unstable/features/Drag.ts +34 -0
  229. package/src/unstable/features/Focus.ts +21 -0
  230. package/src/unstable/features/Hover.ts +21 -0
  231. package/src/unstable/features/InView.ts +21 -0
  232. package/src/unstable/features/Input.ts +37 -0
  233. package/src/unstable/features/Keys.ts +124 -0
  234. package/src/unstable/features/Layout.ts +75 -0
  235. package/src/unstable/features/Pan.ts +21 -0
  236. package/src/unstable/features/Press.ts +21 -0
  237. package/src/unstable/features/Scroll.ts +35 -0
  238. package/src/unstable/features/TimelineKeys.ts +115 -0
  239. package/dist/internal/gate.d.ts +0 -199
  240. package/dist/internal/gate.d.ts.map +0 -1
  241. package/dist/internal/gate.js +0 -570
  242. package/dist/internal/gate.js.map +0 -1
  243. package/dist/internal/report.d.ts +0 -30
  244. package/dist/internal/report.d.ts.map +0 -1
  245. package/dist/internal/report.js +0 -60
  246. package/dist/internal/report.js.map +0 -1
  247. package/dist/internal/runner.d.ts +0 -22
  248. package/dist/internal/runner.d.ts.map +0 -1
  249. package/dist/internal/runner.js +0 -62
  250. package/dist/internal/runner.js.map +0 -1
  251. package/src/internal/gate.ts +0 -706
  252. package/src/internal/report.ts +0 -69
  253. package/src/internal/runner.ts +0 -78
@@ -1,706 +0,0 @@
1
- /**
2
- * `makeFlushGate` — the deferred **Flush gate** (ADR-0006), framework-free here in `@wardic/dom`
3
- * so every binding shares one (ADR-0031, decision 3). The binding hands in its `batch` and its
4
- * sinks; the gate imports nothing from a framework.
5
- *
6
- * Per ADR-0006, per-frame writes never reach their element directly. Each source
7
- * `write(id, partialValues)`s into a provider-owned gate that:
8
- *
9
- * 1. Accumulates *value-maps* (NOT already-projected Patches) per element,
10
- * merging partials by key — so multiple sources can feed one element
11
- * (e.g. a drag setting `x`/`y` while a spring drives `scale`, all
12
- * collapsing into one grouped `transform`). Projecting per source would
13
- * clobber the grouped transform.
14
- * 2. Resolves the Renderer's PURE `project` ONCE at creation and uses it to
15
- * turn each dirty element's merged value-map into a `Patch` exactly once
16
- * per element per frame.
17
- * 3. Commits each resulting Patch onto its element with the Renderer's `commit`, a plain
18
- * call (ADR-0034) — one DOM pass per frame, shared by every element: at the end of the
19
- * Frame loop's tick, in the Refresh frame that computed the values (ADR-0033). No
20
- * framework runs per frame: a binding's JSX carries an element's style only until its
21
- * first commit (ADR-0021, decision 6), and after it only the keys the gate doesn't hold.
22
- *
23
- * Three locked design decisions (this session's grills):
24
- * - FLUSHED at the end of the Frame loop's tick (ADR-0033): the gate registers a hook on
25
- * the Environment's loop (`afterTick`), so everything a tick writes is applied at the end
26
- * of that tick, inside the Clock's callback, and paints in that Refresh frame. A write
27
- * made outside a tick (a drag's move, a `release` from a task, an effect a sink's hook ran,
28
- * a Tier 2 `Stream` on `Clock.ticks` subscribed after the loop) still requests a
29
- * Refresh frame, only if one is not already pending, and the hook withdraws that request
30
- * when it flushes first. `flush` does NOT auto-reschedule, so an idle accumulator
31
- * requests no frames — the next `write` does. The frames come from the Environment's
32
- * `RefreshFrameSource` (ADR-0031): on the web, `requestAnimationFrame` itself. No binding
33
- * calls the browser's frame functions itself. A Tier 2 `Stream` that writes here paints in
34
- * the loop's frame or the next one, by its subscription order (ADR-0033): run it on the
35
- * loop (`Machine.run`) to paint with it.
36
- * - ONE flush per frame: all dirty elements flush together. The one exception
37
- * is `flushPass` (ADR-0018): a projection Measure pass's own writes are applied
38
- * at the end of its task, so a new layout never paints without its projection.
39
- * - ONE sink shape (ADR-0034): a sink is the element its patch is committed onto. The gate
40
- * also removes a key its last patch had and this one doesn't (a dragged node's `z-index`
41
- * once its raise is dropped, ADR-0016 *Amendment (Reorder)*), restoring the element's own
42
- * inline value, saved before the gate first wrote the key. Two hooks reach the binding,
43
- * outside the commits, each in the binding's `batch` (ADR-0034, *Amendment (#209)*): the
44
- * Starting-style switch before an element's first commit (`beforeFirstCommit`), and the keys
45
- * the gate holds on the element whenever they change (`onHeld`), so the binding's `style`
46
- * leaves them to Wardic.
47
- *
48
- * Observability (CONTEXT.md convention): the hot path (`write`/`flush`) is the
49
- * per-frame work, so — exactly like core's per-frame writes and the Clock's
50
- * `tick` — it stays quiet (no span, no per-call log, no metric). A flush that throws (a
51
- * binding's hook, a commit) is reported (`reportFailure`) and the gate
52
- * goes on, so it can't fail the Frame loop's tick it runs in (ADR-0033).
53
- */
54
- import * as FrameLoop from "@wardic/core/FrameLoop"
55
- import * as RefreshFrameSource from "@wardic/core/RefreshFrameSource"
56
- import * as Renderer from "@wardic/core/Renderer"
57
- import * as Cause from "effect/Cause"
58
- import * as Atom from "effect/reactivity/Atom"
59
- import * as AtomRegistry from "effect/reactivity/AtomRegistry"
60
- import * as Effect from "effect/Effect"
61
- import * as Exit from "effect/Exit"
62
- import type * as Fiber from "effect/Fiber"
63
- import * as Predicate from "effect/Predicate"
64
- import * as UndefinedOr from "effect/UndefinedOr"
65
- import * as Scope from "effect/Scope"
66
- import { reportFailure } from "./report.ts"
67
- import { TEMPLATE_KEY } from "./renderer.ts"
68
- import type { TimelineValue } from "./timeline.ts"
69
- import { dashCase } from "./svg.ts"
70
-
71
- /**
72
- * Where a flushed `Patch` is delivered: committed onto `target` with the Renderer's `commit`,
73
- * at flush time.
74
- */
75
- export interface FlushSink {
76
- /** The element the patch is committed onto. */
77
- readonly target: unknown
78
- /**
79
- * Called once, just before the element's first commit in a frame flush (not a Measure
80
- * pass's `flushPass`), inside the binding's `batch` with every other element's switch that
81
- * flush: a binding drops its Starting style from its `style` prop here,
82
- * so its framework removes those keys and the commit writes the first frame in the same
83
- * Refresh frame, with no paint in between.
84
- */
85
- readonly beforeFirstCommit?: (() => void) | undefined
86
- /**
87
- * Called with every key the gate now holds on the element, each time that set changes: after the
88
- * gate restores a key it dropped, and before the commit that first
89
- * writes a key. A binding whose `style` prop reaches the element leaves these keys out of it,
90
- * so its framework never writes over Wardic's value (`style` is a key's fallback). Called in
91
- * the binding's `batch`, with every other element's whose keys changed that flush, so what the
92
- * binding changes reaches the element before the commit, a framework that applies an update later
93
- * (Solid 2) included.
94
- */
95
- // ADR-0034, *Amendment (#209)*.
96
- readonly onHeld?: ((keys: ReadonlyArray<string>) => void) | undefined
97
- /**
98
- * Called once per frame in which the element's values were committed, after every commit of that
99
- * frame (Motion's `onUpdate`), with its values before
100
- * projection (`x` as a number). The object is the element's own, reused each call: valid during
101
- * the call, copied to keep. A Measure pass's commits are told at the frame flush after them, so
102
- * a frame tells each element once. A write it makes is the next frame's. A throw is reported,
103
- * and the others are still told.
104
- */
105
- readonly onCommit?: ((values: Readonly<Record<string, unknown>>) => void) | undefined
106
- }
107
-
108
- /** Accumulated pre-`project` state for one registered element. */
109
- interface Entry {
110
- /** Merged value-map (partials `Object.assign`ed in by key). */
111
- readonly values: Record<string, unknown>
112
- /** Where this element's projected Patch goes. */
113
- readonly sink: FlushSink
114
- /** Whether a `write` has landed since the last flush. */
115
- dirty: boolean
116
- /**
117
- * The keys the gate holds on the element: its last patch's, each with the element's own
118
- * inline value from before the gate first wrote it (`""` for none), to restore when the
119
- * key drops out.
120
- */
121
- readonly committed: Map<string, string>
122
- /** Its keys' live outputs (`valueOf`), or `undefined` while nothing asked for one. */
123
- outputs: Map<string, Output> | undefined
124
- /** The values its sink's `onCommit` is told, one object reused, made on the first call. */
125
- latest: Record<string, unknown> | undefined
126
- /**
127
- * Whether its `onCommit` threw at its last call (#257 item 4): a run of throws is logged and
128
- * reported at its first, so one that throws every frame logs once; a call that returns ends it.
129
- */
130
- failing: boolean
131
- /** Its patch, projected this flush and committed once the binding has heard the keys held. */
132
- patch: Renderer.Patch | undefined
133
- }
134
-
135
- /** One key's live output: its Atom, the value last set on it, and its mount in the registry. */
136
- interface Output {
137
- readonly atom: Atom.Writable<unknown>
138
- last: unknown
139
- readonly unmount: () => void
140
- }
141
-
142
- /** The element's own inline value for a patch key (`""` for none, or a target with no style). */
143
- const inlineValueOf = (target: unknown, key: string): string => {
144
- if (Predicate.isNullish(target)) return ""
145
- const style = (target as { readonly style?: CSSStyleDeclaration }).style
146
- if (Predicate.isUndefined(style)) return ""
147
- return style.getPropertyValue(dashCase(key))
148
- }
149
-
150
- /** Each of `values` cancelled (#240). Per flush: a plain loop. */
151
- const cancelEach = (values: Iterable<TimelineValue>): void => {
152
- for (const value of values) value.cancel()
153
- }
154
-
155
- /** A Flush gate: what a binding registers its elements with and writes their values into, one per provider. */
156
- export interface FlushGate {
157
- /**
158
- * Register an element under `id` with its `sink`. Returns an unregister fn
159
- * that removes the element from the accumulator (a subsequent `write` is a
160
- * no-op). `values` start its value-map, unflushed: drawn with its first `write`, so they never
161
- * commit alone.
162
- */
163
- // #443: its Transform template, which mustn't take its Starting style off early.
164
- readonly register: (id: string, sink: FlushSink, values?: Readonly<Record<string, unknown>>) => () => void
165
- /**
166
- * Merge `partial` into the element's value-map by key, mark it dirty, and
167
- * schedule a flush: the end of the Frame loop's tick, for a write made in one, or else the
168
- * next Refresh frame. A `write` for an unregistered (or unregistered-since) id
169
- * is a no-op.
170
- */
171
- readonly write: (id: string, partial: Record<string, unknown>) => void
172
- /**
173
- * Run a projection **Measure pass** now and apply exactly what it wrote before
174
- * returning. Only `write()`s made while
175
- * `pass()` runs are recorded; each recorded entry is `project`ed and committed once, and
176
- * marked clean. Everything else stays dirty for its flush. A write made by an effect a sink's
177
- * hook runs (a Solid effect) takes the ordinary path. The Projection system calls it at the
178
- * end of a task, so a new layout never paints without its projection.
179
- */
180
- readonly flushPass: (pass: () => void) => void
181
- /**
182
- * Hand `keys` back to the element's own style: drop each from the element's
183
- * value-map and schedule a flush, which writes `restore[key]` (CSS text) for a key it had
184
- * written, or else the inline value it overwrote, and tells the sink (`onHeld`). A key the
185
- * entry doesn't hold, or an unknown id, is a no-op. A binding releases a key back at its `style`
186
- * value, so a later `style` change shows at rest. A later `write` brings the key back. A property in
187
- * `keep` (`transform` for its keys) is left as it's drawn when it drops out: another writer draws it next.
188
- */
189
- // `keep`: #665's PR 4, a Batch member's group handed back to its Batch, whose writer draws it from then on.
190
- readonly release: (id: string, keys: ReadonlyArray<string>, restore?: Readonly<Record<string, string>>, keep?: ReadonlyArray<string>) => void
191
- /**
192
- * The element's value for `id`'s `key`, live: an `Atom` set as each write that
193
- * changes it lands, so it's the value the next commit draws, before the Renderer projects it
194
- * (`x` as a number, not a `transform`). Set at the write, not the commit, so a value derived
195
- * from it (another key following it through a binding) is written in the same frame and
196
- * commits with it. `undefined` before the key's first write, and once it's released or the
197
- * element unregisters. One Atom for an id and a key, made on first ask, so per frame only the
198
- * keys asked for cost anything.
199
- */
200
- readonly valueOf: (id: string, key: string) => Atom.Atom<unknown>
201
- /**
202
- * Run `key`'s Timeline value on `id`'s element (#240), or stop it (`undefined`): a binding sets one
203
- * while the key shows its Live value, and clears it when an entry of the Override stack takes the
204
- * key. The gate goes on writing the key: at each flush that commits the element, before the commit,
205
- * it starts the value's animation over it, or cancels it while something else adds to its property
206
- * (a projection, a Transform template, another transform key off its identity), so a frame shows one
207
- * or the other. A cleared or replaced one is cancelled at the next flush; a released key's, an
208
- * unregistered element's and a disposed gate's, at once. Setting one schedules a flush.
209
- */
210
- readonly timeline: (id: string, key: string, timeline: TimelineValue | undefined) => void
211
- /**
212
- * Call `fn` once, after the gate's next flush: the end of the Frame loop's tick, for a call
213
- * made in one, else the next Refresh frame's, so what was written before it is on the elements.
214
- * It schedules that flush if none is pending. A binding tells an animation's end here, as Motion's
215
- * `onAnimationComplete` comes with the final value set. One that throws is reported, and the rest
216
- * still run.
217
- */
218
- readonly afterFlush: (fn: () => void) => void
219
- /** Takes the gate off the Frame loop, cancels a pending frame and clears what it held. The Layer's Scope calls it. */
220
- // Wired into the provider's `onCleanup`.
221
- readonly dispose: () => void
222
- }
223
-
224
- /** What a flush gate needs from its Environment: the `Renderer`, the Frame loop it flushes at the end of each tick of, and the `RefreshFrameSource`. */
225
- // ADR-0033; ADR-0031.
226
- export type FlushGateServices = Renderer.Renderer | RefreshFrameSource.RefreshFrameSource | FrameLoop.FrameLoop | AtomRegistry.AtomRegistry
227
-
228
- /**
229
- * How the gate runs its Effects: synchronously, and forked. `FlushGate.make` builds one from its
230
- * Layer's context, forking into its Scope (#132, ADR-0041); a test's `ManagedRuntime` is one too.
231
- */
232
- export interface FlushGateRuntime {
233
- readonly runSync: <A, E>(effect: Effect.Effect<A, E, FlushGateServices>) => A
234
- readonly runFork: <A, E>(effect: Effect.Effect<A, E, FlushGateServices>) => Fiber.Fiber<A, E>
235
- /** The Scope it was built in: its own fibers live there, ended as it closes (#618). */
236
- readonly scope: Scope.Scope
237
- }
238
-
239
- /** What a binding hands its flush gate. */
240
- export interface FlushGateOptions {
241
- /**
242
- * Runs a flush's hooks together: calls `apply`, and returns once every update inside it has reached
243
- * the elements, before the gate commits. Solid 1 passes its `batch`, Solid 2 runs `apply` then
244
- * `flush()`, and React would pass `flushSync`, untried; a binding with nothing to batch passes
245
- * `(apply) => apply()`. Called at most twice a flush: once for the starting-style switches
246
- * (`beforeFirstCommit`) of the elements committing for the first time, before anything is read off the
247
- * elements; and once for the held keys (`onHeld`) of the elements whose held keys changed.
248
- */
249
- // ADR-0031, decision 3, ADR-0034; *Amendment (#209)*.
250
- readonly batch: (apply: () => void) => void
251
- }
252
-
253
- /**
254
- * Build a flush gate against the provider's `runtime`, running each frame flush's Starting-style
255
- * switches through the binding's `batch`.
256
- *
257
- * Resolves both ONCE here: `project` is pure and `commit` a plain call (both called directly at
258
- * flush, ADR-0034), `requestFrame` /
259
- * `cancelFrame` schedule and cancel the flush of a write made outside a tick, and the Frame
260
- * loop's `afterTick` takes the gate's hook for its lifetime. All come from whichever env the
261
- * provider was given (`DomLive` / `TestLive`), so the gate inherits that environment's
262
- * grouping/unit logic, its Refresh frames and its loop with zero duplication.
263
- */
264
- export const makeFlushGate = (runtime: FlushGateRuntime, options: FlushGateOptions): FlushGate => {
265
- const { batch } = options
266
- // Resolve the Renderer's two halves and the Refresh frame source exactly once at creation.
267
- // `requestFrame` and `cancelFrame` are called detached, never as `frames.requestFrame(cb)`: a
268
- // browser throws "Illegal invocation" when `requestAnimationFrame` runs with `this` bound to
269
- // anything but the window (ADR-0031, decision 7).
270
- const { commit, project, requestFrame, cancelFrame, afterTick } = runtime.runSync(
271
- Effect.gen(function* () {
272
- const { commit, project } = yield* Renderer.Renderer
273
- const { requestFrame, cancelFrame } = yield* RefreshFrameSource.RefreshFrameSource
274
- const { afterTick } = yield* FrameLoop.FrameLoop
275
- return { commit, project, requestFrame, cancelFrame, afterTick }
276
- }),
277
- )
278
-
279
- const accumulator = new Map<string, Entry>()
280
- // Every live output asked for (`valueOf`), by id: an entry registered later picks its map up.
281
- const outputsById = new Map<string, Map<string, Output>>()
282
- const registry = runtime.runSync(AtomRegistry.AtomRegistry)
283
- // Sinks waiting for their first commit's `beforeFirstCommit` (usually empty).
284
- const firstCommits = new Set<string>()
285
- let scheduled = false
286
- // What `afterFlush` queued since the last flush, called at its end (#257).
287
- let afterFlushes: Array<() => void> = []
288
- // The pending Refresh frame's handle, while `scheduled`.
289
- let frame: unknown
290
- // The ids written while a `flushPass` pass runs; `undefined` otherwise.
291
- let recording: Set<string> | undefined
292
- // The entries committed since the last frame flush whose sink has an `onCommit` (#233).
293
- const committedSince = new Set<Entry>()
294
- // Each element's Timeline values by key (#240), and those let go of since its last flush, cancelled at
295
- // its next: only the elements that have one, so the per-frame path checks their sizes alone.
296
- const timelines = new Map<Entry, Map<string, TimelineValue>>()
297
- const endings = new Map<Entry, Array<TimelineValue>>()
298
- // A frame flush's entries, in order, prepared and waiting for their commit; and those whose
299
- // keys held changed, which the binding hears first. Reused each flush: the per-frame path.
300
- const prepared: Array<Entry> = []
301
- const heldChanged: Array<Entry> = []
302
-
303
- /**
304
- * Project one dirty entry's patch and restore the keys it dropped (once per element per flush),
305
- * marking it clean: into `into`, and into `held` when the keys it holds change and its sink
306
- * hears them. Its commit waits for the binding's `batch` of those (ADR-0034, *Amendment
307
- * (#209)*). Plain calls only: this is the per-frame path.
308
- */
309
- const prepare = (entry: Entry, into: Array<Entry>, held: Array<Entry>): void => {
310
- const patch = project(entry.values)
311
- entry.dirty = false
312
- entry.patch = patch
313
- into.push(entry)
314
- const sink = entry.sink
315
- const target = sink.target
316
- const committed = entry.committed
317
- const before = committed.size
318
- let kept = 0
319
- let added = false
320
- for (const key in patch) {
321
- if (committed.has(key)) {
322
- kept++
323
- continue
324
- }
325
- committed.set(key, inlineValueOf(target, key))
326
- added = true
327
- }
328
- // A key the last patch wrote and this one doesn't: the element gets its own value
329
- // back. Only looked for when one dropped out (the usual frame keeps every key).
330
- let restore: Renderer.Patch | undefined
331
- if (kept < before) {
332
- for (const [key, own] of committed) {
333
- if (key in patch) continue
334
- if (Predicate.isUndefined(restore)) restore = {}
335
- restore[key] = own
336
- committed.delete(key)
337
- }
338
- }
339
- if (Predicate.isNotUndefined(restore)) commit(target, restore)
340
- // The keys held changed (the usual frame changes none): the binding hears before the commit.
341
- if ((added || Predicate.isNotUndefined(restore)) && Predicate.isNotUndefined(sink.onHeld)) held.push(entry)
342
- }
343
-
344
- /**
345
- * Before a flush's commits (#240): cancel the Timeline values each element committing now let go of,
346
- * and sync the rest with its values, so each starts or stops as nothing else adds to its property.
347
- * An entry is committing while it holds a prepared patch. Kept beside the entries, not on them, so an
348
- * element with none pays nothing per frame: the flush checks two sizes. Per flush: plain loops.
349
- */
350
- const syncTimelines = (): void => {
351
- for (const [entry, ended] of endings) {
352
- if (Predicate.isUndefined(entry.patch)) continue
353
- endings.delete(entry)
354
- cancelEach(ended)
355
- }
356
- for (const [entry, byKey] of timelines) {
357
- if (Predicate.isUndefined(entry.patch)) continue
358
- for (const value of byKey.values()) value.sync(entry.values)
359
- }
360
- }
361
-
362
- /** Every Timeline value of `entry`, cancelled at once: its element is gone, or the gate is. */
363
- const cancelTimelines = (entry: Entry): void => {
364
- const ended = endings.get(entry)
365
- endings.delete(entry)
366
- if (Predicate.isNotUndefined(ended)) cancelEach(ended)
367
- const byKey = timelines.get(entry)
368
- timelines.delete(entry)
369
- if (Predicate.isNotUndefined(byKey)) cancelEach(byKey.values())
370
- }
371
-
372
- /** Commit a prepared entry's patch onto its element. */
373
- const commitPrepared = (entry: Entry): void => {
374
- const patch = entry.patch
375
- if (Predicate.isUndefined(patch)) return
376
- entry.patch = undefined
377
- commit(entry.sink.target, patch)
378
- if (Predicate.isNotUndefined(entry.sink.onCommit)) committedSince.add(entry)
379
- }
380
-
381
- /**
382
- * The prepared entries, committed, after the binding has heard the keys held change, together, in
383
- * its `batch` (#209); both lists emptied for the next flush.
384
- */
385
- const commitAll = (entries: Array<Entry>, held: Array<Entry>): void => {
386
- if (held.length > 0) batch(() => tellHeld(held))
387
- for (let i = 0; i < entries.length; i++) commitPrepared(entries[i])
388
- entries.length = 0
389
- held.length = 0
390
- }
391
-
392
- /** Each entry's `onHeld`, with every key the gate holds on its element now. */
393
- const tellHeld = (held: ReadonlyArray<Entry>): void => {
394
- for (let i = 0; i < held.length; i++) {
395
- const entry = held[i]
396
- const onHeld = entry.sink.onHeld
397
- if (Predicate.isNotUndefined(onHeld)) onHeld(Array.from(entry.committed.keys()))
398
- }
399
- }
400
-
401
- /**
402
- * Tell each entry committed since the last frame flush, once, after every commit of this one
403
- * (#233). Its values are copied into its own reused object, so its sink never holds the gate's.
404
- */
405
- const tellCommitted = (): void => {
406
- for (const entry of committedSince) {
407
- const onCommit = entry.sink.onCommit
408
- if (Predicate.isUndefined(onCommit)) continue
409
- let latest = entry.latest
410
- if (Predicate.isUndefined(latest)) {
411
- latest = {}
412
- entry.latest = latest
413
- }
414
- for (const key in latest) if (!Object.hasOwn(entry.values, key)) delete latest[key]
415
- Object.assign(latest, entry.values)
416
- // Its Transform template rides in its values (#443), and isn't one: Motion's `onUpdate` never sees it.
417
- delete latest[TEMPLATE_KEY]
418
- try {
419
- onCommit(latest)
420
- entry.failing = false
421
- } catch (defect) {
422
- if (entry.failing) continue
423
- entry.failing = true
424
- runtime.runFork(reportFailure("wardic.gate: an onCommit failed", Cause.die(defect)))
425
- }
426
- }
427
- committedSince.clear()
428
- }
429
-
430
- /**
431
- * The live outputs asked for of `entry`, each set where its value changed, as a write or a
432
- * release lands: a value derived from one (a Live value of another key, through a binding) is
433
- * written in the same frame, and commits with it. An unchanged one skips the registry. Plain
434
- * calls: a write is the per-frame path.
435
- */
436
- const setOutputs = (entry: Entry): void => {
437
- const outputs = entry.outputs
438
- if (Predicate.isUndefined(outputs)) return
439
- for (const [key, output] of outputs) {
440
- const value = entry.values[key]
441
- if (value === output.last) continue
442
- output.last = value
443
- registry.set(output.atom, value)
444
- }
445
- }
446
-
447
- /**
448
- * Run `beforeFirstCommit` for each waiting entry about to commit (dirty), in the binding's
449
- * `batch` before any commit, so the binding applies what it changes first. A wrap that never
450
- * commits stays waiting, so this loops over the wraps still waiting, once per frame flush.
451
- */
452
- const runFirstCommits = (): void => {
453
- for (const id of firstCommits) {
454
- const entry = accumulator.get(id)
455
- if (Predicate.isUndefined(entry) || !entry.dirty) continue
456
- firstCommits.delete(id)
457
- const hook = entry.sink.beforeFirstCommit
458
- if (Predicate.isNotUndefined(hook)) hook()
459
- }
460
- }
461
-
462
- const flush = (): void => {
463
- scheduled = false
464
- try {
465
- // The switches first: an element's own inline values are read once its Starting style is gone.
466
- if (firstCommits.size > 0) batch(runFirstCommits)
467
- // Every dirty element, once. No auto-reschedule — the next write() does. A write()
468
- // from an effect a sink's hook runs requests the next frame (it isn't stranded).
469
- for (const entry of accumulator.values()) if (entry.dirty) prepare(entry, prepared, heldChanged)
470
- if (timelines.size > 0 || endings.size > 0) syncTimelines()
471
- commitAll(prepared, heldChanged)
472
- if (committedSince.size > 0) tellCommitted()
473
- } catch (defect) {
474
- prepared.length = 0
475
- heldChanged.length = 0
476
- runtime.runFork(reportFailure("wardic.gate: a flush failed", Cause.die(defect)))
477
- }
478
- if (afterFlushes.length > 0) runAfterFlushes()
479
- }
480
-
481
- /** The calls `afterFlush` queued, each once, a new queue for any they make. */
482
- const runAfterFlushes = (): void => {
483
- const due = afterFlushes
484
- afterFlushes = []
485
- for (const fn of due) {
486
- try {
487
- fn()
488
- } catch (defect) {
489
- runtime.runFork(reportFailure("wardic.gate: an afterFlush call failed", Cause.die(defect)))
490
- }
491
- }
492
- }
493
-
494
- const afterFlush: FlushGate["afterFlush"] = (fn) => {
495
- afterFlushes.push(fn)
496
- scheduleFlush()
497
- }
498
-
499
- /**
500
- * The end of the Frame loop's tick (ADR-0033): flush now, in the Refresh frame that computed
501
- * the values, and withdraw the frame the first write since the last flush requested.
502
- */
503
- const flushTicked = (): undefined => {
504
- if (!scheduled) return undefined
505
- cancelFrame(frame)
506
- flush()
507
- return undefined
508
- }
509
-
510
- const scheduleFlush = (): void => {
511
- if (scheduled) return
512
- scheduled = true
513
- frame = requestFrame(flush)
514
- }
515
-
516
- const register: FlushGate["register"] = (id, sink, values) => {
517
- const entry: Entry = {
518
- values: UndefinedOr.match(values, { onUndefined: () => ({}), onDefined: (start) => ({ ...start }) }),
519
- sink,
520
- dirty: false,
521
- committed: new Map(),
522
- outputs: outputsById.get(id),
523
- latest: undefined,
524
- failing: false,
525
- patch: undefined,
526
- }
527
- // An entry the id had: its Timeline values end with it (#240).
528
- const replaced = accumulator.get(id)
529
- if (Predicate.isNotUndefined(replaced)) cancelTimelines(replaced)
530
- accumulator.set(id, entry)
531
- if (Predicate.isNotUndefined(sink.beforeFirstCommit)) firstCommits.add(id)
532
- return () => {
533
- cancelTimelines(entry)
534
- accumulator.delete(id)
535
- firstCommits.delete(id)
536
- committedSince.delete(entry)
537
- endOutputs(id)
538
- }
539
- }
540
-
541
- /** `id`'s live outputs, each set to `undefined` and forgotten: its element is gone. */
542
- const endOutputs = (id: string): void => {
543
- const outputs = outputsById.get(id)
544
- if (Predicate.isUndefined(outputs)) return
545
- outputsById.delete(id)
546
- for (const output of outputs.values()) {
547
- registry.set(output.atom, undefined)
548
- output.unmount()
549
- }
550
- }
551
-
552
- /** `id`'s current value for `key`, or `undefined` for an unregistered id or a key it hasn't written. */
553
- const committedValueOf = (id: string, key: string): unknown => {
554
- const entry = accumulator.get(id)
555
- if (Predicate.isUndefined(entry)) return undefined
556
- return entry.values[key]
557
- }
558
-
559
- const valueOf: FlushGate["valueOf"] = (id, key) => {
560
- let outputs = outputsById.get(id)
561
- if (Predicate.isUndefined(outputs)) {
562
- outputs = new Map()
563
- outputsById.set(id, outputs)
564
- const entry = accumulator.get(id)
565
- if (Predicate.isNotUndefined(entry)) entry.outputs = outputs
566
- }
567
- const known = outputs.get(key)
568
- if (Predicate.isNotUndefined(known)) return known.atom
569
- // Made `undefined` and mounted until its element unregisters, not kept alive: a kept-alive
570
- // Atom's node never leaves the registry, and one left behind reads `undefined` afresh.
571
- const atom = Atom.make<unknown>(undefined)
572
- const output: Output = { atom, last: undefined, unmount: registry.mount(atom) }
573
- outputs.set(key, output)
574
- const value = committedValueOf(id, key)
575
- if (Predicate.isNotUndefined(value)) {
576
- output.last = value
577
- registry.set(atom, value)
578
- }
579
- return atom
580
- }
581
-
582
- const write: FlushGate["write"] = (id, partial) => {
583
- const entry = accumulator.get(id)
584
- if (Predicate.isUndefined(entry)) return
585
- Object.assign(entry.values, partial)
586
- entry.dirty = true
587
- if (Predicate.isNotUndefined(recording)) recording.add(id)
588
- scheduleFlush()
589
- setOutputs(entry)
590
- }
591
-
592
- const flushPass: FlushGate["flushPass"] = (pass) => {
593
- const written = new Set<string>()
594
- recording = written
595
- try {
596
- pass()
597
- } finally {
598
- recording = undefined
599
- }
600
- if (written.size === 0) return
601
- // No `beforeFirstCommit` here: a Measure pass may write only a node's projection, and
602
- // dropping the Starting style then would leave its animated keys unset until the frame
603
- // flush (a frame later for an element mounted inside a frame). The frame flush switches.
604
- // A commit here is told at the frame flush (#233): the write that made it scheduled that flush.
605
- // Its own lists: a pass may run from a hook the frame flush's `batch` runs.
606
- const entries: Array<Entry> = []
607
- const held: Array<Entry> = []
608
- for (const id of written) {
609
- const entry = accumulator.get(id)
610
- if (Predicate.isNotUndefined(entry) && entry.dirty) prepare(entry, entries, held)
611
- }
612
- if (timelines.size > 0 || endings.size > 0) syncTimelines()
613
- commitAll(entries, held)
614
- }
615
-
616
- // Per key per Retarget, as the Override stack takes a key and lets it go: statements (the hot path).
617
- const timeline: FlushGate["timeline"] = (id, key, value) => {
618
- const entry = accumulator.get(id)
619
- if (Predicate.isUndefined(entry)) return
620
- let byKey = timelines.get(entry)
621
- let known: TimelineValue | undefined
622
- if (Predicate.isNotUndefined(byKey)) known = byKey.get(key)
623
- if (known === value) return
624
- // The one it had is cancelled at the next flush, with the commit that draws the key without it.
625
- if (Predicate.isNotUndefined(known)) {
626
- const ending = endings.get(entry)
627
- if (Predicate.isNotUndefined(ending)) ending.push(known)
628
- if (Predicate.isUndefined(ending)) endings.set(entry, [known])
629
- if (Predicate.isNotUndefined(byKey)) byKey.delete(key)
630
- }
631
- if (Predicate.isNotUndefined(value)) {
632
- if (Predicate.isUndefined(byKey)) {
633
- byKey = new Map()
634
- timelines.set(entry, byKey)
635
- }
636
- byKey.set(key, value)
637
- }
638
- // An element left with none leaves the map, so the flush skips it.
639
- if (Predicate.isNotUndefined(byKey) && byKey.size === 0) timelines.delete(entry)
640
- entry.dirty = true
641
- scheduleFlush()
642
- }
643
-
644
- /** `entry`'s Timeline values for `keys`, cancelled at once: those keys go back to the element's own style. */
645
- const releaseTimelines = (entry: Entry, keys: ReadonlyArray<string>): void => {
646
- const byKey = timelines.get(entry)
647
- if (Predicate.isUndefined(byKey)) return
648
- for (const key of keys) {
649
- const value = byKey.get(key)
650
- if (Predicate.isUndefined(value)) continue
651
- byKey.delete(key)
652
- value.cancel()
653
- }
654
- if (byKey.size === 0) timelines.delete(entry)
655
- }
656
-
657
- const release: FlushGate["release"] = (id, keys, restore, keep) => {
658
- const entry = accumulator.get(id)
659
- if (Predicate.isUndefined(entry)) return
660
- releaseTimelines(entry, keys)
661
- // A property another writer draws next: dropped from what's saved, so its drop-out writes nothing.
662
- if (Predicate.isNotUndefined(keep)) for (const property of keep) entry.committed.delete(property)
663
- let released = false
664
- for (const key of keys) {
665
- if (!Object.hasOwn(entry.values, key)) continue
666
- delete entry.values[key]
667
- released = true
668
- // The drop-out path in `apply` writes the saved value back: make it the one handed in.
669
- if (Predicate.isUndefined(restore)) continue
670
- const value: string | undefined = restore[key]
671
- if (Predicate.isNotUndefined(value) && entry.committed.has(key)) entry.committed.set(key, value)
672
- }
673
- if (!released) return
674
- entry.dirty = true
675
- scheduleFlush()
676
- setOutputs(entry)
677
- }
678
-
679
- const dispose: FlushGate["dispose"] = () => {
680
- // Off the loop first, so no tick flushes what follows; a failure reported, never thrown (#618).
681
- const unhooked = Effect.runSyncExit(Scope.close(ticks, Exit.void))
682
- if (Exit.isFailure(unhooked)) runtime.runFork(reportFailure("wardic.gate: its tick hook failed to close", unhooked.cause))
683
- if (scheduled) {
684
- cancelFrame(frame)
685
- scheduled = false
686
- }
687
- for (const entry of accumulator.values()) cancelTimelines(entry)
688
- timelines.clear()
689
- endings.clear()
690
- accumulator.clear()
691
- firstCommits.clear()
692
- committedSince.clear()
693
- // The calls waiting on a flush that won't come: their provider is gone (#257).
694
- afterFlushes = []
695
- for (const id of [...outputsById.keys()]) endOutputs(id)
696
- }
697
-
698
- // The gate's hook on the loop, for the gate's lifetime: a child of the Scope it's built in, so a gate
699
- // its `dispose` never reached is unhooked as that Scope closes.
700
- const ticks = Scope.forkUnsafe(runtime.scope, "sequential")
701
- runtime.runSync(afterTick(flushTicked).pipe(Scope.provide(ticks)))
702
-
703
- return { register, write, flushPass, release, valueOf, afterFlush, timeline, dispose }
704
- }
705
-
706
-