@vielzeug/ripple 1.3.0 → 2.0.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 (163) hide show
  1. package/README.md +33 -72
  2. package/dist/_async.cjs +2 -0
  3. package/dist/_async.cjs.map +1 -0
  4. package/dist/_async.d.ts +40 -0
  5. package/dist/_async.d.ts.map +1 -0
  6. package/dist/_async.js +75 -0
  7. package/dist/_async.js.map +1 -0
  8. package/dist/_store.cjs +2 -0
  9. package/dist/_store.cjs.map +1 -0
  10. package/dist/_store.d.ts +20 -0
  11. package/dist/_store.d.ts.map +1 -0
  12. package/dist/_store.js +24 -0
  13. package/dist/_store.js.map +1 -0
  14. package/dist/_watch.cjs +2 -0
  15. package/dist/_watch.cjs.map +1 -0
  16. package/dist/_watch.d.ts +15 -0
  17. package/dist/_watch.d.ts.map +1 -0
  18. package/dist/_watch.js +18 -0
  19. package/dist/_watch.js.map +1 -0
  20. package/dist/async.cjs +1 -0
  21. package/dist/async.d.ts +3 -0
  22. package/dist/async.d.ts.map +1 -0
  23. package/dist/async.js +2 -0
  24. package/dist/errors.cjs +1 -1
  25. package/dist/errors.cjs.map +1 -1
  26. package/dist/errors.d.ts +2 -15
  27. package/dist/errors.d.ts.map +1 -1
  28. package/dist/errors.js +2 -2
  29. package/dist/errors.js.map +1 -1
  30. package/dist/index.cjs +2 -1
  31. package/dist/index.cjs.map +1 -0
  32. package/dist/index.d.ts +34 -10
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +25 -11
  35. package/dist/index.js.map +1 -0
  36. package/dist/ripple.cjs +1 -1
  37. package/dist/ripple.cjs.map +1 -1
  38. package/dist/ripple.iife.js +1 -1
  39. package/dist/ripple.iife.js.map +1 -1
  40. package/dist/ripple.js +1 -1
  41. package/dist/ripple.js.map +1 -1
  42. package/dist/runtime.cjs +2 -0
  43. package/dist/runtime.cjs.map +1 -0
  44. package/dist/runtime.d.ts +98 -0
  45. package/dist/runtime.d.ts.map +1 -0
  46. package/dist/runtime.js +340 -0
  47. package/dist/runtime.js.map +1 -0
  48. package/dist/store.cjs +1 -2
  49. package/dist/store.d.ts +2 -57
  50. package/dist/store.d.ts.map +1 -1
  51. package/dist/store.js +2 -207
  52. package/dist/types.d.ts +37 -301
  53. package/dist/types.d.ts.map +1 -1
  54. package/dist/watch.cjs +1 -0
  55. package/dist/watch.d.ts +3 -0
  56. package/dist/watch.d.ts.map +1 -0
  57. package/dist/watch.js +2 -0
  58. package/package.json +22 -21
  59. package/dist/_dev.cjs +0 -2
  60. package/dist/_dev.cjs.map +0 -1
  61. package/dist/_dev.d.ts +0 -2
  62. package/dist/_dev.d.ts.map +0 -1
  63. package/dist/_dev.js +0 -9
  64. package/dist/_dev.js.map +0 -1
  65. package/dist/_error-utils.cjs +0 -2
  66. package/dist/_error-utils.cjs.map +0 -1
  67. package/dist/_error-utils.d.ts +0 -24
  68. package/dist/_error-utils.d.ts.map +0 -1
  69. package/dist/_error-utils.js +0 -20
  70. package/dist/_error-utils.js.map +0 -1
  71. package/dist/_virtual/_rolldown/runtime.js +0 -7
  72. package/dist/async-computed.cjs +0 -2
  73. package/dist/async-computed.cjs.map +0 -1
  74. package/dist/async-computed.d.ts +0 -36
  75. package/dist/async-computed.d.ts.map +0 -1
  76. package/dist/async-computed.js +0 -62
  77. package/dist/async-computed.js.map +0 -1
  78. package/dist/computed.cjs +0 -2
  79. package/dist/computed.cjs.map +0 -1
  80. package/dist/computed.d.ts +0 -26
  81. package/dist/computed.d.ts.map +0 -1
  82. package/dist/computed.js +0 -113
  83. package/dist/computed.js.map +0 -1
  84. package/dist/devtools-hook.cjs +0 -2
  85. package/dist/devtools-hook.cjs.map +0 -1
  86. package/dist/devtools-hook.d.ts +0 -4
  87. package/dist/devtools-hook.d.ts.map +0 -1
  88. package/dist/devtools-hook.js +0 -8
  89. package/dist/devtools-hook.js.map +0 -1
  90. package/dist/devtools.d.ts +0 -50
  91. package/dist/devtools.d.ts.map +0 -1
  92. package/dist/effect.cjs +0 -2
  93. package/dist/effect.cjs.map +0 -1
  94. package/dist/effect.d.ts +0 -104
  95. package/dist/effect.d.ts.map +0 -1
  96. package/dist/effect.js +0 -174
  97. package/dist/effect.js.map +0 -1
  98. package/dist/execution-context.cjs +0 -2
  99. package/dist/execution-context.cjs.map +0 -1
  100. package/dist/execution-context.d.ts +0 -49
  101. package/dist/execution-context.d.ts.map +0 -1
  102. package/dist/execution-context.js +0 -32
  103. package/dist/execution-context.js.map +0 -1
  104. package/dist/history.d.ts +0 -56
  105. package/dist/history.d.ts.map +0 -1
  106. package/dist/reactive-base.cjs +0 -2
  107. package/dist/reactive-base.cjs.map +0 -1
  108. package/dist/reactive-base.d.ts +0 -60
  109. package/dist/reactive-base.d.ts.map +0 -1
  110. package/dist/reactive-base.js +0 -56
  111. package/dist/reactive-base.js.map +0 -1
  112. package/dist/scheduling.cjs +0 -2
  113. package/dist/scheduling.cjs.map +0 -1
  114. package/dist/scheduling.d.ts +0 -5
  115. package/dist/scheduling.d.ts.map +0 -1
  116. package/dist/scheduling.js +0 -57
  117. package/dist/scheduling.js.map +0 -1
  118. package/dist/signal.cjs +0 -2
  119. package/dist/signal.cjs.map +0 -1
  120. package/dist/signal.d.ts +0 -24
  121. package/dist/signal.d.ts.map +0 -1
  122. package/dist/signal.js +0 -54
  123. package/dist/signal.js.map +0 -1
  124. package/dist/src/devtools.cjs +0 -2
  125. package/dist/src/devtools.cjs.map +0 -1
  126. package/dist/src/devtools.js +0 -36
  127. package/dist/src/devtools.js.map +0 -1
  128. package/dist/src/history.cjs +0 -2
  129. package/dist/src/history.cjs.map +0 -1
  130. package/dist/src/history.js +0 -60
  131. package/dist/src/history.js.map +0 -1
  132. package/dist/src/ssr/index.cjs +0 -2
  133. package/dist/src/ssr/index.cjs.map +0 -1
  134. package/dist/src/ssr/index.js +0 -38
  135. package/dist/src/ssr/index.js.map +0 -1
  136. package/dist/ssr/index.d.ts +0 -56
  137. package/dist/ssr/index.d.ts.map +0 -1
  138. package/dist/store.cjs.map +0 -1
  139. package/dist/store.js.map +0 -1
  140. package/dist/subscription.cjs +0 -2
  141. package/dist/subscription.cjs.map +0 -1
  142. package/dist/subscription.d.ts +0 -22
  143. package/dist/subscription.d.ts.map +0 -1
  144. package/dist/subscription.js +0 -47
  145. package/dist/subscription.js.map +0 -1
  146. package/dist/symbols.cjs +0 -2
  147. package/dist/symbols.cjs.map +0 -1
  148. package/dist/symbols.d.ts +0 -6
  149. package/dist/symbols.d.ts.map +0 -1
  150. package/dist/symbols.js +0 -6
  151. package/dist/symbols.js.map +0 -1
  152. package/dist/tracking.cjs +0 -2
  153. package/dist/tracking.cjs.map +0 -1
  154. package/dist/tracking.d.ts +0 -51
  155. package/dist/tracking.d.ts.map +0 -1
  156. package/dist/tracking.js +0 -28
  157. package/dist/tracking.js.map +0 -1
  158. package/dist/utilities.cjs +0 -2
  159. package/dist/utilities.cjs.map +0 -1
  160. package/dist/utilities.d.ts +0 -56
  161. package/dist/utilities.d.ts.map +0 -1
  162. package/dist/utilities.js +0 -25
  163. package/dist/utilities.js.map +0 -1
package/dist/effect.js DELETED
@@ -1,174 +0,0 @@
1
- import { getDevToolsHook as e } from "./devtools-hook.js";
2
- import { collectErrors as t, rethrowWith as n, runAll as r } from "./_error-utils.js";
3
- import { RippleDisposedScopeError as i, RippleInfiniteLoopError as a, RippleInvalidCleanupError as o } from "./errors.js";
4
- import { getScopeCleanups as s, withScopeCleanups as c } from "./execution-context.js";
5
- import "./scheduling.js";
6
- import { AsyncSubscriptionImpl as l, SubscriptionImpl as u } from "./subscription.js";
7
- import { IS_COMPUTED as d, SUPPRESS_RUN_EVENT as f } from "./symbols.js";
8
- import { getTracking as p, withTracking as m } from "./tracking.js";
9
- //#region src/effect.ts
10
- var h = (e, t) => {
11
- if (t === "sync" || t === void 0) return e;
12
- let n = !1;
13
- return () => {
14
- n || (n = !0, queueMicrotask(() => {
15
- n = !1, e();
16
- }));
17
- };
18
- }, g = (i, c) => {
19
- let l = c?.scheduler ?? "sync", p = c?.name, g = c?.[f], _ = [], v = /* @__PURE__ */ new Set(), y = /* @__PURE__ */ new Map(), b = !1, x = !1, S = !1, C = () => {
20
- if (y.clear(), _.length === 0 && v.size === 0) return;
21
- let e = [..._, ...v];
22
- _.length = 0, v.clear(), r(e, "effect teardown errors");
23
- }, w = () => {
24
- if (!S) {
25
- if (b) {
26
- x = !0;
27
- return;
28
- }
29
- b = !0;
30
- try {
31
- let r = 0;
32
- do {
33
- if (++r > 100) throw new a(`infinite effect loop (> 100 iterations)${p ? ` in "${p}"` : ""}`);
34
- x = !1, C(), g || e()?.run?.({ name: p });
35
- let s;
36
- try {
37
- s = m({
38
- cleanups: _,
39
- deps: y,
40
- effect: T,
41
- kind: "effect",
42
- subscriptions: v
43
- }, i);
44
- } catch (e) {
45
- let r = [...t(v), ...t(_)];
46
- _.length = 0, v.clear(), n(e, r, "effect failure with cleanup errors");
47
- }
48
- if (s !== void 0 && typeof s != "function") throw new o(`effect() returned ${typeof s} — expected a cleanup function or void.`);
49
- typeof s == "function" && _.push(s);
50
- } while (x && !S);
51
- } finally {
52
- b = !1;
53
- }
54
- }
55
- }, T = h(w, l);
56
- w();
57
- let E = new u(() => {
58
- S || (S = !0, C(), e()?.dispose?.({
59
- kind: "effect",
60
- name: p
61
- }));
62
- });
63
- return s()?.push(() => E.dispose()), {
64
- dispose: () => E.dispose(),
65
- get disposed() {
66
- return E.disposed;
67
- },
68
- getDependencies() {
69
- return [...y.keys()].map((e) => ({
70
- kind: d in e ? "computed" : "signal",
71
- name: e.name
72
- }));
73
- },
74
- [Symbol.dispose]() {
75
- E.dispose();
76
- }
77
- };
78
- }, _ = (e, t) => {
79
- let n = null, r = null, i = null, a = t?.onError ?? ((e) => {
80
- queueMicrotask(() => {
81
- throw e;
82
- });
83
- });
84
- return new l(g(() => {
85
- n?.abort(), r?.(), r = null, n = new AbortController();
86
- let { signal: t } = n, o = y(), s;
87
- return i = s = (async () => {
88
- try {
89
- let n = await e(t, o);
90
- typeof n == "function" && (t.aborted ? n() : r = n);
91
- } catch (e) {
92
- t.aborted || a(e);
93
- } finally {
94
- o.dispose(), i === s && (i = null);
95
- }
96
- })(), () => {
97
- n?.abort(), r?.(), r = null;
98
- };
99
- }, { name: t?.name }), async () => {
100
- let e = i;
101
- e && await e;
102
- }, () => i);
103
- }, v = (e) => {
104
- let t = p();
105
- if (t?.kind === "effect") {
106
- t.cleanups.push(e);
107
- return;
108
- }
109
- let n = s();
110
- if (n !== null) {
111
- n.push(e);
112
- return;
113
- }
114
- throw new o("onCleanup() must be called from within an active effect or scope.");
115
- }, y = (e) => {
116
- let t = [], n = new AbortController(), a = !1, o = (e) => {
117
- if (a) throw new i("Cannot register cleanup on a disposed scope.");
118
- t.push(e);
119
- }, s = (e) => {
120
- if (a) throw new i("Cannot run inside a disposed scope.");
121
- return c(t, e);
122
- }, l = () => {
123
- a || (a = !0, n.abort(), r([...t].reverse(), "scope cleanup errors"), t.length = 0);
124
- }, u = {
125
- add: o,
126
- get disposalSignal() {
127
- return n.signal;
128
- },
129
- dispose: l,
130
- get disposed() {
131
- return a;
132
- },
133
- run: s,
134
- [Symbol.dispose]: l
135
- };
136
- return e && s(e), u;
137
- };
138
- function b(e, t, n) {
139
- let r = n?.equals ?? Object.is, i, a = (e, n) => {
140
- i?.(), i = void 0;
141
- let r = t(e, n);
142
- if (r !== void 0 && typeof r != "function") throw new o(`watch() callback returned ${typeof r} — expected a cleanup function or void.`);
143
- typeof r == "function" && (i = r);
144
- }, c;
145
- if (typeof e == "function") {
146
- let t, o = !0, s = g(() => {
147
- let i = e();
148
- if (o) {
149
- o = !1, t = i;
150
- return;
151
- }
152
- if (!r(t, i)) {
153
- let e = t;
154
- t = i, a(i, e), n?.once && c.dispose();
155
- }
156
- }, { name: n?.name });
157
- c = new u(() => {
158
- i?.(), i = void 0, s.dispose();
159
- }), n?.immediate && (a(t, void 0), n.once && c.dispose());
160
- } else {
161
- let t = e.peek(), o = e.subscribe(() => {
162
- let i = e.peek();
163
- r(t, i) || (a(i, t), t = i, n?.once && c.dispose());
164
- });
165
- c = new u(() => {
166
- i?.(), i = void 0, o.dispose();
167
- }), n?.immediate && (a(t, void 0), n.once && c.dispose());
168
- }
169
- return s()?.push(() => c.dispose()), c;
170
- }
171
- //#endregion
172
- export { g as effect, _ as effectAsync, v as onCleanup, y as scope, b as watch };
173
-
174
- //# sourceMappingURL=effect.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"effect.js","names":[],"sources":["../src/effect.ts"],"sourcesContent":["import type { ReactiveBase } from './reactive-base';\nimport type {\n AsyncEffectCallback,\n AsyncSubscription,\n CleanupFn,\n DepInfo,\n EffectAsyncOptions,\n EffectCallback,\n EffectHandle,\n EffectOptions,\n EqualityFn,\n Readable,\n Scope,\n Subscriber,\n Subscription,\n WatchOptions,\n} from './types';\n\nimport { collectErrors, rethrowWith, runAll } from './_error-utils';\nimport { getDevToolsHook } from './devtools-hook';\nimport { RippleDisposedScopeError, RippleInfiniteLoopError, RippleInvalidCleanupError } from './errors';\nimport { getScopeCleanups, withScopeCleanups } from './execution-context';\nimport { DEFAULT_MAX_ITERATIONS } from './scheduling';\nimport { AsyncSubscriptionImpl, SubscriptionImpl } from './subscription';\nimport { IS_COMPUTED, SUPPRESS_RUN_EVENT } from './symbols';\nimport { getTracking, withTracking } from './tracking';\n\n/**\n * Wraps a core `run` function with a microtask-based scheduler that coalesces rapid re-runs.\n * The `subscriber` returned here is what gets registered in signal subscriber sets —\n * so notifications call the deferred wrapper, not `run` directly.\n *\n * The scheduler identity is stable for the lifetime of the effect.\n * Never replace `subscriber` with a new function after creation — doing so would break\n * the removeEffectSub calls that rely on reference identity.\n */\nconst withScheduler = (run: Subscriber, scheduler: EffectOptions['scheduler']): Subscriber => {\n if (scheduler === 'sync' || scheduler === undefined) return run;\n\n // 'microtask'\n let scheduled = false;\n\n return (): void => {\n if (scheduled) return;\n\n scheduled = true;\n queueMicrotask(() => {\n scheduled = false;\n run();\n });\n };\n};\n\n/**\n * Creates a reactive side-effect.\n * Runs immediately, re-runs whenever tracked dependencies change.\n * The callback may return a cleanup function that runs before the next re-run and on dispose.\n *\n * @example\n * ```ts\n * const stop = effect(() => {\n * document.title = count.value.toString();\n * return () => { document.title = ''; }; // optional cleanup\n * });\n *\n * stop.dispose(); // or: using stop = effect(...)\n * console.log(stop.getDependencies()); // reactive graph introspection\n * ```\n */\nexport const effect = (fn: EffectCallback, options?: EffectOptions): EffectHandle => {\n const scheduler = options?.scheduler ?? 'sync';\n const effectName = options?.name;\n // Internal-only escape hatch — see SUPPRESS_RUN_EVENT's JSDoc in symbols.ts.\n // No public option can ever reach this: EffectOptions doesn't declare the key, and\n // the symbol is never exported from index.ts.\n const suppressRunEvent = (options as Partial<Record<typeof SUPPRESS_RUN_EVENT, boolean>> | undefined)?.[\n SUPPRESS_RUN_EVENT\n ];\n\n const runCleanups: CleanupFn[] = [];\n const subscriptions = new Set<CleanupFn>();\n const currentDeps = new Map<ReactiveBase<unknown>, number>();\n let isRunning = false;\n let isDirty = false;\n let isDisposed = false;\n\n const teardown = (): void => {\n currentDeps.clear();\n\n if (runCleanups.length === 0 && subscriptions.size === 0) return;\n\n const toRun = [...runCleanups, ...subscriptions];\n\n runCleanups.length = 0;\n subscriptions.clear();\n\n runAll(toRun, 'effect teardown errors');\n };\n\n // The inner do-while handles self-cascade: when the effect body writes to a signal it reads,\n // the recursive flush sets isDirty via the isRunning guard.\n const run: Subscriber = (): void => {\n if (isDisposed) return;\n\n if (isRunning) {\n isDirty = true;\n\n return;\n }\n\n isRunning = true;\n\n try {\n let iterations = 0;\n\n do {\n if (++iterations > DEFAULT_MAX_ITERATIONS) {\n const label = effectName ? ` in \"${effectName}\"` : '';\n\n throw new RippleInfiniteLoopError(`infinite effect loop (> ${DEFAULT_MAX_ITERATIONS} iterations)${label}`);\n }\n\n isDirty = false;\n teardown();\n\n if (!suppressRunEvent) getDevToolsHook()?.run?.({ name: effectName });\n\n let returnedCleanup: CleanupFn | void = undefined;\n\n try {\n returnedCleanup = withTracking(\n { cleanups: runCleanups, deps: currentDeps, effect: subscriber, kind: 'effect', subscriptions },\n fn,\n );\n } catch (error) {\n const cleanupErrors = [...collectErrors(subscriptions), ...collectErrors(runCleanups)];\n\n runCleanups.length = 0;\n subscriptions.clear();\n rethrowWith(error, cleanupErrors, 'effect failure with cleanup errors');\n }\n\n if (returnedCleanup !== undefined && typeof returnedCleanup !== 'function') {\n throw new RippleInvalidCleanupError(\n `effect() returned ${typeof returnedCleanup} — expected a cleanup function or void.`,\n );\n }\n\n if (typeof returnedCleanup === 'function') runCleanups.push(returnedCleanup);\n } while (isDirty && !isDisposed);\n } finally {\n isRunning = false;\n }\n };\n\n // subscriber is what gets registered in signal subscriber Sets.\n // For 'sync' it is the same as run; for deferred schedulers it's the debouncing wrapper.\n const subscriber = withScheduler(run, scheduler);\n\n // Always run synchronously on creation to establish initial tracking.\n run();\n\n const sub = new SubscriptionImpl(() => {\n if (isDisposed) return;\n\n isDisposed = true;\n teardown();\n getDevToolsHook()?.dispose?.({ kind: 'effect', name: effectName });\n });\n\n // Auto-register disposal into the enclosing scope (if any).\n // Uses the separate scope stack — orthogonal to the effect/computed tracking context.\n getScopeCleanups()?.push(() => sub.dispose());\n\n const handle: EffectHandle = {\n dispose: () => sub.dispose(),\n get disposed() {\n return sub.disposed;\n },\n getDependencies(): ReadonlyArray<DepInfo> {\n return [...currentDeps.keys()].map((src) => ({\n kind: IS_COMPUTED in (src as object) ? 'computed' : 'signal',\n name: src.name,\n }));\n },\n [Symbol.dispose]() {\n sub.dispose();\n },\n };\n\n return handle;\n};\n\n/**\n * Like `effect()`, but the callback is async and receives an AbortSignal that fires when the\n * effect re-runs or is disposed. Read reactive dependencies synchronously before the first\n * `await` to register them as tracked.\n *\n * Returns an {@link AsyncSubscription} — call `await stop[Symbol.asyncDispose]()` to await\n * full teardown, or `stop.run()` to await just the current in-flight run.\n *\n * @example\n * ```ts\n * const userId = signal('u1');\n * const stop = effectAsync(async (signal) => {\n * const id = userId.value; // sync dep — tracked\n * const data = await fetchUser(id, { signal }); // aborted automatically if id changes\n * renderUser(data);\n * });\n *\n * await stop[Symbol.asyncDispose]();\n * ```\n */\nexport const effectAsync = (fn: AsyncEffectCallback, options?: EffectAsyncOptions): AsyncSubscription => {\n let controller: AbortController | null = null;\n let asyncCleanup: CleanupFn | null = null;\n let currentRunPromise: Promise<void> | null = null;\n\n const onError =\n options?.onError ??\n ((err: unknown) => {\n queueMicrotask(() => {\n throw err;\n });\n });\n\n const syncStop = effect(\n () => {\n controller?.abort();\n asyncCleanup?.();\n asyncCleanup = null;\n\n controller = new AbortController();\n\n const { signal } = controller;\n const runOwner = scope(); // per-run owner scope for async body resources\n\n let theRun!: Promise<void>;\n\n currentRunPromise = theRun = (async () => {\n try {\n const returned = await fn(signal, runOwner);\n\n if (typeof returned === 'function') {\n if (signal.aborted) {\n // Aborted while async fn was running — run cleanup immediately.\n returned();\n } else {\n asyncCleanup = returned;\n }\n }\n } catch (err) {\n if (!signal.aborted) onError(err);\n } finally {\n runOwner.dispose();\n\n if (currentRunPromise === theRun) currentRunPromise = null;\n }\n })();\n\n return () => {\n controller?.abort();\n asyncCleanup?.();\n asyncCleanup = null;\n };\n },\n { name: options?.name },\n );\n\n return new AsyncSubscriptionImpl(\n syncStop,\n async () => {\n const runningPromise = currentRunPromise;\n\n if (runningPromise) await runningPromise;\n },\n () => currentRunPromise,\n );\n};\n\nexport const onCleanup = (fn: CleanupFn): void => {\n const ctx = getTracking();\n\n if (ctx?.kind === 'effect') {\n ctx.cleanups.push(fn);\n\n return;\n }\n\n const scopeCleanups = getScopeCleanups();\n\n if (scopeCleanups !== null) {\n scopeCleanups.push(fn);\n\n return;\n }\n\n throw new RippleInvalidCleanupError('onCleanup() must be called from within an active effect or scope.');\n};\n\n/**\n * Creates a lifecycle scope that collects `onCleanup()` registrations and runs\n * them in reverse order when `dispose()` is called.\n *\n * The optional `setup` callback is run immediately inside the scope so that\n * `onCleanup()` calls in setup are captured without requiring a separate\n * `scope.run(setup)` call.\n *\n * Use `scope.add(fn)` to explicitly register a cleanup into this scope from\n * anywhere — including from inside an effect body where `onCleanup()` would otherwise\n * go to the effect's own cleanup queue.\n *\n * @example\n * ```ts\n * const s = scope(() => {\n * onCleanup(() => expensiveCleanup()); // captured by scope\n * });\n *\n * const stop = effect(() => {\n * void count.value;\n * s.add(() => doWork()); // explicit: goes to scope, not effect\n * onCleanup(() => cheapCleanup()); // goes to effect\n * });\n *\n * // later:\n * s.dispose(); // or: using s = scope(...)\n * ```\n */\nexport const scope = (setup?: () => void): Scope => {\n const cleanups: CleanupFn[] = [];\n const ac = new AbortController();\n let disposed = false;\n\n const scopeOnCleanup = (fn: CleanupFn): void => {\n if (disposed) throw new RippleDisposedScopeError('Cannot register cleanup on a disposed scope.');\n\n cleanups.push(fn);\n };\n\n const run = <T>(fn: () => T): T => {\n if (disposed) throw new RippleDisposedScopeError('Cannot run inside a disposed scope.');\n\n return withScopeCleanups(cleanups, fn);\n };\n\n const dispose = (): void => {\n if (disposed) return;\n\n disposed = true;\n ac.abort();\n runAll([...cleanups].reverse(), 'scope cleanup errors');\n cleanups.length = 0;\n };\n\n const api: Scope = {\n add: scopeOnCleanup,\n get disposalSignal() {\n return ac.signal;\n },\n dispose,\n get disposed() {\n return disposed;\n },\n run,\n [Symbol.dispose]: dispose,\n };\n\n if (setup) run(setup);\n\n return api;\n};\n\n// ── watch() ───────────────────────────────────────────────────────────────────\n\n/**\n * Observes a reactive source and calls `callback` whenever its value changes.\n * Does NOT invoke `callback` on creation (unless `immediate: true` is passed).\n *\n * `source` may be a single `Readable<T>` (signal, computed, or store lens), or a\n * function that reads multiple reactive sources — the function form tracks every\n * dependency read inside it, like `computed()`, without needing an intermediate\n * `computed()` node.\n *\n * When called without `immediate`, `prev` is always `T` — the previous value.\n * When `immediate: true` is passed, `prev` is `T | undefined` on the first call.\n *\n * @example\n * ```ts\n * const stop = watch(count, (next, prev) => {\n * console.log(`count changed: ${prev} → ${next}`);\n * });\n *\n * stop.dispose();\n * ```\n *\n * @example\n * ```ts\n * // Function form — tracks every signal read inside, re-runs when any changes.\n * const stopSum = watch(\n * () => a.value + b.value,\n * (sum, prevSum) => console.log(`sum: ${prevSum} → ${sum}`),\n * );\n *\n * stopSum.dispose();\n * ```\n */\nexport function watch<T>(\n source: Readable<T>,\n callback: (value: T, prev: T | undefined) => CleanupFn | void,\n options?: WatchOptions<T>,\n): Subscription;\nexport function watch<T>(\n source: () => T,\n callback: (value: T, prev: T | undefined) => CleanupFn | void,\n options?: WatchOptions<T>,\n): Subscription;\nexport function watch<T>(\n source: Readable<T> | (() => T),\n callback: (value: T, prev: T | undefined) => CleanupFn | void,\n options?: WatchOptions<T>,\n): Subscription {\n const equals: EqualityFn<T> = options?.equals ?? Object.is;\n let pendingCleanup: CleanupFn | undefined;\n const invokeCallback = (next: T, p: T | undefined): void => {\n pendingCleanup?.();\n pendingCleanup = undefined;\n\n const returned = callback(next, p);\n\n if (returned !== undefined && typeof returned !== 'function') {\n throw new RippleInvalidCleanupError(\n `watch() callback returned ${typeof returned} — expected a cleanup function or void.`,\n );\n }\n\n if (typeof returned === 'function') pendingCleanup = returned;\n };\n\n // Declared before the subscriber/effect closures so both they and the immediate\n // path can call watchSub.dispose() when once:true. Subscribers/effects always\n // (re-)run after watchSub is assigned, since it's assigned synchronously right after.\n\n let watchSub!: SubscriptionImpl;\n\n if (typeof source === 'function') {\n // Function form — track every dependency read inside `source` via a real effect,\n // mirroring computed()'s dependency collection. `first` suppresses the callback\n // on the initial (tracking-establishing) run — handled explicitly below (after\n // watchSub exists) instead of inside this synchronous first run, since effect()\n // runs its body immediately and watchSub isn't assigned until after it returns.\n let prev!: T;\n let first = true;\n\n const stopEffect = effect(\n () => {\n const next = source();\n\n if (first) {\n first = false;\n prev = next;\n\n return;\n }\n\n if (!equals(prev, next)) {\n const p = prev;\n\n prev = next;\n invokeCallback(next, p);\n\n if (options?.once) watchSub.dispose();\n }\n },\n { name: options?.name },\n );\n\n watchSub = new SubscriptionImpl(() => {\n pendingCleanup?.();\n pendingCleanup = undefined;\n stopEffect.dispose();\n });\n\n if (options?.immediate) {\n invokeCallback(prev, undefined);\n\n if (options.once) watchSub.dispose();\n }\n } else {\n let prev: T = source.peek();\n\n const innerSub = source.subscribe(() => {\n const next = source.peek();\n\n if (!equals(prev, next)) {\n invokeCallback(next, prev);\n prev = next;\n\n if (options?.once) watchSub.dispose();\n }\n });\n\n watchSub = new SubscriptionImpl(() => {\n pendingCleanup?.();\n pendingCleanup = undefined;\n innerSub.dispose();\n });\n\n if (options?.immediate) {\n invokeCallback(prev, undefined);\n\n if (options.once) watchSub.dispose();\n }\n }\n\n // Auto-register disposal into the enclosing scope (if any) — matches effect() behaviour.\n getScopeCleanups()?.push(() => watchSub.dispose());\n\n return watchSub;\n}\n"],"mappings":";;;;;;;;;AAoCA,IAAM,KAAiB,GAAiB,MAAsD;CAC5F,IAAI,MAAc,UAAU,MAAc,KAAA,GAAW,OAAO;CAG5D,IAAI,IAAY;CAEhB,aAAmB;EACb,MAEJ,IAAY,IACZ,qBAAqB;GAEnB,AADA,IAAY,IACZ,EAAI;EACN,CAAC;CACH;AACF,GAkBa,KAAU,GAAoB,MAA0C;CACnF,IAAM,IAAY,GAAS,aAAa,QAClC,IAAa,GAAS,MAItB,IAAoB,IACxB,IAGI,IAA2B,CAAC,GAC5B,oBAAgB,IAAI,IAAe,GACnC,oBAAc,IAAI,IAAmC,GACvD,IAAY,IACZ,IAAU,IACV,IAAa,IAEX,UAAuB;EAG3B,IAFA,EAAY,MAAM,GAEd,EAAY,WAAW,KAAK,EAAc,SAAS,GAAG;EAE1D,IAAM,IAAQ,CAAC,GAAG,GAAa,GAAG,CAAa;EAK/C,AAHA,EAAY,SAAS,GACrB,EAAc,MAAM,GAEpB,EAAO,GAAO,wBAAwB;CACxC,GAIM,UAA8B;EAC9B,QAEJ;OAAI,GAAW;IACb,IAAU;IAEV;GACF;GAEA,IAAY;GAEZ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vC,OAAO;EACL,IAAI,IAAU,EAAO,KAAK,GAEpB,IAAW,EAAO,gBAAgB;GACtC,IAAM,IAAO,EAAO,KAAK;GAEzB,AAAK,EAAO,GAAM,CAAI,MACpB,EAAe,GAAM,CAAI,GACzB,IAAO,GAEH,GAAS,QAAM,EAAS,QAAQ;EAExC,CAAC;EAQD,AANA,IAAW,IAAI,QAAuB;GAGpC,AAFA,IAAiB,GACjB,IAAiB,KAAA,GACjB,EAAS,QAAQ;EACnB,CAAC,GAEG,GAAS,cACX,EAAe,GAAM,KAAA,CAAS,GAE1B,EAAQ,QAAM,EAAS,QAAQ;CAEvC;CAKA,OAFA,EAAiB,CAAC,EAAE,WAAW,EAAS,QAAQ,CAAC,GAE1C;AACT"}
@@ -1,2 +0,0 @@
1
- var e=()=>({activeDirty:`a`,batchDepth:0,dirtyWithEffectSubsA:new Set,dirtyWithEffectSubsB:new Set,pendingSubscribers:new Set}),t={scheduling:e(),scopeCleanups:null,tracking:null},n=null,r=()=>n===null?t:n.get(),i=(e,i)=>{let a={...r(),...e};if(n!==null)return n.run(a,i);let o=t;t=a;try{return i()}finally{t=o}},a=()=>r().scheduling,o=()=>n!==null,s=()=>r().scopeCleanups,c=(e,t)=>i({scopeCleanups:e},t),l=e=>{let t=n;return n=e,t};exports._installContextHook=l,exports.createSchedulingState=e,exports.getExecutionContext=r,exports.getSchedulingState=a,exports.getScopeCleanups=s,exports.hasContextHook=o,exports.runInContext=i,exports.withScopeCleanups=c;
2
- //# sourceMappingURL=execution-context.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execution-context.cjs","names":[],"sources":["../src/execution-context.ts"],"sourcesContent":["// ── ExecutionContext ──────────────────────────────────────────────────────────\n//\n// Owns the one piece of process-wide (or, once an SSR hook is installed,\n// per-request) mutable state every reactive primitive reads through: the active\n// scheduling bucket, the active scope's cleanup array, and the active tracking\n// context. Split out of tracking.ts so this file's only job is \"where does the\n// current execution context live and how do you swap it\" — tracking.ts owns\n// what a TrackingCtx *means* (dep collection), this file owns how one gets\n// installed for the duration of a call.\n//\n// TrackingCtx is imported type-only here (erased at compile time) so tracking.ts\n// can depend on this file's runtime exports (getExecutionContext, runInContext)\n// without creating an actual circular import — only one direction is real at\n// runtime: tracking.ts -> execution-context.ts.\n\nimport type { ComputedBase } from './reactive-base';\nimport type { TrackingCtx } from './tracking';\nimport type { CleanupFn, Subscriber } from './types';\n\n// ── Scheduling state ────────────────────────────────────────────────────────\n//\n// batchDepth, pendingSubscribers, and the dirty-computed sets live here (rather\n// than as scheduling.ts module-level variables) so the /ripple/ssr sub-path can\n// isolate the flush queue per request via the same context hook that isolates\n// tracking — closing the gap where concurrent SSR requests would otherwise share\n// one flush queue. Outside SSR (no hook installed), this is a single\n// module-level singleton with identical behavior and cost to a plain global.\n\nexport type SchedulingState = {\n activeDirty: 'a' | 'b';\n batchDepth: number;\n readonly dirtyWithEffectSubsA: Set<ComputedBase<unknown>>;\n readonly dirtyWithEffectSubsB: Set<ComputedBase<unknown>>;\n readonly pendingSubscribers: Set<Subscriber>;\n};\n\nexport const createSchedulingState = (): SchedulingState => ({\n activeDirty: 'a',\n batchDepth: 0,\n dirtyWithEffectSubsA: new Set(),\n dirtyWithEffectSubsB: new Set(),\n pendingSubscribers: new Set(),\n});\n\n// ── The context itself ────────────────────────────────────────────────────────\n\nexport type ExecutionContext = {\n readonly scheduling: SchedulingState;\n readonly scopeCleanups: CleanupFn[] | null;\n readonly tracking: TrackingCtx | null;\n};\n\nexport type ContextHook = {\n get(): ExecutionContext;\n run<T>(ctx: ExecutionContext, fn: () => T): T;\n};\n\nlet _ctx: ExecutionContext = { scheduling: createSchedulingState(), scopeCleanups: null, tracking: null };\nlet _hook: ContextHook | null = null;\n\n/** Returns the active context — the installed SSR hook's, or the module-level singleton. */\nexport const getExecutionContext = (): ExecutionContext => (_hook !== null ? _hook.get() : _ctx);\n\n/**\n * Runs `fn` with `patch` merged onto the active context, restoring the previous\n * context afterwards. Delegates to the SSR hook when one is installed (it owns its\n * own restore semantics, e.g. via AsyncLocalStorage); otherwise swaps the module-level\n * singleton directly. Every \"run with a modified context\" helper (withTracking,\n * withScopeCleanups) is a one-line call to this — there is exactly one context\n * swap/restore implementation.\n *\n * Takes a `Partial<ExecutionContext>` (merged internally), not a full replacement\n * context — a caller can only ever override the field(s) it names, so it's\n * impossible to accidentally drop `scheduling` or `scopeCleanups` by forgetting to\n * spread the current context first.\n */\nexport const runInContext = <T>(patch: Partial<ExecutionContext>, fn: () => T): T => {\n const ctx = { ...getExecutionContext(), ...patch };\n\n if (_hook !== null) return _hook.run(ctx, fn);\n\n const prev = _ctx;\n\n _ctx = ctx;\n\n try {\n return fn();\n } finally {\n _ctx = prev;\n }\n};\n\n/** Returns the scheduling-state bucket for the active execution context. */\nexport const getSchedulingState = (): SchedulingState => getExecutionContext().scheduling;\n\n/** `true` once an SSR context hook is installed — scheduling state is then request-isolated. */\nexport const hasContextHook = (): boolean => _hook !== null;\n\n// ── Scope cleanup ─────────────────────────────────────────────────────────────\n\n/** Returns the cleanup array of the innermost active scope, or `null` if not inside a scope. */\nexport const getScopeCleanups = (): CleanupFn[] | null => getExecutionContext().scopeCleanups;\n\n/**\n * Pushes `cleanups` as the active scope cleanup array for the duration of `fn`.\n * Any `onCleanup()` calls inside `fn` register into these cleanups; effects and\n * computed values created inside `fn` auto-register their disposal too.\n */\nexport const withScopeCleanups = <T>(cleanups: CleanupFn[], fn: () => T): T =>\n runInContext({ scopeCleanups: cleanups }, fn);\n\n// ── Context hook (for SSR) ────────────────────────────────────────────────────\n\n/**\n * @internal Used only by `/ripple/ssr`.\n * Installs a context hook that overrides both tracking and scope-cleanup access.\n * Returns the previous hook so callers can restore it.\n */\nexport const _installContextHook = (hook: ContextHook | null): ContextHook | null => {\n const prev = _hook;\n\n _hook = hook;\n\n return prev;\n};\n"],"mappings":"AAoCA,IAAa,OAAgD,CAC3D,YAAa,IACb,WAAY,EACZ,qBAAsB,IAAI,IAC1B,qBAAsB,IAAI,IAC1B,mBAAoB,IAAI,GAC1B,GAeI,EAAyB,CAAE,WAAY,EAAsB,EAAG,cAAe,KAAM,SAAU,IAAK,EACpG,EAA4B,KAGnB,MAA+C,IAAU,KAAqB,EAAd,EAAM,IAAI,EAe1E,GAAmB,EAAkC,IAAmB,CACnF,IAAM,EAAM,CAAE,GAAG,EAAoB,EAAG,GAAG,CAAM,EAEjD,GAAI,IAAU,KAAM,OAAO,EAAM,IAAI,EAAK,CAAE,EAE5C,IAAM,EAAO,EAEb,EAAO,EAEP,GAAI,CACF,OAAO,EAAG,CACZ,QAAU,CACR,EAAO,CACT,CACF,EAGa,MAA4C,EAAoB,CAAC,CAAC,WAGlE,MAAgC,IAAU,KAK1C,MAA6C,EAAoB,CAAC,CAAC,cAOnE,GAAwB,EAAuB,IAC1D,EAAa,CAAE,cAAe,CAAS,EAAG,CAAE,EASjC,EAAuB,GAAiD,CACnF,IAAM,EAAO,EAIb,MAFA,GAAQ,EAED,CACT"}
@@ -1,49 +0,0 @@
1
- import type { ComputedBase } from './reactive-base';
2
- import type { TrackingCtx } from './tracking';
3
- import type { CleanupFn, Subscriber } from './types';
4
- export type SchedulingState = {
5
- activeDirty: 'a' | 'b';
6
- batchDepth: number;
7
- readonly dirtyWithEffectSubsA: Set<ComputedBase<unknown>>;
8
- readonly dirtyWithEffectSubsB: Set<ComputedBase<unknown>>;
9
- readonly pendingSubscribers: Set<Subscriber>;
10
- };
11
- export declare const createSchedulingState: () => SchedulingState;
12
- export type ExecutionContext = {
13
- readonly scheduling: SchedulingState;
14
- readonly scopeCleanups: CleanupFn[] | null;
15
- readonly tracking: TrackingCtx | null;
16
- };
17
- export type ContextHook = {
18
- get(): ExecutionContext;
19
- run<T>(ctx: ExecutionContext, fn: () => T): T;
20
- };
21
- /** Returns the active context — the installed SSR hook's, or the module-level singleton. */
22
- export declare const getExecutionContext: () => ExecutionContext;
23
- /**
24
- * Runs `fn` with `patch` merged onto the active context, restoring the previous
25
- * context afterwards. Delegates to the SSR hook when one is installed (it owns its
26
- * own restore semantics, e.g. via AsyncLocalStorage); otherwise swaps the module-level
27
- * singleton directly. Every "run with a modified context" helper (withTracking,
28
- * withScopeCleanups) is a one-line call to this — there is exactly one context
29
- * swap/restore implementation.
30
- *
31
- * Takes a `Partial<ExecutionContext>` (merged internally), not a full replacement
32
- * context — a caller can only ever override the field(s) it names, so it's
33
- * impossible to accidentally drop `scheduling` or `scopeCleanups` by forgetting to
34
- * spread the current context first.
35
- */
36
- export declare const runInContext: <T>(patch: Partial<ExecutionContext>, fn: () => T) => T;
37
- /** Returns the scheduling-state bucket for the active execution context. */
38
- export declare const getSchedulingState: () => SchedulingState;
39
- /** `true` once an SSR context hook is installed — scheduling state is then request-isolated. */
40
- export declare const hasContextHook: () => boolean;
41
- /** Returns the cleanup array of the innermost active scope, or `null` if not inside a scope. */
42
- export declare const getScopeCleanups: () => CleanupFn[] | null;
43
- /**
44
- * Pushes `cleanups` as the active scope cleanup array for the duration of `fn`.
45
- * Any `onCleanup()` calls inside `fn` register into these cleanups; effects and
46
- * computed values created inside `fn` auto-register their disposal too.
47
- */
48
- export declare const withScopeCleanups: <T>(cleanups: CleanupFn[], fn: () => T) => T;
49
- //# sourceMappingURL=execution-context.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execution-context.d.ts","sourceRoot":"","sources":["../src/execution-context.ts"],"names":[],"mappings":"AAeA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AACpD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAWrD,MAAM,MAAM,eAAe,GAAG;IAC5B,WAAW,EAAE,GAAG,GAAG,GAAG,CAAC;IACvB,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,oBAAoB,EAAE,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,QAAQ,CAAC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WithEffectSubsB: /* @__PURE__ */ new Set(),
7
- pendingSubscribers: /* @__PURE__ */ new Set()
8
- }), t = {
9
- scheduling: e(),
10
- scopeCleanups: null,
11
- tracking: null
12
- }, n = null, r = () => n === null ? t : n.get(), i = (e, i) => {
13
- let a = {
14
- ...r(),
15
- ...e
16
- };
17
- if (n !== null) return n.run(a, i);
18
- let o = t;
19
- t = a;
20
- try {
21
- return i();
22
- } finally {
23
- t = o;
24
- }
25
- }, a = () => r().scheduling, o = () => n !== null, s = () => r().scopeCleanups, c = (e, t) => i({ scopeCleanups: e }, t), l = (e) => {
26
- let t = n;
27
- return n = e, t;
28
- };
29
- //#endregion
30
- export { l as _installContextHook, e as createSchedulingState, r as getExecutionContext, a as getSchedulingState, s as getScopeCleanups, o as hasContextHook, i as runInContext, c as withScopeCleanups };
31
-
32
- //# sourceMappingURL=execution-context.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"execution-context.js","names":[],"sources":["../src/execution-context.ts"],"sourcesContent":["// ── ExecutionContext ──────────────────────────────────────────────────────────\n//\n// Owns the one piece of process-wide (or, once an SSR hook is installed,\n// per-request) mutable state every reactive primitive reads through: the active\n// scheduling bucket, the active scope's cleanup array, and the active tracking\n// context. Split out of tracking.ts so this file's only job is \"where does the\n// current execution context live and how do you swap it\" — tracking.ts owns\n// what a TrackingCtx *means* (dep collection), this file owns how one gets\n// installed for the duration of a call.\n//\n// TrackingCtx is imported type-only here (erased at compile time) so tracking.ts\n// can depend on this file's runtime exports (getExecutionContext, runInContext)\n// without creating an actual circular import — only one direction is real at\n// runtime: tracking.ts -> execution-context.ts.\n\nimport type { ComputedBase } from './reactive-base';\nimport type { TrackingCtx } from './tracking';\nimport type { CleanupFn, Subscriber } from './types';\n\n// ── Scheduling state ────────────────────────────────────────────────────────\n//\n// batchDepth, pendingSubscribers, and the dirty-computed sets live here (rather\n// than as scheduling.ts module-level variables) so the /ripple/ssr sub-path can\n// isolate the flush queue per request via the same context hook that isolates\n// tracking — closing the gap where concurrent SSR requests would otherwise share\n// one flush queue. Outside SSR (no hook installed), this is a single\n// module-level singleton with identical behavior and cost to a plain global.\n\nexport type SchedulingState = {\n activeDirty: 'a' | 'b';\n batchDepth: number;\n readonly dirtyWithEffectSubsA: Set<ComputedBase<unknown>>;\n readonly dirtyWithEffectSubsB: Set<ComputedBase<unknown>>;\n readonly pendingSubscribers: Set<Subscriber>;\n};\n\nexport const createSchedulingState = (): SchedulingState => ({\n activeDirty: 'a',\n batchDepth: 0,\n dirtyWithEffectSubsA: new Set(),\n dirtyWithEffectSubsB: new Set(),\n pendingSubscribers: new Set(),\n});\n\n// ── The context itself ────────────────────────────────────────────────────────\n\nexport type ExecutionContext = {\n readonly scheduling: SchedulingState;\n readonly scopeCleanups: CleanupFn[] | null;\n readonly tracking: TrackingCtx | null;\n};\n\nexport type ContextHook = {\n get(): ExecutionContext;\n run<T>(ctx: ExecutionContext, fn: () => T): T;\n};\n\nlet _ctx: ExecutionContext = { scheduling: createSchedulingState(), scopeCleanups: null, tracking: null };\nlet _hook: ContextHook | null = null;\n\n/** Returns the active context — the installed SSR hook's, or the module-level singleton. */\nexport const getExecutionContext = (): ExecutionContext => (_hook !== null ? _hook.get() : _ctx);\n\n/**\n * Runs `fn` with `patch` merged onto the active context, restoring the previous\n * context afterwards. Delegates to the SSR hook when one is installed (it owns its\n * own restore semantics, e.g. via AsyncLocalStorage); otherwise swaps the module-level\n * singleton directly. Every \"run with a modified context\" helper (withTracking,\n * withScopeCleanups) is a one-line call to this — there is exactly one context\n * swap/restore implementation.\n *\n * Takes a `Partial<ExecutionContext>` (merged internally), not a full replacement\n * context — a caller can only ever override the field(s) it names, so it's\n * impossible to accidentally drop `scheduling` or `scopeCleanups` by forgetting to\n * spread the current context first.\n */\nexport const runInContext = <T>(patch: Partial<ExecutionContext>, fn: () => T): T => {\n const ctx = { ...getExecutionContext(), ...patch };\n\n if (_hook !== null) return _hook.run(ctx, fn);\n\n const prev = _ctx;\n\n _ctx = ctx;\n\n try {\n return fn();\n } finally {\n _ctx = prev;\n }\n};\n\n/** Returns the scheduling-state bucket for the active execution context. */\nexport const getSchedulingState = (): SchedulingState => getExecutionContext().scheduling;\n\n/** `true` once an SSR context hook is installed — scheduling state is then request-isolated. */\nexport const hasContextHook = (): boolean => _hook !== null;\n\n// ── Scope cleanup ─────────────────────────────────────────────────────────────\n\n/** Returns the cleanup array of the innermost active scope, or `null` if not inside a scope. */\nexport const getScopeCleanups = (): CleanupFn[] | null => getExecutionContext().scopeCleanups;\n\n/**\n * Pushes `cleanups` as the active scope cleanup array for the duration of `fn`.\n * Any `onCleanup()` calls inside `fn` register into these cleanups; effects and\n * computed values created inside `fn` auto-register their disposal too.\n */\nexport const withScopeCleanups = <T>(cleanups: CleanupFn[], fn: () => T): T =>\n runInContext({ scopeCleanups: cleanups }, fn);\n\n// ── Context hook (for SSR) ────────────────────────────────────────────────────\n\n/**\n * @internal Used only by `/ripple/ssr`.\n * Installs a context hook that overrides both tracking and scope-cleanup access.\n * Returns the previous hook so callers can restore it.\n */\nexport const _installContextHook = (hook: ContextHook | null): ContextHook | null => {\n const prev = _hook;\n\n _hook = hook;\n\n return prev;\n};\n"],"mappings":";AAoCA,IAAa,WAAgD;CAC3D,aAAa;CACb,YAAY;CACZ,sCAAsB,IAAI,IAAI;CAC9B,sCAAsB,IAAI,IAAI;CAC9B,oCAAoB,IAAI,IAAI;AAC9B,IAeI,IAAyB;CAAE,YAAY,EAAsB;CAAG,eAAe;CAAM,UAAU;AAAK,GACpG,IAA4B,MAGnB,UAA+C,MAAU,OAAqB,IAAd,EAAM,IAAI,GAe1E,KAAmB,GAAkC,MAAmB;CACnF,IAAM,IAAM;EAAE,GAAG,EAAoB;EAAG,GAAG;CAAM;CAEjD,IAAI,MAAU,MAAM,OAAO,EAAM,IAAI,GAAK,CAAE;CAE5C,IAAM,IAAO;CAEb,IAAO;CAEP,IAAI;EACF,OAAO,EAAG;CACZ,UAAU;EACR,IAAO;CACT;AACF,GAGa,UAA4C,EAAoB,CAAC,CAAC,YAGlE,UAAgC,MAAU,MAK1C,UAA6C,EAAoB,CAAC,CAAC,eAOnE,KAAwB,GAAuB,MAC1D,EAAa,EAAE,eAAe,EAAS,GAAG,CAAE,GASjC,KAAuB,MAAiD;CACnF,IAAM,IAAO;CAIb,OAFA,IAAQ,GAED;AACT"}
package/dist/history.d.ts DELETED
@@ -1,56 +0,0 @@
1
- /**
2
- * @vielzeug/ripple — snapshot-based store undo/redo.
3
- *
4
- * Import from the dedicated sub-path so it is tree-shaken from bundles that
5
- * never use it:
6
- * ```ts
7
- * import { storeWithHistory } from '@vielzeug/ripple/history';
8
- * ```
9
- *
10
- * This is a thin, synchronous, single-store adapter — for async commands,
11
- * multi-step undo grouping, or history over anything other than a `Store<T>`,
12
- * use `@vielzeug/ledger` instead.
13
- */
14
- import type { Store, StoreWithHistory } from './types';
15
- export type { HistoryEntry, StoreWithHistory } from './types';
16
- /**
17
- * Wraps a store (or creates one from an initial value) with explicit snapshot history
18
- * for undo/redo / time-travel.
19
- *
20
- * **Ownership:** if called with an initial value, the adapter creates and owns
21
- * the underlying store — `dispose()` will also dispose it. If called with an
22
- * existing `Store<T>`, the adapter does NOT own it — `dispose()` leaves the
23
- * store alive.
24
- *
25
- * History is **explicit** — call `push()` or `pushNamed()` after mutations you want
26
- * to be undoable. This gives you full control over snapshot granularity: you can
27
- * batch multiple mutations before pushing, or avoid pushing for programmatic
28
- * operations like server sync or reset-and-reload.
29
- *
30
- * This is a pure external adapter — it does not access any store internals.
31
- *
32
- * @example
33
- * ```ts
34
- * const h = storeWithHistory({ count: 0 }, { maxHistory: 10 });
35
- *
36
- * h.patch({ count: 1 });
37
- * h.push(); // save checkpoint
38
- * h.patch({ count: 2 });
39
- * h.pushNamed('increment');
40
- *
41
- * h.undo(); // back to { count: 1 }
42
- * h.redo(); // forward to { count: 2 }
43
- * h.historyAt(0); // { label: undefined, state: { count: 0 } }
44
- * h.canUndo; // true
45
- *
46
- * // Wrap an existing store:
47
- * const existingStore = store({ x: 0 });
48
- * const h2 = storeWithHistory(existingStore);
49
- * h2.dispose(); // existingStore is NOT disposed
50
- * ```
51
- */
52
- export declare const storeWithHistory: <T extends object>(storeOrInitial: Store<T> | T, options?: {
53
- maxHistory?: number;
54
- name?: string;
55
- }) => StoreWithHistory<T>;
56
- //# sourceMappingURL=history.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"history.d.ts","sourceRoot":"","sources":["../src/history.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAgB,KAAK,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAQrE,YAAY,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAO9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,eAAO,MAAM,gBAAgB,GAAI,CAAC,SAAS,MAAM,EAC/C,gBAAgB,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,EAC5B,UAAU;IAAE,UAAU,CAAC,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,KAC/C,gBAAgB,CAAC,CAAC,CAgGpB,CAAC"}
@@ -1,2 +0,0 @@
1
- const e=require("./symbols.cjs");var t=new FinalizationRegistry(({key:e,map:t})=>{t.delete(e)}),n=class{version=0;name;[e.IS_SIGNAL]=!0;computedSubs_=new Map;effectSubs_=new Set;constructor(e){this.name=e}addComputedSub(e){let n=new WeakRef(e);this.computedSubs_.set(e,n),t.register(e,{key:e,map:this.computedSubs_},n)}removeComputedSub(e){let n=this.computedSubs_.get(e);n!==void 0&&(this.computedSubs_.delete(e),t.unregister(n))}addEffectSub(e){this.effectSubs_.add(e)}removeEffectSub(e){this.effectSubs_.delete(e)}clearSubscribers(){for(let e of this.computedSubs_.values())t.unregister(e);this.computedSubs_.clear(),this.effectSubs_.clear()}hasSubscribers(){if(this.effectSubs_.size>0)return!0;for(let e of this.computedSubs_.values())if(e.deref()!==void 0)return!0;return!1}*computedSubs(){for(let[e,n]of this.computedSubs_){let r=n.deref();r===void 0?(this.computedSubs_.delete(e),t.unregister(n)):yield r}}effectSubs(){return this.effectSubs_}},r=class extends n{[e.IS_COMPUTED]=!0;lastPropEpoch_=0};exports.ComputedBase=r,exports.ReactiveBase=n;
2
- //# sourceMappingURL=reactive-base.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reactive-base.cjs","names":[],"sources":["../src/reactive-base.ts"],"sourcesContent":["import type { Subscriber } from './types';\n\nimport { IS_COMPUTED, IS_SIGNAL } from './symbols';\n\n// ── Global FinalizationRegistry (F1) ──────────────────────────────────────────\n//\n// When a ComputedBase node becomes garbage-collectible, the registry fires and\n// removes the entry from its source's computedSubs_ map. This lets orphaned\n// computeds (created outside a scope/effect and never explicitly disposed) be\n// reclaimed by the GC without manual lifecycle management.\n\ntype ComputedWeakEntry = {\n readonly key: ComputedBase<unknown>;\n readonly map: Map<ComputedBase<unknown>, WeakRef<ComputedBase<unknown>>>;\n};\n\nconst computedSubRegistry = new FinalizationRegistry<ComputedWeakEntry>(({ key, map }) => {\n map.delete(key);\n});\n\n// ── ReactiveBase ──────────────────────────────────────────────────────────────\n\n/**\n * Abstract base shared by SignalImpl and ComputedImpl.\n *\n * Centralises:\n * - Subscriber-set management (computed subs via WeakRef, effect subs directly)\n * - Version counter (used for dep-version cache invalidation in computed)\n * - The [IS_SIGNAL] brand marker\n */\nexport abstract class ReactiveBase<T> {\n version = 0;\n readonly name: string | undefined;\n [IS_SIGNAL] = true;\n\n // A single Map<computed, WeakRef> replaces the previous Set<WeakRef> + WeakMap pair.\n // O(1) add, remove, and lookup without keeping two structures in sync.\n private readonly computedSubs_ = new Map<ComputedBase<unknown>, WeakRef<ComputedBase<unknown>>>();\n private readonly effectSubs_ = new Set<Subscriber>();\n\n constructor(name?: string) {\n this.name = name;\n }\n\n /**\n * Registers a computed as a downstream subscriber. Callers (trackSource in\n * tracking.ts) must ensure they only call this for genuinely NEW deps — i.e.\n * deps not already present in the previous dep list. This guarantees each\n * computed is registered exactly once per source, keeping the WeakRef set\n * clean without needing a dedup scan.\n */\n addComputedSub(c: ComputedBase<unknown>): void {\n const ref = new WeakRef(c);\n\n this.computedSubs_.set(c, ref);\n computedSubRegistry.register(c, { key: c, map: this.computedSubs_ }, ref);\n }\n\n removeComputedSub(c: ComputedBase<unknown>): void {\n const ref = this.computedSubs_.get(c);\n\n if (ref === undefined) return;\n\n this.computedSubs_.delete(c);\n computedSubRegistry.unregister(ref);\n }\n\n addEffectSub(subscriber: Subscriber): void {\n this.effectSubs_.add(subscriber);\n }\n\n removeEffectSub(subscriber: Subscriber): void {\n this.effectSubs_.delete(subscriber);\n }\n\n protected clearSubscribers(): void {\n for (const ref of this.computedSubs_.values()) {\n computedSubRegistry.unregister(ref);\n }\n\n this.computedSubs_.clear();\n this.effectSubs_.clear();\n }\n\n hasSubscribers(): boolean {\n if (this.effectSubs_.size > 0) return true;\n\n for (const ref of this.computedSubs_.values()) {\n if (ref.deref() !== undefined) return true;\n }\n\n return false;\n }\n\n /**\n * Yields live downstream computed subscribers.\n * Dead WeakRefs (GC'd computeds) are pruned eagerly from the map on each traversal,\n * keeping the subscriber set compact without requiring manual dispose calls.\n */\n *computedSubs(): Generator<ComputedBase<unknown>> {\n for (const [key, ref] of this.computedSubs_) {\n const node = ref.deref();\n\n if (node !== undefined) {\n yield node;\n } else {\n this.computedSubs_.delete(key);\n computedSubRegistry.unregister(ref);\n }\n }\n }\n\n effectSubs(): ReadonlySet<Subscriber> {\n return this.effectSubs_;\n }\n\n abstract get value(): T;\n abstract peek(): T;\n}\n\n// ── Refreshable ──────────────────────────────────────────────────────────────\n\n/**\n * Structural interface for lazy nodes that support dirty-flagging and\n * on-demand recompute. Used by tracking.ts to pull computed deps without\n * importing the concrete ComputedImpl class.\n */\nexport interface Refreshable {\n refreshIfDirty(): boolean;\n}\n\n// ── ComputedBase ──────────────────────────────────────────────────────────────\n\n/**\n * Extension of ReactiveBase for derived (lazy) nodes that can be marked dirty\n * and refreshed on demand. Exposes the two methods scheduling.ts needs without\n * importing the concrete ComputedImpl class (breaks the potential circular dep).\n */\nexport abstract class ComputedBase<T> extends ReactiveBase<T> implements Refreshable {\n [IS_COMPUTED] = true;\n lastPropEpoch_ = 0;\n\n abstract markDirty(): boolean;\n abstract refreshIfDirty(): boolean;\n}\n"],"mappings":"iCAgBA,IAAM,EAAsB,IAAI,sBAAyC,CAAE,MAAK,SAAU,CACxF,EAAI,OAAO,CAAG,CAChB,CAAC,EAYqB,EAAtB,KAAsC,CACpC,QAAU,EACV,KACA,CAAC,EAAA,WAAa,GAId,cAAiC,IAAI,IACrC,YAA+B,IAAI,IAEnC,YAAY,EAAe,CACzB,KAAK,KAAO,CACd,CASA,eAAe,EAAgC,CAC7C,IAAM,EAAM,IAAI,QAAQ,CAAC,EAEzB,KAAK,cAAc,IAAI,EAAG,CAAG,EAC7B,EAAoB,SAAS,EAAG,CAAE,IAAK,EAAG,IAAK,KAAK,aAAc,EAAG,CAAG,CAC1E,CAEA,kBAAkB,EAAgC,CAChD,IAAM,EAAM,KAAK,cAAc,IAAI,CAAC,EAEhC,IAAQ,IAAA,KAEZ,KAAK,cAAc,OAAO,CAAC,EAC3B,EAAoB,WAAW,CAAG,EACpC,CAEA,aAAa,EAA8B,CACzC,KAAK,YAAY,IAAI,CAAU,CACjC,CAEA,gBAAgB,EAA8B,CAC5C,KAAK,YAAY,OAAO,CAAU,CACpC,CAEA,kBAAmC,CACjC,IAAK,IAAM,KAAO,KAAK,cAAc,OAAO,EAC1C,EAAoB,WAAW,CAAG,EAGpC,KAAK,cAAc,MAAM,EACzB,KAAK,YAAY,MAAM,CACzB,CAEA,gBAA0B,CACxB,GAAI,KAAK,YAAY,KAAO,EAAG,MAAO,GAEtC,IAAK,IAAM,KAAO,KAAK,cAAc,OAAO,EAC1C,GAAI,EAAI,MAAM,IAAM,IAAA,GAAW,MAAO,GAGxC,MAAO,EACT,CAOA,CAAC,cAAiD,CAChD,IAAK,GAAM,CAAC,EAAK,KAAQ,KAAK,cAAe,CAC3C,IAAM,EAAO,EAAI,MAAM,EAEnB,IAAS,IAAA,IAGX,KAAK,cAAc,OAAO,CAAG,EAC7B,EAAoB,WAAW,CAAG,GAHlC,MAAM,CAKV,CACF,CAEA,YAAsC,CACpC,OAAO,KAAK,WACd,CAIF,EAoBsB,EAAtB,cAA8C,CAAuC,CACnF,CAAC,EAAA,aAAe,GAChB,eAAiB,CAInB"}
@@ -1,60 +0,0 @@
1
- import type { Subscriber } from './types';
2
- import { IS_COMPUTED, IS_SIGNAL } from './symbols';
3
- /**
4
- * Abstract base shared by SignalImpl and ComputedImpl.
5
- *
6
- * Centralises:
7
- * - Subscriber-set management (computed subs via WeakRef, effect subs directly)
8
- * - Version counter (used for dep-version cache invalidation in computed)
9
- * - The [IS_SIGNAL] brand marker
10
- */
11
- export declare abstract class ReactiveBase<T> {
12
- version: number;
13
- readonly name: string | undefined;
14
- [IS_SIGNAL]: boolean;
15
- private readonly computedSubs_;
16
- private readonly effectSubs_;
17
- constructor(name?: string);
18
- /**
19
- * Registers a computed as a downstream subscriber. Callers (trackSource in
20
- * tracking.ts) must ensure they only call this for genuinely NEW deps — i.e.
21
- * deps not already present in the previous dep list. This guarantees each
22
- * computed is registered exactly once per source, keeping the WeakRef set
23
- * clean without needing a dedup scan.
24
- */
25
- addComputedSub(c: ComputedBase<unknown>): void;
26
- removeComputedSub(c: ComputedBase<unknown>): void;
27
- addEffectSub(subscriber: Subscriber): void;
28
- removeEffectSub(subscriber: Subscriber): void;
29
- protected clearSubscribers(): void;
30
- hasSubscribers(): boolean;
31
- /**
32
- * Yields live downstream computed subscribers.
33
- * Dead WeakRefs (GC'd computeds) are pruned eagerly from the map on each traversal,
34
- * keeping the subscriber set compact without requiring manual dispose calls.
35
- */
36
- computedSubs(): Generator<ComputedBase<unknown>>;
37
- effectSubs(): ReadonlySet<Subscriber>;
38
- abstract get value(): T;
39
- abstract peek(): T;
40
- }
41
- /**
42
- * Structural interface for lazy nodes that support dirty-flagging and
43
- * on-demand recompute. Used by tracking.ts to pull computed deps without
44
- * importing the concrete ComputedImpl class.
45
- */
46
- export interface Refreshable {
47
- refreshIfDirty(): boolean;
48
- }
49
- /**
50
- * Extension of ReactiveBase for derived (lazy) nodes that can be marked dirty
51
- * and refreshed on demand. Exposes the two methods scheduling.ts needs without
52
- * importing the concrete ComputedImpl class (breaks the potential circular dep).
53
- */
54
- export declare abstract class ComputedBase<T> extends ReactiveBase<T> implements Refreshable {
55
- [IS_COMPUTED]: boolean;
56
- lastPropEpoch_: number;
57
- abstract markDirty(): boolean;
58
- abstract refreshIfDirty(): boolean;
59
- }
60
- //# sourceMappingURL=reactive-base.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reactive-base.d.ts","sourceRoot":"","sources":["../src/reactive-base.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1C,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AAoBnD;;;;;;;GAOG;AACH,8BAAsB,YAAY,CAAC,CAAC;IAClC,OAAO,SAAK;IACZ,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IAClC,CAAC,SAAS,CAAC,UAAQ;IAInB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAoE;IAClG,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAyB;gBAEzC,IAAI,CAAC,EAAE,MAAM;IAIzB;;;;;;OAMG;IACH,cAAc,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI;IAO9C,iBAAiB,CAAC,CAAC,EAAE,YAAY,CAAC,OAAO,CAAC,GAAG,IAAI;IASjD,YAAY,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAI1C,eAAe,CAAC,UAAU,EAAE,UAAU,GAAG,IAAI;IAI7C,SAAS,CAAC,gBAAgB,IAAI,IAAI;IASlC,cAAc,IAAI,OAAO;IAUzB;;;;OAIG;IACF,YAAY,IAAI,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC;IAajD,UAAU,IAAI,WAAW,CAAC,UAAU,CAAC;IAIrC,QAAQ,KAAK,KAAK,IAAI,CAAC,CAAC;IACxB,QAAQ,CAAC,IAAI,IAAI,CAAC;CACnB;AAID;;;;GAIG;AACH,MAAM,WAAW,WAAW;IAC1B,cAAc,IAAI,OAAO,CAAC;CAC3B;AAID;;;;GAIG;AACH,8BAAsB,YAAY,CAAC,CAAC,CAAE,SAAQ,YAAY,CAAC,CAAC,CAAE,YAAW,WAAW;IAClF,CAAC,WAAW,CAAC,UAAQ;IACrB,cAAc,SAAK;IAEnB,QAAQ,CAAC,SAAS,IAAI,OAAO;IAC7B,QAAQ,CAAC,cAAc,IAAI,OAAO;CACnC"}
@@ -1,56 +0,0 @@
1
- import { IS_COMPUTED as e, IS_SIGNAL as t } from "./symbols.js";
2
- //#region src/reactive-base.ts
3
- var n = new FinalizationRegistry(({ key: e, map: t }) => {
4
- t.delete(e);
5
- }), r = class {
6
- version = 0;
7
- name;
8
- [t] = !0;
9
- computedSubs_ = /* @__PURE__ */ new Map();
10
- effectSubs_ = /* @__PURE__ */ new Set();
11
- constructor(e) {
12
- this.name = e;
13
- }
14
- addComputedSub(e) {
15
- let t = new WeakRef(e);
16
- this.computedSubs_.set(e, t), n.register(e, {
17
- key: e,
18
- map: this.computedSubs_
19
- }, t);
20
- }
21
- removeComputedSub(e) {
22
- let t = this.computedSubs_.get(e);
23
- t !== void 0 && (this.computedSubs_.delete(e), n.unregister(t));
24
- }
25
- addEffectSub(e) {
26
- this.effectSubs_.add(e);
27
- }
28
- removeEffectSub(e) {
29
- this.effectSubs_.delete(e);
30
- }
31
- clearSubscribers() {
32
- for (let e of this.computedSubs_.values()) n.unregister(e);
33
- this.computedSubs_.clear(), this.effectSubs_.clear();
34
- }
35
- hasSubscribers() {
36
- if (this.effectSubs_.size > 0) return !0;
37
- for (let e of this.computedSubs_.values()) if (e.deref() !== void 0) return !0;
38
- return !1;
39
- }
40
- *computedSubs() {
41
- for (let [e, t] of this.computedSubs_) {
42
- let r = t.deref();
43
- r === void 0 ? (this.computedSubs_.delete(e), n.unregister(t)) : yield r;
44
- }
45
- }
46
- effectSubs() {
47
- return this.effectSubs_;
48
- }
49
- }, i = class extends r {
50
- [e] = !0;
51
- lastPropEpoch_ = 0;
52
- };
53
- //#endregion
54
- export { i as ComputedBase, r as ReactiveBase };
55
-
56
- //# sourceMappingURL=reactive-base.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"reactive-base.js","names":[],"sources":["../src/reactive-base.ts"],"sourcesContent":["import type { Subscriber } from './types';\n\nimport { IS_COMPUTED, IS_SIGNAL } from './symbols';\n\n// ── Global FinalizationRegistry (F1) ──────────────────────────────────────────\n//\n// When a ComputedBase node becomes garbage-collectible, the registry fires and\n// removes the entry from its source's computedSubs_ map. This lets orphaned\n// computeds (created outside a scope/effect and never explicitly disposed) be\n// reclaimed by the GC without manual lifecycle management.\n\ntype ComputedWeakEntry = {\n readonly key: ComputedBase<unknown>;\n readonly map: Map<ComputedBase<unknown>, WeakRef<ComputedBase<unknown>>>;\n};\n\nconst computedSubRegistry = new FinalizationRegistry<ComputedWeakEntry>(({ key, map }) => {\n map.delete(key);\n});\n\n// ── ReactiveBase ──────────────────────────────────────────────────────────────\n\n/**\n * Abstract base shared by SignalImpl and ComputedImpl.\n *\n * Centralises:\n * - Subscriber-set management (computed subs via WeakRef, effect subs directly)\n * - Version counter (used for dep-version cache invalidation in computed)\n * - The [IS_SIGNAL] brand marker\n */\nexport abstract class ReactiveBase<T> {\n version = 0;\n readonly name: string | undefined;\n [IS_SIGNAL] = true;\n\n // A single Map<computed, WeakRef> replaces the previous Set<WeakRef> + WeakMap pair.\n // O(1) add, remove, and lookup without keeping two structures in sync.\n private readonly computedSubs_ = new Map<ComputedBase<unknown>, WeakRef<ComputedBase<unknown>>>();\n private readonly effectSubs_ = new Set<Subscriber>();\n\n constructor(name?: string) {\n this.name = name;\n }\n\n /**\n * Registers a computed as a downstream subscriber. Callers (trackSource in\n * tracking.ts) must ensure they only call this for genuinely NEW deps — i.e.\n * deps not already present in the previous dep list. This guarantees each\n * computed is registered exactly once per source, keeping the WeakRef set\n * clean without needing a dedup scan.\n */\n addComputedSub(c: ComputedBase<unknown>): void {\n const ref = new WeakRef(c);\n\n this.computedSubs_.set(c, ref);\n computedSubRegistry.register(c, { key: c, map: this.computedSubs_ }, ref);\n }\n\n removeComputedSub(c: ComputedBase<unknown>): void {\n const ref = this.computedSubs_.get(c);\n\n if (ref === undefined) return;\n\n this.computedSubs_.delete(c);\n computedSubRegistry.unregister(ref);\n }\n\n addEffectSub(subscriber: Subscriber): void {\n this.effectSubs_.add(subscriber);\n }\n\n removeEffectSub(subscriber: Subscriber): void {\n this.effectSubs_.delete(subscriber);\n }\n\n protected clearSubscribers(): void {\n for (const ref of this.computedSubs_.values()) {\n computedSubRegistry.unregister(ref);\n }\n\n this.computedSubs_.clear();\n this.effectSubs_.clear();\n }\n\n hasSubscribers(): boolean {\n if (this.effectSubs_.size > 0) return true;\n\n for (const ref of this.computedSubs_.values()) {\n if (ref.deref() !== undefined) return true;\n }\n\n return false;\n }\n\n /**\n * Yields live downstream computed subscribers.\n * Dead WeakRefs (GC'd computeds) are pruned eagerly from the map on each traversal,\n * keeping the subscriber set compact without requiring manual dispose calls.\n */\n *computedSubs(): Generator<ComputedBase<unknown>> {\n for (const [key, ref] of this.computedSubs_) {\n const node = ref.deref();\n\n if (node !== undefined) {\n yield node;\n } else {\n this.computedSubs_.delete(key);\n computedSubRegistry.unregister(ref);\n }\n }\n }\n\n effectSubs(): ReadonlySet<Subscriber> {\n return this.effectSubs_;\n }\n\n abstract get value(): T;\n abstract peek(): T;\n}\n\n// ── Refreshable ──────────────────────────────────────────────────────────────\n\n/**\n * Structural interface for lazy nodes that support dirty-flagging and\n * on-demand recompute. Used by tracking.ts to pull computed deps without\n * importing the concrete ComputedImpl class.\n */\nexport interface Refreshable {\n refreshIfDirty(): boolean;\n}\n\n// ── ComputedBase ──────────────────────────────────────────────────────────────\n\n/**\n * Extension of ReactiveBase for derived (lazy) nodes that can be marked dirty\n * and refreshed on demand. Exposes the two methods scheduling.ts needs without\n * importing the concrete ComputedImpl class (breaks the potential circular dep).\n */\nexport abstract class ComputedBase<T> extends ReactiveBase<T> implements Refreshable {\n [IS_COMPUTED] = true;\n lastPropEpoch_ = 0;\n\n abstract markDirty(): boolean;\n abstract refreshIfDirty(): boolean;\n}\n"],"mappings":";;AAgBA,IAAM,IAAsB,IAAI,sBAAyC,EAAE,QAAK,aAAU;CACxF,EAAI,OAAO,CAAG;AAChB,CAAC,GAYqB,IAAtB,MAAsC;CACpC,UAAU;CACV;CACA,CAAC,KAAa;CAId,gCAAiC,IAAI,IAA2D;CAChG,8BAA+B,IAAI,IAAgB;CAEnD,YAAY,GAAe;EACzB,KAAK,OAAO;CACd;CASA,eAAe,GAAgC;EAC7C,IAAM,IAAM,IAAI,QAAQ,CAAC;EAGzB,AADA,KAAK,cAAc,IAAI,GAAG,CAAG,GAC7B,EAAoB,SAAS,GAAG;GAAE,KAAK;GAAG,KAAK,KAAK;EAAc,GAAG,CAAG;CAC1E;CAEA,kBAAkB,GAAgC;EAChD,IAAM,IAAM,KAAK,cAAc,IAAI,CAAC;EAEhC,MAAQ,KAAA,MAEZ,KAAK,cAAc,OAAO,CAAC,GAC3B,EAAoB,WAAW,CAAG;CACpC;CAEA,aAAa,GAA8B;EACzC,KAAK,YAAY,IAAI,CAAU;CACjC;CAEA,gBAAgB,GAA8B;EAC5C,KAAK,YAAY,OAAO,CAAU;CACpC;CAEA,mBAAmC;EACjC,KAAK,IAAM,KAAO,KAAK,cAAc,OAAO,GAC1C,EAAoB,WAAW,CAAG;EAIpC,AADA,KAAK,cAAc,MAAM,GACzB,KAAK,YAAY,MAAM;CACzB;CAEA,iBAA0B;EACxB,IAAI,KAAK,YAAY,OAAO,GAAG,OAAO;EAEtC,KAAK,IAAM,KAAO,KAAK,cAAc,OAAO,GAC1C,IAAI,EAAI,MAAM,MAAM,KAAA,GAAW,OAAO;EAGxC,OAAO;CACT;CAOA,CAAC,eAAiD;EAChD,KAAK,IAAM,CAAC,GAAK,MAAQ,KAAK,eAAe;GAC3C,IAAM,IAAO,EAAI,MAAM;GAEvB,AAAI,MAAS,KAAA,KAGX,KAAK,cAAc,OAAO,CAAG,GAC7B,EAAoB,WAAW,CAAG,KAHlC,MAAM;EAKV;CACF;CAEA,aAAsC;EACpC,OAAO,KAAK;CACd;AAIF,GAoBsB,IAAtB,cAA8C,EAAuC;CACnF,CAAC,KAAe;CAChB,iBAAiB;AAInB"}
@@ -1,2 +0,0 @@
1
- const e=require("./_error-utils.cjs"),t=require("./errors.cjs"),n=require("./execution-context.cjs"),r=require("./_dev.cjs");var i=!1,a=0,o=[],s=e=>e.activeDirty===`a`?e.dirtyWithEffectSubsA:e.dirtyWithEffectSubsB,c=(e,t)=>{let n=++a;for(let n of t.effectSubs())e.pendingSubscribers.add(n);for(let e of t.computedSubs())o.push(e);try{for(;o.length>0;){let t=o.pop();if(t.lastPropEpoch_!==n&&(t.lastPropEpoch_=n,t.markDirty())){t.effectSubs().size>0&&s(e).add(t);for(let e of t.computedSubs())o.push(e)}}}finally{o.length=0}},l=e=>{for(;s(e).size>0;){let t=s(e);e.activeDirty=e.activeDirty===`a`?`b`:`a`,s(e).clear();for(let n of t)if(n.hasSubscribers()&&n.refreshIfDirty()){for(let t of n.effectSubs())e.pendingSubscribers.add(t);for(let t of n.computedSubs())t.markDirty()&&t.effectSubs().size>0&&s(e).add(t)}t.clear()}},u=n=>{let r=0;for(;n.pendingSubscribers.size>0||s(n).size>0;){if(++r>100)throw new t.RippleInfiniteLoopError(`infinite flush loop (> 100 iterations)`);if(s(n).size>0&&l(n),n.pendingSubscribers.size===0)continue;let i=[...n.pendingSubscribers];n.pendingSubscribers.clear(),e.runAll(i,`subscriber errors`)}},d=globalThis.process?.versions!=null,f=e=>{if(!e.hasSubscribers())return;!i&&d&&!n.hasContextHook()&&(i=!0,r.warn(`Signal updated in a Node.js-like environment. The module-level flush queue is shared across concurrent requests — use per-request worker isolation or the @vielzeug/ripple/ssr sub-path for request-isolated scheduling.`));let t=n.getSchedulingState();c(t,e),t.batchDepth===0&&u(t)},p=e=>{let t=n.getSchedulingState();t.batchDepth++;let r;try{r=e()}catch(e){throw t.batchDepth--,t.batchDepth===0&&(t.pendingSubscribers.clear(),t.dirtyWithEffectSubsA.clear(),t.dirtyWithEffectSubsB.clear()),e}return t.batchDepth--,t.batchDepth===0&&u(t),r};exports.batch=p,exports.notifyNodeChange=f;
2
- //# sourceMappingURL=scheduling.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scheduling.cjs","names":[],"sources":["../src/scheduling.ts"],"sourcesContent":["import type { ComputedBase, ReactiveBase } from './reactive-base';\nimport type { Subscriber } from './types';\n\nimport { warn } from './_dev';\nimport { runAll } from './_error-utils';\nimport { RippleInfiniteLoopError } from './errors';\nimport { getSchedulingState, hasContextHook, type SchedulingState } from './execution-context';\n\nexport const DEFAULT_MAX_ITERATIONS = 100;\n\n// batchDepth, pendingSubscribers, and the dirty-computed sets live in `SchedulingState`\n// (see tracking.ts) rather than as module-level variables — this lets the /ripple/ssr\n// sub-path isolate the flush queue per request (via the same AsyncLocalStorage-backed\n// context hook that already isolates tracking), closing the gap where concurrent SSR\n// requests previously shared one flush queue. Outside SSR (no hook installed), this is\n// a single module-level singleton with identical behavior and cost to before.\nlet ssrWarnFired = false;\n\n// ── F1: Simplified flush — no topological sort ─────────────────────────────\n//\n// Push phase (propagateDirty):\n// Mark all downstream computeds dirty in a BFS pass.\n// Directly collect effect subscribers of the changed signal.\n// For computeds with direct effect subscribers, defer to the pull phase.\n//\n// Pull phase (recomputeWithEffectSubs):\n// For each dirty computed that has direct effect subscribers, recompute it.\n// If the value changed, queue its effect subscribers.\n// Any further downstream dirty computeds with effect subs are handled in the\n// same loop (re-queued into dirtyWithEffectSubs if they become dirty during\n// a parent recompute).\n//\n// Effect phase: run all queued effect subscribers.\n//\n// This eliminates the O(n²) topo sort while preserving the equality-suppression\n// guarantee: effect subs of a computed are only notified when the computed's\n// value actually changes.\n//\n// Computeds without direct effect subs (pure lazy nodes) are still pulled\n// lazily when an effect reads them during re-run.\n\n// Module-level scratch state — safe to share even under SSR isolation. Both are only\n// touched within a single synchronous call stack (no `await` inside propagateDirty /\n// recomputeWithEffectSubs / flushEffects), which JS's run-to-completion model already\n// isolates; they never carry information across two separate top-level signal writes.\nlet _propEpoch = 0;\nconst _propagateStack: ComputedBase<unknown>[] = [];\n\n/** Returns (and possibly swaps) the currently-active dirty-with-effect-subs set. */\nconst activeDirtySet = (s: SchedulingState): Set<ComputedBase<unknown>> =>\n s.activeDirty === 'a' ? s.dirtyWithEffectSubsA : s.dirtyWithEffectSubsB;\n\nconst propagateDirty = (\n s: SchedulingState,\n node: {\n computedSubs(): Generator<ComputedBase<unknown>>;\n effectSubs(): ReadonlySet<Subscriber>;\n },\n): void => {\n const epoch = ++_propEpoch;\n\n // Queue direct effect subs of the changed node\n for (const sub of node.effectSubs()) {\n s.pendingSubscribers.add(sub);\n }\n\n for (const c of node.computedSubs()) {\n _propagateStack.push(c);\n }\n\n try {\n while (_propagateStack.length > 0) {\n const c = _propagateStack.pop()!;\n\n if (c.lastPropEpoch_ === epoch) continue;\n\n c.lastPropEpoch_ = epoch;\n\n if (!c.markDirty()) continue; // already dirty — already processed\n\n // If this computed has effect subs, defer recompute to the pull phase.\n // We cannot queue them immediately because the computed might not change.\n if (c.effectSubs().size > 0) {\n activeDirtySet(s).add(c);\n }\n\n for (const downstream of c.computedSubs()) {\n _propagateStack.push(downstream);\n }\n }\n } finally {\n _propagateStack.length = 0;\n }\n};\n\nconst recomputeWithEffectSubs = (s: SchedulingState): void => {\n // Iterate until stable — recomputing one computed may dirty others.\n // Set-swap pattern: swap active/idle sets each pass so new dirty nodes accumulate\n // in the idle set while we iterate the current batch — zero array allocations.\n while (activeDirtySet(s).size > 0) {\n const toProcess = activeDirtySet(s);\n\n // Swap: new dirty nodes from this iteration go into the other set\n s.activeDirty = s.activeDirty === 'a' ? 'b' : 'a';\n activeDirtySet(s).clear();\n\n for (const c of toProcess) {\n if (!c.hasSubscribers()) continue;\n\n const changed = c.refreshIfDirty();\n\n if (!changed) continue;\n\n // Value changed — queue effect subs\n for (const sub of c.effectSubs()) {\n s.pendingSubscribers.add(sub);\n }\n\n // Downstream computeds may now need recomputing too\n for (const downstream of c.computedSubs()) {\n if (downstream.markDirty() && downstream.effectSubs().size > 0) {\n activeDirtySet(s).add(downstream);\n }\n }\n }\n\n toProcess.clear();\n }\n};\n\nconst flushEffects = (s: SchedulingState): void => {\n let iterations = 0;\n\n while (s.pendingSubscribers.size > 0 || activeDirtySet(s).size > 0) {\n if (++iterations > DEFAULT_MAX_ITERATIONS) {\n throw new RippleInfiniteLoopError(`infinite flush loop (> ${DEFAULT_MAX_ITERATIONS} iterations)`);\n }\n\n if (activeDirtySet(s).size > 0) recomputeWithEffectSubs(s);\n\n if (s.pendingSubscribers.size === 0) continue;\n\n const subscribersToRun = [...s.pendingSubscribers];\n\n s.pendingSubscribers.clear();\n runAll(subscribersToRun, 'subscriber errors');\n }\n};\n\n// Fire the warning once per module load in environments that look like Node.js,\n// and only when no SSR context hook is installed (once installed, the flush queue\n// is genuinely request-isolated via SchedulingState — see tracking.ts).\n// window-check is unreliable (jsdom sets window in tests); check for process.versions instead.\n// Access entirely via globalThis to avoid requiring @types/node in downstream tsconfigs.\nconst isNodeLike = (globalThis as { process?: { versions?: unknown } }).process?.versions != null;\n\nexport const notifyNodeChange = (node: ReactiveBase<unknown>): void => {\n if (!node.hasSubscribers()) return;\n\n if (!ssrWarnFired && isNodeLike && !hasContextHook()) {\n ssrWarnFired = true;\n warn(\n 'Signal updated in a Node.js-like environment. The module-level flush queue is shared across concurrent requests ' +\n '— use per-request worker isolation or the @vielzeug/ripple/ssr sub-path for request-isolated scheduling.',\n );\n }\n\n const s = getSchedulingState();\n\n propagateDirty(s, node);\n\n if (s.batchDepth === 0) flushEffects(s);\n};\n\nexport const batch = <T>(fn: () => T): T => {\n const s = getSchedulingState();\n\n s.batchDepth++;\n\n let result: T;\n\n try {\n result = fn();\n } catch (e) {\n s.batchDepth--;\n\n // Outermost batch: clear the pending flush queue on body error.\n // Leaving stale subscribers in the queue would flush them on the next unrelated\n // signal write, surfacing errors in unexpected contexts.\n if (s.batchDepth === 0) {\n s.pendingSubscribers.clear();\n s.dirtyWithEffectSubsA.clear();\n s.dirtyWithEffectSubsB.clear();\n }\n\n throw e;\n }\n\n s.batchDepth--;\n\n if (s.batchDepth === 0) flushEffects(s);\n\n return result;\n};\n"],"mappings":"6HAgBA,IAAI,EAAe,GA6Bf,EAAa,EACX,EAA2C,CAAC,EAG5C,EAAkB,GACtB,EAAE,cAAgB,IAAM,EAAE,qBAAuB,EAAE,qBAE/C,GACJ,EACA,IAIS,CACT,IAAM,EAAQ,EAAE,EAGhB,IAAK,IAAM,KAAO,EAAK,WAAW,EAChC,EAAE,mBAAmB,IAAI,CAAG,EAG9B,IAAK,IAAM,KAAK,EAAK,aAAa,EAChC,EAAgB,KAAK,CAAC,EAGxB,GAAI,CACF,KAAO,EAAgB,OAAS,GAAG,CACjC,IAAM,EAAI,EAAgB,IAAI,EAE1B,KAAE,iBAAmB,IAEzB,EAAE,eAAiB,EAEd,EAAE,UAAU,GAIjB,CAAI,EAAE,WAAW,CAAC,CAAC,KAAO,GACxB,EAAe,CAAC,CAAC,CAAC,IAAI,CAAC,EAGzB,IAAK,IAAM,KAAc,EAAE,aAAa,EACtC,EAAgB,KAAK,CAAU,CAJR,CAM3B,CACF,QAAU,CACR,EAAgB,OAAS,CAC3B,CACF,EAEM,EAA2B,GAA6B,CAI5D,KAAO,EAAe,CAAC,CAAC,CAAC,KAAO,GAAG,CACjC,IAAM,EAAY,EAAe,CAAC,EAGlC,EAAE,YAAc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,MAAM,EAC7B,EAAE,qBAAqB,MAAM,GAGzB,CACR,CAMA,MAJA,GAAE,aAEE,EAAE,aAAe,GAAG,EAAa,CAAC,EAE/B,CACT"}
@@ -1,5 +0,0 @@
1
- import type { ReactiveBase } from './reactive-base';
2
- export declare const DEFAULT_MAX_ITERATIONS = 100;
3
- export declare const notifyNodeChange: (node: ReactiveBase<unknown>) => void;
4
- export declare const batch: <T>(fn: () => T) => T;
5
- //# sourceMappingURL=scheduling.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"scheduling.d.ts","sourceRoot":"","sources":["../src/scheduling.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAgB,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAQlE,eAAO,MAAM,sBAAsB,MAAM,CAAC;AAoJ1C,eAAO,MAAM,gBAAgB,GAAI,MAAM,YAAY,CAAC,OAAO,CAAC,KAAG,IAgB9D,CAAC;AAEF,eAAO,MAAM,KAAK,GAAI,CAAC,EAAE,IAAI,MAAM,CAAC,KAAG,CA6BtC,CAAC"}