@fluixi/reactive 1.0.0-alpha.82 → 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 (169) hide show
  1. package/README.md +4 -0
  2. package/dist/cdn/reactive.cjs +2673 -1
  3. package/dist/cdn/reactive.global.js +2 -1
  4. package/dist/cdn/reactive.mjs +2657 -1
  5. package/dist/cdn/signal.cjs +299 -1
  6. package/dist/cdn/signal.d.ts +1 -1
  7. package/dist/cdn/signal.global.js +2 -1
  8. package/dist/cdn/signal.js +1 -1
  9. package/dist/cdn/signal.mjs +276 -1
  10. package/dist/index.cjs +2673 -1
  11. package/dist/index.mjs +2657 -1
  12. package/dist/lib/index.cjs +2674 -1
  13. package/dist/lib/index.js +1 -1
  14. package/dist/lib/index.mjs +2659 -1
  15. package/dist/lib/observable/index.cjs +386 -1
  16. package/dist/lib/observable/index.mjs +364 -1
  17. package/dist/lib/observable/observable.cjs +384 -1
  18. package/dist/lib/observable/observable.d.ts +0 -137
  19. package/dist/lib/observable/observable.d.ts.map +1 -1
  20. package/dist/lib/observable/observable.js +0 -71
  21. package/dist/lib/observable/observable.mjs +361 -1
  22. package/dist/lib/observable/subscription.cjs +180 -1
  23. package/dist/lib/observable/subscription.d.ts +0 -12
  24. package/dist/lib/observable/subscription.d.ts.map +1 -1
  25. package/dist/lib/observable/subscription.js +0 -12
  26. package/dist/lib/observable/subscription.mjs +157 -1
  27. package/dist/lib/observable/types.cjs +18 -1
  28. package/dist/lib/observable/types.d.ts.map +1 -1
  29. package/dist/lib/predicates.cjs +44 -1
  30. package/dist/lib/predicates.d.ts +2 -2
  31. package/dist/lib/predicates.js +2 -2
  32. package/dist/lib/predicates.mjs +23 -1
  33. package/dist/lib/signal/api.cjs +571 -1
  34. package/dist/lib/signal/api.d.ts +211 -1
  35. package/dist/lib/signal/api.d.ts.map +1 -1
  36. package/dist/lib/signal/api.js +207 -12
  37. package/dist/lib/signal/api.mjs +548 -1
  38. package/dist/lib/signal/cached-resource.cjs +672 -1
  39. package/dist/lib/signal/cached-resource.d.ts +28 -16
  40. package/dist/lib/signal/cached-resource.d.ts.map +1 -1
  41. package/dist/lib/signal/cached-resource.js +35 -29
  42. package/dist/lib/signal/cached-resource.mjs +650 -1
  43. package/dist/lib/signal/graph/children.cjs +325 -1
  44. package/dist/lib/signal/graph/children.js +1 -1
  45. package/dist/lib/signal/graph/children.mjs +302 -1
  46. package/dist/lib/signal/graph/compat.cjs +578 -1
  47. package/dist/lib/signal/graph/compat.d.ts +13 -13
  48. package/dist/lib/signal/graph/compat.d.ts.map +1 -1
  49. package/dist/lib/signal/graph/compat.js +51 -32
  50. package/dist/lib/signal/graph/compat.mjs +556 -1
  51. package/dist/lib/signal/graph/core.cjs +295 -1
  52. package/dist/lib/signal/graph/core.d.ts +28 -24
  53. package/dist/lib/signal/graph/core.d.ts.map +1 -1
  54. package/dist/lib/signal/graph/core.js +45 -31
  55. package/dist/lib/signal/graph/core.mjs +273 -1
  56. package/dist/lib/signal/graph/debounced.cjs +668 -1
  57. package/dist/lib/signal/graph/debounced.d.ts +5 -5
  58. package/dist/lib/signal/graph/debounced.d.ts.map +1 -1
  59. package/dist/lib/signal/graph/debounced.js +5 -5
  60. package/dist/lib/signal/graph/debounced.mjs +645 -1
  61. package/dist/lib/signal/graph/derived.cjs +496 -1
  62. package/dist/lib/signal/graph/derived.d.ts +1 -1
  63. package/dist/lib/signal/graph/derived.js +1 -1
  64. package/dist/lib/signal/graph/derived.mjs +473 -1
  65. package/dist/lib/signal/graph/detect.cjs +66 -1
  66. package/dist/lib/signal/graph/detect.mjs +45 -1
  67. package/dist/lib/signal/graph/error-boundary.cjs +301 -1
  68. package/dist/lib/signal/graph/error-boundary.js +3 -3
  69. package/dist/lib/signal/graph/error-boundary.mjs +278 -1
  70. package/dist/lib/signal/graph/index.cjs +305 -1
  71. package/dist/lib/signal/graph/index.d.ts +7 -6
  72. package/dist/lib/signal/graph/index.d.ts.map +1 -1
  73. package/dist/lib/signal/graph/index.js +7 -6
  74. package/dist/lib/signal/graph/index.mjs +283 -1
  75. package/dist/lib/signal/graph/observe.cjs +163 -0
  76. package/dist/lib/signal/graph/observe.d.ts +141 -0
  77. package/dist/lib/signal/graph/observe.d.ts.map +1 -0
  78. package/dist/lib/signal/graph/observe.js +149 -0
  79. package/dist/lib/signal/graph/observe.mjs +140 -0
  80. package/dist/lib/signal/graph/resource.cjs +620 -1
  81. package/dist/lib/signal/graph/resource.d.ts +1 -1
  82. package/dist/lib/signal/graph/resource.js +7 -8
  83. package/dist/lib/signal/graph/resource.mjs +597 -1
  84. package/dist/lib/signal/graph/runtime.cjs +501 -1
  85. package/dist/lib/signal/graph/runtime.d.ts +9 -9
  86. package/dist/lib/signal/graph/runtime.d.ts.map +1 -1
  87. package/dist/lib/signal/graph/runtime.js +56 -37
  88. package/dist/lib/signal/graph/runtime.mjs +478 -1
  89. package/dist/lib/signal/graph/signal-next.cjs +1208 -1
  90. package/dist/lib/signal/graph/signal-next.d.ts +5 -5
  91. package/dist/lib/signal/graph/signal-next.d.ts.map +1 -1
  92. package/dist/lib/signal/graph/signal-next.js +14 -12
  93. package/dist/lib/signal/graph/signal-next.mjs +1186 -1
  94. package/dist/lib/signal/graph/ssr-hooks.cjs +60 -1
  95. package/dist/lib/signal/graph/ssr-hooks.d.ts +6 -7
  96. package/dist/lib/signal/graph/ssr-hooks.d.ts.map +1 -1
  97. package/dist/lib/signal/graph/ssr-hooks.js +6 -7
  98. package/dist/lib/signal/graph/ssr-hooks.mjs +39 -1
  99. package/dist/lib/signal/graph/state.cjs +72 -1
  100. package/dist/lib/signal/graph/state.d.ts +43 -10
  101. package/dist/lib/signal/graph/state.d.ts.map +1 -1
  102. package/dist/lib/signal/graph/state.js +83 -21
  103. package/dist/lib/signal/graph/state.mjs +49 -1
  104. package/dist/lib/signal/graph/suspense.cjs +301 -1
  105. package/dist/lib/signal/graph/suspense.js +4 -4
  106. package/dist/lib/signal/graph/suspense.mjs +278 -1
  107. package/dist/lib/signal/index-legacy.cjs +2540 -1
  108. package/dist/lib/signal/index-legacy.d.ts +1 -1
  109. package/dist/lib/signal/index-legacy.js +1 -1
  110. package/dist/lib/signal/index-legacy.mjs +2518 -1
  111. package/dist/lib/signal/index.cjs +1275 -1
  112. package/dist/lib/signal/index.d.ts +5 -2
  113. package/dist/lib/signal/index.d.ts.map +1 -1
  114. package/dist/lib/signal/index.js +8 -3
  115. package/dist/lib/signal/index.mjs +1253 -1
  116. package/dist/lib/signal/list.cjs +549 -1
  117. package/dist/lib/signal/list.d.ts +5 -5
  118. package/dist/lib/signal/list.js +10 -10
  119. package/dist/lib/signal/list.mjs +526 -1
  120. package/dist/lib/signal/resource-api.cjs +626 -1
  121. package/dist/lib/signal/resource-api.d.ts +5 -5
  122. package/dist/lib/signal/resource-api.js +5 -5
  123. package/dist/lib/signal/resource-api.mjs +603 -1
  124. package/dist/lib/signal/signal.cjs +2023 -1
  125. package/dist/lib/signal/signal.d.ts +4 -4
  126. package/dist/lib/signal/signal.d.ts.map +1 -1
  127. package/dist/lib/signal/signal.js +22 -23
  128. package/dist/lib/signal/signal.mjs +2000 -1
  129. package/dist/lib/signal/types.cjs +38 -1
  130. package/dist/lib/signal/types.d.ts.map +1 -1
  131. package/dist/lib/signal/types.js +2 -2
  132. package/dist/lib/signal/types.mjs +17 -1
  133. package/dist/lib/signal/utilities.cjs +1012 -1
  134. package/dist/lib/signal/utilities.d.ts +0 -108
  135. package/dist/lib/signal/utilities.d.ts.map +1 -1
  136. package/dist/lib/signal/utilities.js +0 -158
  137. package/dist/lib/signal/utilities.mjs +990 -1
  138. package/dist/lib/store/api.cjs +612 -1
  139. package/dist/lib/store/api.d.ts +33 -0
  140. package/dist/lib/store/api.d.ts.map +1 -1
  141. package/dist/lib/store/api.js +41 -8
  142. package/dist/lib/store/api.mjs +596 -1
  143. package/dist/lib/store/index.cjs +691 -1
  144. package/dist/lib/store/index.js +1 -1
  145. package/dist/lib/store/index.mjs +676 -1
  146. package/dist/lib/store/setter.types.cjs +18 -1
  147. package/dist/lib/store/setter.types.d.ts +43 -3
  148. package/dist/lib/store/setter.types.d.ts.map +1 -1
  149. package/dist/lib/store/store.cjs +658 -1
  150. package/dist/lib/store/store.d.ts +72 -0
  151. package/dist/lib/store/store.d.ts.map +1 -1
  152. package/dist/lib/store/store.js +294 -11
  153. package/dist/lib/store/store.mjs +644 -1
  154. package/dist/lib/store/types.cjs +18 -1
  155. package/dist/lib/store/types.d.ts +1 -1
  156. package/dist/lib/store/types.d.ts.map +1 -1
  157. package/dist/lib/store/utils.cjs +43 -1
  158. package/dist/lib/store/utils.d.ts +1 -1
  159. package/dist/lib/store/utils.js +1 -1
  160. package/dist/lib/store/utils.mjs +22 -1
  161. package/dist/lib/subject.cjs +450 -1
  162. package/dist/lib/subject.js +3 -91
  163. package/dist/lib/subject.mjs +427 -1
  164. package/dist/tsconfig.lib.tsbuildinfo +1 -1
  165. package/dist/version.generated.cjs +27 -1
  166. package/dist/version.generated.d.ts +1 -1
  167. package/dist/version.generated.js +2 -2
  168. package/dist/version.generated.mjs +7 -1
  169. package/package.json +5 -4
@@ -1,28 +1,31 @@
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
- import { effect as l1effect, batch as l1batch, setScheduler, afterWrite, flushSync, reportSuspend, getOwner, runWithOwner, } from './runtime.js';
19
+ import { effect as l1effect, batch as l1batch, setScheduler, afterWrite, flushSync, reportSuspend, getOwner, runWithOwner, onCleanup as l1onCleanup, } from './runtime.js';
20
+ import { isObserved, reportReactiveDispose, reportReactiveNode } from './observe.js';
18
21
  function isThenable(v) {
19
22
  return !!v && typeof v.then === 'function';
20
23
  }
21
24
  export { createRoot, onCleanup, getOwner, setOwner, runWithOwner } from './runtime.js';
22
25
  // Compat owns all flush points (afterWrite / batch), so the host scheduler is a
23
- // 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
24
27
  // afterWrite. This separates marking from running (glitch-free, legacy-equivalent
25
- // synchronous effects) a synchronous scheduler that flushed mid-propagation would
28
+ // synchronous effects), a synchronous scheduler that flushed mid-propagation would
26
29
  // run effects before all observers were marked.
27
30
  setScheduler(() => { });
28
31
  const $SIGNAL = Symbol.for('signal');
@@ -31,7 +34,7 @@ const $MEMO = Symbol.for('memo');
31
34
  // under this symbol; consumers like the store read `signal[$NODE].value` to gate
32
35
  // updates. compat exposes a matching node-like view so those consumers work unchanged.
33
36
  const $NODE = Symbol.for('signal-node');
34
- /** createSignal a writable cell, returned as the legacy `[get, set]` tuple. */
37
+ /** createSignal, a writable cell, returned as the legacy `[get, set]` tuple. */
35
38
  export function createSignal(value, options) {
36
39
  const state = new State(value, { equals: options?.equals });
37
40
  const read = (() => state.get());
@@ -54,13 +57,24 @@ export function createSignal(value, options) {
54
57
  },
55
58
  enumerable: false,
56
59
  });
60
+ reportReactiveNode({
61
+ kind: 'signal',
62
+ node: state,
63
+ handle: read,
64
+ name: options?.name,
65
+ set: write,
66
+ });
67
+ // A signal goes when its owner does, the same as a memo. A list rebuilt without a key
68
+ // makes one per row per update, and a watcher that is never told keeps every one of them.
69
+ if (isObserved())
70
+ l1onCleanup(() => reportReactiveDispose(state));
57
71
  return [read, write];
58
72
  }
59
- /** createMemo a lazy, cached derived value (legacy accessor). */
73
+ /** createMemo, a lazy, cached derived value (legacy accessor). */
60
74
  export function createMemo(fn, value, options) {
61
75
  let prev = value;
62
76
  // Capture the owner at creation so the memo's fn (and any component it renders, e.g.
63
- // 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
64
78
  // even when the memo recomputes later (async SSR drain). Matches legacy memo semantics.
65
79
  const owner = getOwner();
66
80
  const c = new Computed(() => runWithOwner(owner, () => {
@@ -79,33 +93,38 @@ export function createMemo(fn, value, options) {
79
93
  }
80
94
  }), { equals: options?.equals });
81
95
  const read = (() => c.get());
82
- // 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
83
97
  // createMemo) so `isSignal(memo)` is true. Without this, the DOM runtime's
84
98
  // insert() fails to recognise a control-flow memo (For/Switch/Index/Dynamic)
85
- // 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.
86
100
  Object.defineProperty(read, $SIGNAL, { value: true, enumerable: true });
87
101
  Object.defineProperty(read, $MEMO, { value: true, enumerable: true });
102
+ reportReactiveNode({ kind: 'memo', node: c, handle: read, name: options?.name });
103
+ // A memo has no dispose of its own, it goes when its owner does. Without saying so, a
104
+ // list that re-renders leaves every row it ever had in a watcher's graph.
105
+ if (isObserved())
106
+ l1onCleanup(() => reportReactiveDispose(c));
88
107
  return read;
89
108
  }
90
109
  /**
91
- * 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
92
111
  * value and may return a new one (legacy signature) or a cleanup function.
93
112
  */
94
113
  export function createEffect(fn, value) {
95
114
  let prev = value;
96
115
  return l1effect(() => {
97
116
  const r = fn(prev);
98
- // 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
99
118
  // never returns one, in which case onCleanup is the cleanup path. We keep the
100
119
  // legacy carry-the-value behaviour; cleanups use onCleanup.
101
120
  prev = r;
102
- });
121
+ }, true);
103
122
  }
104
123
  /**
105
- * createComputed an EAGER, owner-managed reactive computation (returns void).
124
+ * createComputed, an EAGER, owner-managed reactive computation (returns void).
106
125
  * Unlike a lazy memo it runs immediately and re-runs eagerly when a dep changes;
107
- * used for derivations with side effects (e.g. store internals). On L1 that is an
108
- * 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.
109
128
  */
110
129
  export function createComputed(fn, value) {
111
130
  let prev = value;
@@ -114,7 +133,7 @@ export function createComputed(fn, value) {
114
133
  });
115
134
  }
116
135
  /**
117
- * 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
118
137
  * core this is an eager effect (the render-vs-commit timing distinction is a DOM-
119
138
  * layer concern); returns a dispose like createEffect.
120
139
  */
@@ -124,16 +143,16 @@ export function createRenderEffect(fn, value) {
124
143
  prev = fn(prev);
125
144
  });
126
145
  }
127
- /** batch coalesce writes so dependent effects flush once. */
146
+ /** batch: coalesce writes so dependent effects flush once. */
128
147
  export function batch(fn) {
129
148
  return l1batch(fn);
130
149
  }
131
- /** untrack read without subscribing. */
150
+ /** untrack: read without subscribing. */
132
151
  export function untrack(fn) {
133
152
  return l0untrack(fn);
134
153
  }
135
154
  /**
136
- * 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
137
156
  * time-slicing/deferral of the legacy implementation is a later refinement; the
138
157
  * batched-commit semantics that callers rely on are preserved.)
139
158
  */
@@ -141,14 +160,14 @@ export function startTransition(fn) {
141
160
  l1batch(fn);
142
161
  return Promise.resolve();
143
162
  }
144
- /** useTransition `[isPending, startTransition]`. isPending is synchronous here (no deferral). */
163
+ /** useTransition: `[isPending, startTransition]`. isPending is synchronous here (no deferral). */
145
164
  export function useTransition() {
146
165
  return [() => false, startTransition];
147
166
  }
148
167
  /** Force any pending effects to run now. */
149
168
  export { flushSync };
150
169
  /**
151
- * 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
152
171
  * callers do `flush().then(...)`). Effects already flush synchronously on each write via
153
172
  * afterWrite, so this just settles any remainder and resolves.
154
173
  */
@@ -157,7 +176,7 @@ export function flush() {
157
176
  return Promise.resolve();
158
177
  }
159
178
  /**
160
- * on(deps, fn, { defer }) an explicit-dependency helper. Reads `deps` (tracked),
179
+ * on(deps, fn, { defer }), an explicit-dependency helper. Reads `deps` (tracked),
161
180
  * then runs `fn(value, prevValue, prevResult)` untracked. `defer` skips the first run.
162
181
  */
163
182
  export function on(deps, fn, options) {