@fluixi/reactive 1.0.0-alpha.83 → 1.0.0-alpha.84

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 (167) hide show
  1. package/dist/cdn/reactive.cjs +2673 -1
  2. package/dist/cdn/reactive.global.js +2 -1
  3. package/dist/cdn/reactive.mjs +2657 -1
  4. package/dist/cdn/signal.cjs +299 -1
  5. package/dist/cdn/signal.d.ts +1 -1
  6. package/dist/cdn/signal.global.js +2 -1
  7. package/dist/cdn/signal.js +1 -1
  8. package/dist/cdn/signal.mjs +276 -1
  9. package/dist/index.cjs +2673 -1
  10. package/dist/index.mjs +2657 -1
  11. package/dist/lib/index.cjs +2674 -1
  12. package/dist/lib/index.js +1 -1
  13. package/dist/lib/index.mjs +2659 -1
  14. package/dist/lib/observable/index.cjs +386 -1
  15. package/dist/lib/observable/index.mjs +364 -1
  16. package/dist/lib/observable/observable.cjs +384 -1
  17. package/dist/lib/observable/observable.d.ts +0 -137
  18. package/dist/lib/observable/observable.d.ts.map +1 -1
  19. package/dist/lib/observable/observable.js +0 -71
  20. package/dist/lib/observable/observable.mjs +361 -1
  21. package/dist/lib/observable/subscription.cjs +180 -1
  22. package/dist/lib/observable/subscription.d.ts +0 -12
  23. package/dist/lib/observable/subscription.d.ts.map +1 -1
  24. package/dist/lib/observable/subscription.js +0 -12
  25. package/dist/lib/observable/subscription.mjs +157 -1
  26. package/dist/lib/observable/types.cjs +18 -1
  27. package/dist/lib/observable/types.d.ts.map +1 -1
  28. package/dist/lib/predicates.cjs +44 -1
  29. package/dist/lib/predicates.d.ts +2 -2
  30. package/dist/lib/predicates.js +2 -2
  31. package/dist/lib/predicates.mjs +23 -1
  32. package/dist/lib/signal/api.cjs +571 -1
  33. package/dist/lib/signal/api.d.ts +211 -1
  34. package/dist/lib/signal/api.d.ts.map +1 -1
  35. package/dist/lib/signal/api.js +207 -12
  36. package/dist/lib/signal/api.mjs +548 -1
  37. package/dist/lib/signal/cached-resource.cjs +672 -1
  38. package/dist/lib/signal/cached-resource.d.ts +28 -16
  39. package/dist/lib/signal/cached-resource.d.ts.map +1 -1
  40. package/dist/lib/signal/cached-resource.js +35 -29
  41. package/dist/lib/signal/cached-resource.mjs +650 -1
  42. package/dist/lib/signal/graph/children.cjs +325 -1
  43. package/dist/lib/signal/graph/children.js +1 -1
  44. package/dist/lib/signal/graph/children.mjs +302 -1
  45. package/dist/lib/signal/graph/compat.cjs +578 -1
  46. package/dist/lib/signal/graph/compat.d.ts +13 -13
  47. package/dist/lib/signal/graph/compat.d.ts.map +1 -1
  48. package/dist/lib/signal/graph/compat.js +33 -31
  49. package/dist/lib/signal/graph/compat.mjs +556 -1
  50. package/dist/lib/signal/graph/core.cjs +295 -1
  51. package/dist/lib/signal/graph/core.d.ts +28 -24
  52. package/dist/lib/signal/graph/core.d.ts.map +1 -1
  53. package/dist/lib/signal/graph/core.js +38 -31
  54. package/dist/lib/signal/graph/core.mjs +273 -1
  55. package/dist/lib/signal/graph/debounced.cjs +668 -1
  56. package/dist/lib/signal/graph/debounced.d.ts +5 -5
  57. package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
  58. package/dist/lib/signal/graph/debounced.js +5 -5
  59. package/dist/lib/signal/graph/debounced.mjs +645 -1
  60. package/dist/lib/signal/graph/derived.cjs +496 -1
  61. package/dist/lib/signal/graph/derived.d.ts +1 -1
  62. package/dist/lib/signal/graph/derived.js +1 -1
  63. package/dist/lib/signal/graph/derived.mjs +473 -1
  64. package/dist/lib/signal/graph/detect.cjs +66 -1
  65. package/dist/lib/signal/graph/detect.mjs +45 -1
  66. package/dist/lib/signal/graph/error-boundary.cjs +301 -1
  67. package/dist/lib/signal/graph/error-boundary.js +3 -3
  68. package/dist/lib/signal/graph/error-boundary.mjs +278 -1
  69. package/dist/lib/signal/graph/index.cjs +305 -1
  70. package/dist/lib/signal/graph/index.d.ts +7 -6
  71. package/dist/lib/signal/graph/index.d.ts.map +1 -1
  72. package/dist/lib/signal/graph/index.js +7 -6
  73. package/dist/lib/signal/graph/index.mjs +283 -1
  74. package/dist/lib/signal/graph/observe.cjs +163 -1
  75. package/dist/lib/signal/graph/observe.d.ts +8 -8
  76. package/dist/lib/signal/graph/observe.js +5 -5
  77. package/dist/lib/signal/graph/observe.mjs +140 -1
  78. package/dist/lib/signal/graph/resource.cjs +620 -1
  79. package/dist/lib/signal/graph/resource.d.ts +1 -1
  80. package/dist/lib/signal/graph/resource.js +7 -8
  81. package/dist/lib/signal/graph/resource.mjs +597 -1
  82. package/dist/lib/signal/graph/runtime.cjs +501 -1
  83. package/dist/lib/signal/graph/runtime.d.ts +7 -7
  84. package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
  85. package/dist/lib/signal/graph/runtime.js +34 -30
  86. package/dist/lib/signal/graph/runtime.mjs +478 -1
  87. package/dist/lib/signal/graph/signal-next.cjs +1208 -1
  88. package/dist/lib/signal/graph/signal-next.d.ts +5 -5
  89. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
  90. package/dist/lib/signal/graph/signal-next.js +14 -12
  91. package/dist/lib/signal/graph/signal-next.mjs +1186 -1
  92. package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
  93. package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
  94. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
  95. package/dist/lib/signal/graph/ssr-hooks.js +6 -7
  96. package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
  97. package/dist/lib/signal/graph/state.cjs +72 -1
  98. package/dist/lib/signal/graph/state.d.ts +41 -10
  99. package/dist/lib/signal/graph/state.d.ts.map +1 -1
  100. package/dist/lib/signal/graph/state.js +83 -22
  101. package/dist/lib/signal/graph/state.mjs +49 -1
  102. package/dist/lib/signal/graph/suspense.cjs +301 -1
  103. package/dist/lib/signal/graph/suspense.js +4 -4
  104. package/dist/lib/signal/graph/suspense.mjs +278 -1
  105. package/dist/lib/signal/index-legacy.cjs +2540 -1
  106. package/dist/lib/signal/index-legacy.d.ts +1 -1
  107. package/dist/lib/signal/index-legacy.js +1 -1
  108. package/dist/lib/signal/index-legacy.mjs +2518 -1
  109. package/dist/lib/signal/index.cjs +1275 -1
  110. package/dist/lib/signal/index.d.ts +3 -2
  111. package/dist/lib/signal/index.d.ts.map +1 -1
  112. package/dist/lib/signal/index.js +7 -4
  113. package/dist/lib/signal/index.mjs +1253 -1
  114. package/dist/lib/signal/list.cjs +549 -1
  115. package/dist/lib/signal/list.d.ts +5 -5
  116. package/dist/lib/signal/list.js +5 -5
  117. package/dist/lib/signal/list.mjs +526 -1
  118. package/dist/lib/signal/resource-api.cjs +626 -1
  119. package/dist/lib/signal/resource-api.d.ts +5 -5
  120. package/dist/lib/signal/resource-api.js +5 -5
  121. package/dist/lib/signal/resource-api.mjs +603 -1
  122. package/dist/lib/signal/signal.cjs +2023 -1
  123. package/dist/lib/signal/signal.d.ts +4 -4
  124. package/dist/lib/signal/signal.d.ts.map +1 -1
  125. package/dist/lib/signal/signal.js +22 -23
  126. package/dist/lib/signal/signal.mjs +2000 -1
  127. package/dist/lib/signal/types.cjs +38 -1
  128. package/dist/lib/signal/types.d.ts.map +1 -1
  129. package/dist/lib/signal/types.js +2 -2
  130. package/dist/lib/signal/types.mjs +17 -1
  131. package/dist/lib/signal/utilities.cjs +1012 -1
  132. package/dist/lib/signal/utilities.d.ts +0 -108
  133. package/dist/lib/signal/utilities.d.ts.map +1 -1
  134. package/dist/lib/signal/utilities.js +0 -158
  135. package/dist/lib/signal/utilities.mjs +990 -1
  136. package/dist/lib/store/api.cjs +612 -1
  137. package/dist/lib/store/api.d.ts +33 -0
  138. package/dist/lib/store/api.d.ts.map +1 -1
  139. package/dist/lib/store/api.js +41 -8
  140. package/dist/lib/store/api.mjs +596 -1
  141. package/dist/lib/store/index.cjs +691 -1
  142. package/dist/lib/store/index.js +1 -1
  143. package/dist/lib/store/index.mjs +676 -1
  144. package/dist/lib/store/setter.types.cjs +18 -1
  145. package/dist/lib/store/setter.types.d.ts +43 -3
  146. package/dist/lib/store/setter.types.d.ts.map +1 -1
  147. package/dist/lib/store/store.cjs +658 -1
  148. package/dist/lib/store/store.d.ts +72 -0
  149. package/dist/lib/store/store.d.ts.map +1 -1
  150. package/dist/lib/store/store.js +148 -5
  151. package/dist/lib/store/store.mjs +644 -1
  152. package/dist/lib/store/types.cjs +18 -1
  153. package/dist/lib/store/types.d.ts +1 -1
  154. package/dist/lib/store/types.d.ts.map +1 -1
  155. package/dist/lib/store/utils.cjs +43 -1
  156. package/dist/lib/store/utils.d.ts +1 -1
  157. package/dist/lib/store/utils.js +1 -1
  158. package/dist/lib/store/utils.mjs +22 -1
  159. package/dist/lib/subject.cjs +450 -1
  160. package/dist/lib/subject.js +3 -91
  161. package/dist/lib/subject.mjs +427 -1
  162. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  163. package/dist/version.generated.cjs +27 -1
  164. package/dist/version.generated.d.ts +1 -1
  165. package/dist/version.generated.js +2 -2
  166. package/dist/version.generated.mjs +7 -1
  167. package/package.json +5 -4
@@ -1,17 +1,19 @@
1
1
  /**
2
- * L2 (core) the legacy public reactive API re-expressed on top of L0 (graph) +
3
- * L1 (runtime), with byte-identical signatures so it is a drop-in for the existing
4
- * `createSignal`/`createMemo`/`createEffect`/… surface. This is the "re-point": the
5
- * old API delegates to the TC39-shaped core instead of the bespoke Computation graph.
2
+ * The `create*` names, over the graph core and the runtime.
6
3
  *
7
- * Scope: the CORE primitives (signals, memos, effects, roots, batch, untrack, on).
8
- * The wider surface (resources, stores, context, suspense, transitions, the SSR
9
- * eager-stale/drain hooks) is ported separately before the production export flips
10
- * until then this lives behind its own module + spec, validated for behavioural
11
- * equivalence against the legacy oracle.
4
+ * Signatures are identical to the ones this API has always had, so nothing calling
5
+ * `createSignal`, `createMemo` or `createEffect` can tell the difference. What
6
+ * changed underneath is that they now delegate to the TC39-shaped core in `core.ts`
7
+ * rather than to the bespoke `Computation` graph, which survives in `../signal.ts`
8
+ * as archive.
12
9
  *
13
- * Timing note: legacy effects flush SYNCHRONOUSLY on a write (outside batch), so we
14
- * install a synchronous L1 scheduler here; `batch` still coalesces to one flush.
10
+ * This module covers the primitives: signals, memos, effects, roots, batch, untrack
11
+ * and on. The wider surface, resources and stores and context and suspense and
12
+ * transitions and the SSR hooks, is ported in the modules beside it.
13
+ *
14
+ * Timing: effects flush synchronously on a write outside a batch, which is what this
15
+ * API has always done, so the scheduler installed here is synchronous. `batch` still
16
+ * coalesces a group of writes into one flush.
15
17
  */
16
18
  import { State, Computed, untrack as l0untrack } from './core.js';
17
19
  import { effect as l1effect, batch as l1batch, setScheduler, afterWrite, flushSync, reportSuspend, getOwner, runWithOwner, onCleanup as l1onCleanup, } from './runtime.js';
@@ -21,9 +23,9 @@ function isThenable(v) {
21
23
  }
22
24
  export { createRoot, onCleanup, getOwner, setOwner, runWithOwner } from './runtime.js';
23
25
  // Compat owns all flush points (afterWrite / batch), so the host scheduler is a
24
- // no-op: enqueue only QUEUES; a write marks the whole graph then flushes once via
26
+ // no-op: enqueue only queues; a write marks the whole graph then flushes once via
25
27
  // afterWrite. This separates marking from running (glitch-free, legacy-equivalent
26
- // synchronous effects) a synchronous scheduler that flushed mid-propagation would
28
+ // synchronous effects), a synchronous scheduler that flushed mid-propagation would
27
29
  // run effects before all observers were marked.
28
30
  setScheduler(() => { });
29
31
  const $SIGNAL = Symbol.for('signal');
@@ -32,7 +34,7 @@ const $MEMO = Symbol.for('memo');
32
34
  // under this symbol; consumers like the store read `signal[$NODE].value` to gate
33
35
  // updates. compat exposes a matching node-like view so those consumers work unchanged.
34
36
  const $NODE = Symbol.for('signal-node');
35
- /** createSignal a writable cell, returned as the legacy `[get, set]` tuple. */
37
+ /** createSignal, a writable cell, returned as the legacy `[get, set]` tuple. */
36
38
  export function createSignal(value, options) {
37
39
  const state = new State(value, { equals: options?.equals });
38
40
  const read = (() => state.get());
@@ -68,11 +70,11 @@ export function createSignal(value, options) {
68
70
  l1onCleanup(() => reportReactiveDispose(state));
69
71
  return [read, write];
70
72
  }
71
- /** createMemo a lazy, cached derived value (legacy accessor). */
73
+ /** createMemo, a lazy, cached derived value (legacy accessor). */
72
74
  export function createMemo(fn, value, options) {
73
75
  let prev = value;
74
76
  // Capture the owner at creation so the memo's fn (and any component it renders, e.g.
75
- // a lazy route) runs under THIS scope's owner preserving context up the owner chain
77
+ // a lazy route) runs under this scope's owner, preserving context up the owner chain
76
78
  // even when the memo recomputes later (async SSR drain). Matches legacy memo semantics.
77
79
  const owner = getOwner();
78
80
  const c = new Computed(() => runWithOwner(owner, () => {
@@ -91,38 +93,38 @@ export function createMemo(fn, value, options) {
91
93
  }
92
94
  }), { equals: options?.equals });
93
95
  const read = (() => c.get());
94
- // A memo IS a readable reactive accessor stamp $SIGNAL (matching the legacy
96
+ // A memo is a readable reactive accessor: stamp $SIGNAL (matching the legacy
95
97
  // createMemo) so `isSignal(memo)` is true. Without this, the DOM runtime's
96
98
  // insert() fails to recognise a control-flow memo (For/Switch/Index/Dynamic)
97
- // as reactive, caches it as a component, and freezes it updates never apply.
99
+ // as reactive, caches it as a component, and freezes it -> updates never apply.
98
100
  Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
99
101
  Object.defineProperty(read, $MEMO, { value: true, enumerable: true });
100
102
  reportReactiveNode({ kind: 'memo', node: c, handle: read, name: options?.name });
101
- // A memo has no dispose of its own it goes when its owner does. Without saying so, a
103
+ // A memo has no dispose of its own, it goes when its owner does. Without saying so, a
102
104
  // list that re-renders leaves every row it ever had in a watcher's graph.
103
105
  if (isObserved())
104
106
  l1onCleanup(() => reportReactiveDispose(c));
105
107
  return read;
106
108
  }
107
109
  /**
108
- * createEffect a re-running side effect. The fn receives the previous return
110
+ * createEffect, a re-running side effect. The fn receives the previous return
109
111
  * value and may return a new one (legacy signature) or a cleanup function.
110
112
  */
111
113
  export function createEffect(fn, value) {
112
114
  let prev = value;
113
115
  return l1effect(() => {
114
116
  const r = fn(prev);
115
- // A function result is treated as the next "prev" (legacy) unless the fn
117
+ // A function result is treated as the next "prev" (legacy), unless the fn
116
118
  // never returns one, in which case onCleanup is the cleanup path. We keep the
117
119
  // legacy carry-the-value behaviour; cleanups use onCleanup.
118
120
  prev = r;
119
121
  }, true);
120
122
  }
121
123
  /**
122
- * createComputed an EAGER, owner-managed reactive computation (returns void).
124
+ * createComputed, an EAGER, owner-managed reactive computation (returns void).
123
125
  * Unlike a lazy memo it runs immediately and re-runs eagerly when a dep changes;
124
- * used for derivations with side effects (e.g. store internals). On L1 that is an
125
- * eager effect whose dispose is owned by the current scope.
126
+ * used for derivations with side effects, such as store internals. It is an eager
127
+ * effect whose dispose is owned by the current scope.
126
128
  */
127
129
  export function createComputed(fn, value) {
128
130
  let prev = value;
@@ -131,7 +133,7 @@ export function createComputed(fn, value) {
131
133
  });
132
134
  }
133
135
  /**
134
- * createRenderEffect an effect that runs in the render phase. For the reactive
136
+ * createRenderEffect, an effect that runs in the render phase. For the reactive
135
137
  * core this is an eager effect (the render-vs-commit timing distinction is a DOM-
136
138
  * layer concern); returns a dispose like createEffect.
137
139
  */
@@ -141,16 +143,16 @@ export function createRenderEffect(fn, value) {
141
143
  prev = fn(prev);
142
144
  });
143
145
  }
144
- /** batch coalesce writes so dependent effects flush once. */
146
+ /** batch: coalesce writes so dependent effects flush once. */
145
147
  export function batch(fn) {
146
148
  return l1batch(fn);
147
149
  }
148
- /** untrack read without subscribing. */
150
+ /** untrack: read without subscribing. */
149
151
  export function untrack(fn) {
150
152
  return l0untrack(fn);
151
153
  }
152
154
  /**
153
- * startTransition run `fn`'s updates as one batch. (Minimal port: the concurrent
155
+ * startTransition: run `fn`'s updates as one batch. (Minimal port, the concurrent
154
156
  * time-slicing/deferral of the legacy implementation is a later refinement; the
155
157
  * batched-commit semantics that callers rely on are preserved.)
156
158
  */
@@ -158,14 +160,14 @@ export function startTransition(fn) {
158
160
  l1batch(fn);
159
161
  return Promise.resolve();
160
162
  }
161
- /** useTransition `[isPending, startTransition]`. isPending is synchronous here (no deferral). */
163
+ /** useTransition: `[isPending, startTransition]`. isPending is synchronous here (no deferral). */
162
164
  export function useTransition() {
163
165
  return [() => false, startTransition];
164
166
  }
165
167
  /** Force any pending effects to run now. */
166
168
  export { flushSync };
167
169
  /**
168
- * flush drain pending effects, returning a Promise (legacy `flush()` is async; many
170
+ * flush: drain pending effects, returning a Promise (legacy `flush()` is async; many
169
171
  * callers do `flush().then(...)`). Effects already flush synchronously on each write via
170
172
  * afterWrite, so this just settles any remainder and resolves.
171
173
  */
@@ -174,7 +176,7 @@ export function flush() {
174
176
  return Promise.resolve();
175
177
  }
176
178
  /**
177
- * on(deps, fn, { defer }) an explicit-dependency helper. Reads `deps` (tracked),
179
+ * on(deps, fn, { defer }), an explicit-dependency helper. Reads `deps` (tracked),
178
180
  * then runs `fn(value, prevValue, prevResult)` untracked. `defer` skips the first run.
179
181
  */
180
182
  export function on(deps, fn, options) {