@vielzeug/ripple 1.2.3 → 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 (157) hide show
  1. package/README.md +33 -71
  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 -11
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +25 -12
  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 -44
  50. package/dist/store.d.ts.map +1 -1
  51. package/dist/store.js +2 -205
  52. package/dist/types.d.ts +37 -292
  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 +23 -16
  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 -58
  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 -173
  97. package/dist/effect.js.map +0 -1
  98. package/dist/reactive-base.cjs +0 -2
  99. package/dist/reactive-base.cjs.map +0 -1
  100. package/dist/reactive-base.d.ts +0 -60
  101. package/dist/reactive-base.d.ts.map +0 -1
  102. package/dist/reactive-base.js +0 -56
  103. package/dist/reactive-base.js.map +0 -1
  104. package/dist/scheduling.cjs +0 -2
  105. package/dist/scheduling.cjs.map +0 -1
  106. package/dist/scheduling.d.ts +0 -5
  107. package/dist/scheduling.d.ts.map +0 -1
  108. package/dist/scheduling.js +0 -57
  109. package/dist/scheduling.js.map +0 -1
  110. package/dist/signal.cjs +0 -2
  111. package/dist/signal.cjs.map +0 -1
  112. package/dist/signal.d.ts +0 -24
  113. package/dist/signal.d.ts.map +0 -1
  114. package/dist/signal.js +0 -54
  115. package/dist/signal.js.map +0 -1
  116. package/dist/src/devtools.cjs +0 -2
  117. package/dist/src/devtools.cjs.map +0 -1
  118. package/dist/src/devtools.js +0 -36
  119. package/dist/src/devtools.js.map +0 -1
  120. package/dist/src/ssr/index.cjs +0 -2
  121. package/dist/src/ssr/index.cjs.map +0 -1
  122. package/dist/src/ssr/index.js +0 -38
  123. package/dist/src/ssr/index.js.map +0 -1
  124. package/dist/ssr/index.d.ts +0 -56
  125. package/dist/ssr/index.d.ts.map +0 -1
  126. package/dist/store-history.cjs +0 -2
  127. package/dist/store-history.cjs.map +0 -1
  128. package/dist/store-history.d.ts +0 -42
  129. package/dist/store-history.d.ts.map +0 -1
  130. package/dist/store-history.js +0 -60
  131. package/dist/store-history.js.map +0 -1
  132. package/dist/store.cjs.map +0 -1
  133. package/dist/store.js.map +0 -1
  134. package/dist/subscription.cjs +0 -2
  135. package/dist/subscription.cjs.map +0 -1
  136. package/dist/subscription.d.ts +0 -22
  137. package/dist/subscription.d.ts.map +0 -1
  138. package/dist/subscription.js +0 -47
  139. package/dist/subscription.js.map +0 -1
  140. package/dist/symbols.cjs +0 -2
  141. package/dist/symbols.cjs.map +0 -1
  142. package/dist/symbols.d.ts +0 -6
  143. package/dist/symbols.d.ts.map +0 -1
  144. package/dist/symbols.js +0 -6
  145. package/dist/symbols.js.map +0 -1
  146. package/dist/tracking.cjs +0 -2
  147. package/dist/tracking.cjs.map +0 -1
  148. package/dist/tracking.d.ts +0 -82
  149. package/dist/tracking.d.ts.map +0 -1
  150. package/dist/tracking.js +0 -76
  151. package/dist/tracking.js.map +0 -1
  152. package/dist/utilities.cjs +0 -2
  153. package/dist/utilities.cjs.map +0 -1
  154. package/dist/utilities.d.ts +0 -56
  155. package/dist/utilities.d.ts.map +0 -1
  156. package/dist/utilities.js +0 -25
  157. package/dist/utilities.js.map +0 -1
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracking.cjs","names":[],"sources":["../src/tracking.ts"],"sourcesContent":["import type { ComputedBase, ReactiveBase } from './reactive-base';\nimport type { CleanupFn, Subscriber } from './types';\n\n// ── Global revision clock ─────────────────────────────────────────────────────\n//\n// Monotonically-increasing counter incremented on every signal write.\n// ComputedImpl records the clock value after each successful recompute and uses\n// it as an O(1) \"nothing has changed globally\" fast-path check in refreshIfDirty.\n\nlet globalRevision = 0;\n\nexport const tickRevision = (): number => ++globalRevision;\nexport const getRevision = (): number => globalRevision;\n\n// ── Internal types ────────────────────────────────────────────────────────────\n\nexport type DepEntry = {\n source: ReactiveBase<unknown>;\n version: number;\n};\n\n/** Called by trackSource to observe each reactive source accessed during a tracked run. */\nexport type SourceObserver = (source: ReactiveBase<unknown>) => void;\n\n// TrackingCtx carries both dep-collection state AND an optional sourceObserver.\n// Putting the observer inside the context (R12) scopes it to the specific effect/computed\n// run rather than making it a process-wide global — nested computed recomputes use their\n// own context (no observer), so the debugEffect pattern works without identity checks.\n// sourceObserver is shared across both branches and lives outside the discriminant union.\nexport type TrackingCtx = {\n sourceObserver?: SourceObserver;\n} & (\n | {\n computed: ComputedBase<unknown>;\n depCollector: DepEntry[];\n kind: 'computed';\n }\n | {\n cleanups: CleanupFn[];\n deps: Map<ReactiveBase<unknown>, number>;\n effect: Subscriber;\n kind: 'effect';\n subscriptions: Set<CleanupFn>;\n }\n);\n\n// ── Scheduling state ────────────────────────────────────────────────────────\n//\n// Colocated here (rather than in scheduling.ts) so it can be a field of\n// ExecutionContext without a runtime circular import between tracking.ts and\n// scheduling.ts — scheduling.ts only needs `getSchedulingState()` and the\n// `SchedulingState` type (type-only import, erased at compile time).\n//\n// Isolating this per-request (via the SSR hook) closes the documented gap where\n// concurrent SSR requests share one flush queue: `batchDepth`, `pendingSubscribers`,\n// and the dirty-computed sets are the only scheduling fields that can observably\n// leak across requests (they persist across `await` boundaries via `batch()`\n// spanning shared module-level signals). The propagation epoch/stack in\n// scheduling.ts stay module-level scratch memory — they're only touched within a\n// single synchronous call stack, which JS's run-to-completion model already isolates.\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// ── ExecutionContext ──────────────────────────────────────────────────────────\n//\n// Unified context replaces two separate globals (_tracking and _scopeStack).\n// Both the dep-tracking context and the innermost scope's cleanup array live here.\n// The SSR hook overrides the entire context per-request — fixing the prior bug\n// where scope cleanups were always a process-wide singleton even with the hook.\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\nconst getCtx = (): ExecutionContext => (_hook !== null ? _hook.get() : _ctx);\n\n/** Returns the scheduling-state bucket for the active execution context (module-level singleton outside SSR). */\nexport const getSchedulingState = (): SchedulingState => getCtx().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// ── Tracking ──────────────────────────────────────────────────────────────────\n\nexport const getTracking = (): TrackingCtx | null => getCtx().tracking;\n\nexport const withTracking = <T>(tracking: TrackingCtx | null, fn: () => T): T => {\n if (_hook !== null) {\n const current = _hook.get();\n\n return _hook.run({ ...current, tracking }, fn);\n }\n\n const prev = _ctx;\n\n _ctx = { ..._ctx, tracking };\n\n try {\n return fn();\n } finally {\n _ctx = prev;\n }\n};\n\n// ── Scope cleanup ─────────────────────────────────────────────────────────────\n\n/**\n * Pushes `cleanups` as the active scope cleanup array for the duration of `fn`.\n * Any `onCleanup()` calls inside `fn` will register into these cleanups.\n * Effects and computed values created inside `fn` are also auto-registered.\n */\nexport const withScopeCleanups = <T>(cleanups: CleanupFn[], fn: () => T): T => {\n if (_hook !== null) {\n const current = _hook.get();\n\n return _hook.run({ ...current, scopeCleanups: cleanups }, fn);\n }\n\n const prev = _ctx;\n\n _ctx = { ..._ctx, scopeCleanups: cleanups };\n\n try {\n return fn();\n } finally {\n _ctx = prev;\n }\n};\n\n/**\n * Returns the cleanup array of the innermost active scope, or `null` if not inside a scope.\n */\nexport const getScopeCleanups = (): CleanupFn[] | null => getCtx().scopeCleanups;\n\n// ── Auto-disposal ───────────────────────────────────────────────────────────────\n//\n// Shared by every primitive that ties its own lifetime to the context it was\n// created in (computed(), resource()): dispose when the enclosing effect re-runs\n// or disposes, or — if not inside an effect — when the enclosing scope disposes.\n// No-op if neither is active (the caller owns disposal directly).\n//\n// Why signal() and store() don't call this: computed()/resource() are *derived*\n// computations — recreating one on every effect re-run is normal and cheap, so\n// tying their lifetime to the enclosing context avoids leaking a fresh graph\n// node per run. signal()/store() hold raw, caller-owned state that is typically\n// created once and read across many effect re-runs; auto-disposing it on the\n// first re-run would silently break any effect that reads a signal it declared\n// itself. Callers who genuinely want scope-scoped state should use\n// `scope.add(() => mySignal.dispose())` explicitly.\n\n/**\n * Registers `dispose` to run when the enclosing effect re-runs/disposes, or —\n * if there is no enclosing effect — when the enclosing scope disposes.\n */\nexport const autoRegisterDisposal = (dispose: CleanupFn): void => {\n const ctx = getTracking();\n\n if (ctx?.kind === 'effect') {\n ctx.cleanups.push(dispose);\n } else {\n getScopeCleanups()?.push(dispose);\n }\n};\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\n// ── Source observer ───────────────────────────────────────────────────────────\n//\n// Observer is now scoped to the active TrackingCtx instead of a process-wide global.\n// This means it only fires for direct deps of the current effect/computed — nested\n// computed recomputes use their own context (no observer) so no identity check needed.\n\n/**\n * Runs `fn` while calling `observer` for every reactive source directly accessed.\n * Used by `debugEffect` to detect which sources changed between runs.\n * No-op if called outside an active tracking context.\n */\nexport const withSourceObserver = <T>(observer: SourceObserver, fn: () => T): T => {\n const current = getTracking();\n\n if (current === null) return fn();\n\n return withTracking({ ...current, sourceObserver: observer }, fn);\n};\n\n// ── untrack ───────────────────────────────────────────────────────────────────\n\n/**\n * Runs `fn` without recording any reactive reads as dependencies of the enclosing\n * effect or computed. Useful when you need to read reactive state \"silently\".\n *\n * @example\n * ```ts\n * effect(() => {\n * const a = count.value; // tracked\n * const b = untrack(() => name.value); // NOT tracked — no re-run when name changes\n * });\n * ```\n */\nexport const untrack = <T>(fn: () => T): T => withTracking(null, fn);\n\n// ── trackSource ───────────────────────────────────────────────────────────────\n//\n// Records `source` as a dependency of the currently active tracking context.\n// For computed contexts: only records the dep entry — addComputedSub is called\n// later by updateDeps() in computed.ts (only for genuinely NEW deps, preventing\n// duplicate WeakRef entries).\n// For effect contexts: immediately subscribes the effect to the source and\n// records the dep for getDependencies().\n\nexport const trackSource = (source: ReactiveBase<unknown>): void => {\n const ctx = getTracking();\n\n if (ctx === null) return;\n\n ctx.sourceObserver?.(source);\n\n if (ctx.kind === 'computed') {\n ctx.depCollector.push({ source, version: source.version });\n } else if (ctx.kind === 'effect') {\n const owner = ctx.effect;\n\n source.addEffectSub(owner);\n ctx.subscriptions.add(() => source.removeEffectSub(owner));\n ctx.deps.set(source, source.version);\n }\n};\n"],"mappings":"AASA,IAAI,EAAiB,EAER,MAA6B,EAAE,EAC/B,MAA4B,EAyD5B,OAAgD,CAC3D,YAAa,IACb,WAAY,EACZ,qBAAsB,IAAI,IAC1B,qBAAsB,IAAI,IAC1B,mBAAoB,IAAI,GAC1B,GAoBI,EAAyB,CAAE,WAAY,EAAsB,EAAG,cAAe,KAAM,SAAU,IAAK,EACpG,EAA4B,KAE1B,MAAkC,IAAU,KAAqB,EAAd,EAAM,IAAI,EAGtD,MAA4C,EAAO,CAAC,CAAC,WAGrD,MAAgC,IAAU,KAI1C,MAAwC,EAAO,CAAC,CAAC,SAEjD,GAAmB,EAA8B,IAAmB,CAC/E,GAAI,IAAU,KAAM,CAClB,IAAM,EAAU,EAAM,IAAI,EAE1B,OAAO,EAAM,IAAI,CAAE,GAAG,EAAS,UAAS,EAAG,CAAE,CAC/C,CAEA,IAAM,EAAO,EAEb,EAAO,CAAE,GAAG,EAAM,UAAS,EAE3B,GAAI,CACF,OAAO,EAAG,CACZ,QAAU,CACR,EAAO,CACT,CACF,EASa,GAAwB,EAAuB,IAAmB,CAC7E,GAAI,IAAU,KAAM,CAClB,IAAM,EAAU,EAAM,IAAI,EAE1B,OAAO,EAAM,IAAI,CAAE,GAAG,EAAS,cAAe,CAAS,EAAG,CAAE,CAC9D,CAEA,IAAM,EAAO,EAEb,EAAO,CAAE,GAAG,EAAM,cAAe,CAAS,EAE1C,GAAI,CACF,OAAO,EAAG,CACZ,QAAU,CACR,EAAO,CACT,CACF,EAKa,MAA6C,EAAO,CAAC,CAAC,cAsBtD,EAAwB,GAA6B,CAChE,IAAM,EAAM,EAAY,EAEpB,GAAK,OAAS,SAChB,EAAI,SAAS,KAAK,CAAO,EAEzB,EAAiB,CAAC,EAAE,KAAK,CAAO,CAEpC,EASa,EAAuB,GAAiD,CACnF,IAAM,EAAO,EAIb,MAFA,GAAQ,EAED,CACT,EAaa,GAAyB,EAA0B,IAAmB,CACjF,IAAM,EAAU,EAAY,EAI5B,OAFI,IAAY,KAAa,EAAG,EAEzB,EAAa,CAAE,GAAG,EAAS,eAAgB,CAAS,EAAG,CAAE,CAClE,EAgBa,EAAc,GAAmB,EAAa,KAAM,CAAE,EAWtD,EAAe,GAAwC,CAClE,IAAM,EAAM,EAAY,EAEpB,OAAQ,KAIZ,IAFA,EAAI,iBAAiB,CAAM,EAEvB,EAAI,OAAS,WACf,EAAI,aAAa,KAAK,CAAE,SAAQ,QAAS,EAAO,OAAQ,CAAC,OACpD,GAAI,EAAI,OAAS,SAAU,CAChC,IAAM,EAAQ,EAAI,OAElB,EAAO,aAAa,CAAK,EACzB,EAAI,cAAc,QAAU,EAAO,gBAAgB,CAAK,CAAC,EACzD,EAAI,KAAK,IAAI,EAAQ,EAAO,OAAO,CACrC,EACF"}
@@ -1,82 +0,0 @@
1
- import type { ComputedBase, ReactiveBase } from './reactive-base';
2
- import type { CleanupFn, Subscriber } from './types';
3
- export declare const tickRevision: () => number;
4
- export declare const getRevision: () => number;
5
- export type DepEntry = {
6
- source: ReactiveBase<unknown>;
7
- version: number;
8
- };
9
- /** Called by trackSource to observe each reactive source accessed during a tracked run. */
10
- export type SourceObserver = (source: ReactiveBase<unknown>) => void;
11
- export type TrackingCtx = {
12
- sourceObserver?: SourceObserver;
13
- } & ({
14
- computed: ComputedBase<unknown>;
15
- depCollector: DepEntry[];
16
- kind: 'computed';
17
- } | {
18
- cleanups: CleanupFn[];
19
- deps: Map<ReactiveBase<unknown>, number>;
20
- effect: Subscriber;
21
- kind: 'effect';
22
- subscriptions: Set<CleanupFn>;
23
- });
24
- export type SchedulingState = {
25
- activeDirty: 'a' | 'b';
26
- batchDepth: number;
27
- readonly dirtyWithEffectSubsA: Set<ComputedBase<unknown>>;
28
- readonly dirtyWithEffectSubsB: Set<ComputedBase<unknown>>;
29
- readonly pendingSubscribers: Set<Subscriber>;
30
- };
31
- export declare const createSchedulingState: () => SchedulingState;
32
- export type ExecutionContext = {
33
- readonly scheduling: SchedulingState;
34
- readonly scopeCleanups: CleanupFn[] | null;
35
- readonly tracking: TrackingCtx | null;
36
- };
37
- export type ContextHook = {
38
- get(): ExecutionContext;
39
- run<T>(ctx: ExecutionContext, fn: () => T): T;
40
- };
41
- /** Returns the scheduling-state bucket for the active execution context (module-level singleton outside SSR). */
42
- export declare const getSchedulingState: () => SchedulingState;
43
- /** `true` once an SSR context hook is installed — scheduling state is then request-isolated. */
44
- export declare const hasContextHook: () => boolean;
45
- export declare const getTracking: () => TrackingCtx | null;
46
- export declare const withTracking: <T>(tracking: TrackingCtx | null, fn: () => T) => T;
47
- /**
48
- * Pushes `cleanups` as the active scope cleanup array for the duration of `fn`.
49
- * Any `onCleanup()` calls inside `fn` will register into these cleanups.
50
- * Effects and computed values created inside `fn` are also auto-registered.
51
- */
52
- export declare const withScopeCleanups: <T>(cleanups: CleanupFn[], fn: () => T) => T;
53
- /**
54
- * Returns the cleanup array of the innermost active scope, or `null` if not inside a scope.
55
- */
56
- export declare const getScopeCleanups: () => CleanupFn[] | null;
57
- /**
58
- * Registers `dispose` to run when the enclosing effect re-runs/disposes, or —
59
- * if there is no enclosing effect — when the enclosing scope disposes.
60
- */
61
- export declare const autoRegisterDisposal: (dispose: CleanupFn) => void;
62
- /**
63
- * Runs `fn` while calling `observer` for every reactive source directly accessed.
64
- * Used by `debugEffect` to detect which sources changed between runs.
65
- * No-op if called outside an active tracking context.
66
- */
67
- export declare const withSourceObserver: <T>(observer: SourceObserver, fn: () => T) => T;
68
- /**
69
- * Runs `fn` without recording any reactive reads as dependencies of the enclosing
70
- * effect or computed. Useful when you need to read reactive state "silently".
71
- *
72
- * @example
73
- * ```ts
74
- * effect(() => {
75
- * const a = count.value; // tracked
76
- * const b = untrack(() => name.value); // NOT tracked — no re-run when name changes
77
- * });
78
- * ```
79
- */
80
- export declare const untrack: <T>(fn: () => T) => T;
81
- export declare const trackSource: (source: ReactiveBase<unknown>) => void;
82
- //# sourceMappingURL=tracking.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracking.d.ts","sourceRoot":"","sources":["../src/tracking.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAClE,OAAO,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAUrD,eAAO,MAAM,YAAY,QAAO,MAA0B,CAAC;AAC3D,eAAO,MAAM,WAAW,QAAO,MAAwB,CAAC;AAIxD,MAAM,MAAM,QAAQ,GAAG;IACrB,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;CACjB,CAAC;AAEF,2FAA2F;AAC3F,MAAM,MAAM,cAAc,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC,OAAO,CAAC,KAAK,IAAI,CAAC;AAOrE,MAAM,MAAM,WAAW,GAAG;IACxB,cAAc,CAAC,EAAE,cAAc,CAAC;CACjC,GAAG,CACA;IACE,QAAQ,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC;IAChC,YAAY,EAAE,QAAQ,EAAE,CAAC;IACzB,IAAI,EAAE,UAAU,CAAC;CAClB,GACD;IACE,QAAQ,EAAE,SAAS,EAAE,CAAC;IACtB,IAAI,EAAE,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;IACzC,MAAM,EAAE,UAAU,CAAC;IACnB,IAAI,EAAE,QAAQ,CAAC;IACf,aAAa,EAAE,GAAG,CAAC,SAAS,CAAC,CAAC;CAC/B,CACJ,CAAC;AAiBF,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,oBAAoB,EAAE,GAAG,CAAC,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;IAC1D,QAAQ,CAAC,kBAAkB,EAAE,GAAG,CAAC,UAAU,CAAC,CAAC;CAC9C,CAAC;AAEF,eAAO,MAAM,qBAAqB,QAAO,eAMvC,CAAC;AASH,MAAM,MAAM,gBAAgB,GAAG;IAC7B,QAAQ,CAAC,UAAU,EAAE,eAAe,CAAC;IACrC,QAAQ,CAAC,aAAa,EAAE,SAAS,EAAE,GAAG,IAAI,CAAC;IAC3C,QAAQ,CAAC,QAAQ,EAAE,WAAW,GAAG,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACxB,GAAG,IAAI,gBAAgB,CAAC;IACxB,GAAG,CAAC,CAAC,EAAE,GAAG,EAAE,gBAAgB,EAAE,EAAE,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC;CAC/C,CAAC;AAOF,iHAAiH;AACjH,eAAO,MAAM,kBAAkB,QAAO,eAAsC,CAAC;AAE7E,gGAAgG;AAChG,eAAO,MAAM,cAAc,QAAO,OAAyB,CAAC;AAI5D,eAAO,MAAM,WAAW,QAAO,WAAW,GAAG,IAAyB,CAAC;AAEvE,eAAO,MAAM,YAAY,GAAI,CAAC,EAAE,UAAU,WAAW,GAAG,IAAI,EAAE,IAAI,MAAM,CAAC,KAAG,CAgB3E,CAAC;AAIF;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,GAAI,CAAC,EAAE,UAAU,SAAS,EAAE,EAAE,IAAI,MAAM,CAAC,KAAG,CAgBzE,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,gBAAgB,QAAO,SAAS,EAAE,GAAG,IAA8B,CAAC;AAkBjF;;;GAGG;AACH,eAAO,MAAM,oBAAoB,GAAI,SAAS,SAAS,KAAG,IAQzD,CAAC;AAuBF;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,GAAI,CAAC,EAAE,UAAU,cAAc,EAAE,IAAI,MAAM,CAAC,KAAG,CAM7E,CAAC;AAIF;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,OAAO,GAAI,CAAC,EAAE,IAAI,MAAM,CAAC,KAAG,CAA2B,CAAC;AAWrE,eAAO,MAAM,WAAW,GAAI,QAAQ,YAAY,CAAC,OAAO,CAAC,KAAG,IAgB3D,CAAC"}
package/dist/tracking.js DELETED
@@ -1,76 +0,0 @@
1
- //#region src/tracking.ts
2
- var e = 0, t = () => ++e, n = () => e, r = () => ({
3
- activeDirty: "a",
4
- batchDepth: 0,
5
- dirtyWithEffectSubsA: /* @__PURE__ */ new Set(),
6
- dirtyWithEffectSubsB: /* @__PURE__ */ new Set(),
7
- pendingSubscribers: /* @__PURE__ */ new Set()
8
- }), i = {
9
- scheduling: r(),
10
- scopeCleanups: null,
11
- tracking: null
12
- }, a = null, o = () => a === null ? i : a.get(), s = () => o().scheduling, c = () => a !== null, l = () => o().tracking, u = (e, t) => {
13
- if (a !== null) {
14
- let n = a.get();
15
- return a.run({
16
- ...n,
17
- tracking: e
18
- }, t);
19
- }
20
- let n = i;
21
- i = {
22
- ...i,
23
- tracking: e
24
- };
25
- try {
26
- return t();
27
- } finally {
28
- i = n;
29
- }
30
- }, d = (e, t) => {
31
- if (a !== null) {
32
- let n = a.get();
33
- return a.run({
34
- ...n,
35
- scopeCleanups: e
36
- }, t);
37
- }
38
- let n = i;
39
- i = {
40
- ...i,
41
- scopeCleanups: e
42
- };
43
- try {
44
- return t();
45
- } finally {
46
- i = n;
47
- }
48
- }, f = () => o().scopeCleanups, p = (e) => {
49
- let t = l();
50
- t?.kind === "effect" ? t.cleanups.push(e) : f()?.push(e);
51
- }, m = (e) => {
52
- let t = a;
53
- return a = e, t;
54
- }, h = (e, t) => {
55
- let n = l();
56
- return n === null ? t() : u({
57
- ...n,
58
- sourceObserver: e
59
- }, t);
60
- }, g = (e) => u(null, e), _ = (e) => {
61
- let t = l();
62
- if (t !== null) {
63
- if (t.sourceObserver?.(e), t.kind === "computed") t.depCollector.push({
64
- source: e,
65
- version: e.version
66
- });
67
- else if (t.kind === "effect") {
68
- let n = t.effect;
69
- e.addEffectSub(n), t.subscriptions.add(() => e.removeEffectSub(n)), t.deps.set(e, e.version);
70
- }
71
- }
72
- };
73
- //#endregion
74
- export { m as _installContextHook, p as autoRegisterDisposal, r as createSchedulingState, n as getRevision, s as getSchedulingState, f as getScopeCleanups, l as getTracking, c as hasContextHook, t as tickRevision, _ as trackSource, g as untrack, d as withScopeCleanups, h as withSourceObserver, u as withTracking };
75
-
76
- //# sourceMappingURL=tracking.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"tracking.js","names":[],"sources":["../src/tracking.ts"],"sourcesContent":["import type { ComputedBase, ReactiveBase } from './reactive-base';\nimport type { CleanupFn, Subscriber } from './types';\n\n// ── Global revision clock ─────────────────────────────────────────────────────\n//\n// Monotonically-increasing counter incremented on every signal write.\n// ComputedImpl records the clock value after each successful recompute and uses\n// it as an O(1) \"nothing has changed globally\" fast-path check in refreshIfDirty.\n\nlet globalRevision = 0;\n\nexport const tickRevision = (): number => ++globalRevision;\nexport const getRevision = (): number => globalRevision;\n\n// ── Internal types ────────────────────────────────────────────────────────────\n\nexport type DepEntry = {\n source: ReactiveBase<unknown>;\n version: number;\n};\n\n/** Called by trackSource to observe each reactive source accessed during a tracked run. */\nexport type SourceObserver = (source: ReactiveBase<unknown>) => void;\n\n// TrackingCtx carries both dep-collection state AND an optional sourceObserver.\n// Putting the observer inside the context (R12) scopes it to the specific effect/computed\n// run rather than making it a process-wide global — nested computed recomputes use their\n// own context (no observer), so the debugEffect pattern works without identity checks.\n// sourceObserver is shared across both branches and lives outside the discriminant union.\nexport type TrackingCtx = {\n sourceObserver?: SourceObserver;\n} & (\n | {\n computed: ComputedBase<unknown>;\n depCollector: DepEntry[];\n kind: 'computed';\n }\n | {\n cleanups: CleanupFn[];\n deps: Map<ReactiveBase<unknown>, number>;\n effect: Subscriber;\n kind: 'effect';\n subscriptions: Set<CleanupFn>;\n }\n);\n\n// ── Scheduling state ────────────────────────────────────────────────────────\n//\n// Colocated here (rather than in scheduling.ts) so it can be a field of\n// ExecutionContext without a runtime circular import between tracking.ts and\n// scheduling.ts — scheduling.ts only needs `getSchedulingState()` and the\n// `SchedulingState` type (type-only import, erased at compile time).\n//\n// Isolating this per-request (via the SSR hook) closes the documented gap where\n// concurrent SSR requests share one flush queue: `batchDepth`, `pendingSubscribers`,\n// and the dirty-computed sets are the only scheduling fields that can observably\n// leak across requests (they persist across `await` boundaries via `batch()`\n// spanning shared module-level signals). The propagation epoch/stack in\n// scheduling.ts stay module-level scratch memory — they're only touched within a\n// single synchronous call stack, which JS's run-to-completion model already isolates.\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// ── ExecutionContext ──────────────────────────────────────────────────────────\n//\n// Unified context replaces two separate globals (_tracking and _scopeStack).\n// Both the dep-tracking context and the innermost scope's cleanup array live here.\n// The SSR hook overrides the entire context per-request — fixing the prior bug\n// where scope cleanups were always a process-wide singleton even with the hook.\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\nconst getCtx = (): ExecutionContext => (_hook !== null ? _hook.get() : _ctx);\n\n/** Returns the scheduling-state bucket for the active execution context (module-level singleton outside SSR). */\nexport const getSchedulingState = (): SchedulingState => getCtx().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// ── Tracking ──────────────────────────────────────────────────────────────────\n\nexport const getTracking = (): TrackingCtx | null => getCtx().tracking;\n\nexport const withTracking = <T>(tracking: TrackingCtx | null, fn: () => T): T => {\n if (_hook !== null) {\n const current = _hook.get();\n\n return _hook.run({ ...current, tracking }, fn);\n }\n\n const prev = _ctx;\n\n _ctx = { ..._ctx, tracking };\n\n try {\n return fn();\n } finally {\n _ctx = prev;\n }\n};\n\n// ── Scope cleanup ─────────────────────────────────────────────────────────────\n\n/**\n * Pushes `cleanups` as the active scope cleanup array for the duration of `fn`.\n * Any `onCleanup()` calls inside `fn` will register into these cleanups.\n * Effects and computed values created inside `fn` are also auto-registered.\n */\nexport const withScopeCleanups = <T>(cleanups: CleanupFn[], fn: () => T): T => {\n if (_hook !== null) {\n const current = _hook.get();\n\n return _hook.run({ ...current, scopeCleanups: cleanups }, fn);\n }\n\n const prev = _ctx;\n\n _ctx = { ..._ctx, scopeCleanups: cleanups };\n\n try {\n return fn();\n } finally {\n _ctx = prev;\n }\n};\n\n/**\n * Returns the cleanup array of the innermost active scope, or `null` if not inside a scope.\n */\nexport const getScopeCleanups = (): CleanupFn[] | null => getCtx().scopeCleanups;\n\n// ── Auto-disposal ───────────────────────────────────────────────────────────────\n//\n// Shared by every primitive that ties its own lifetime to the context it was\n// created in (computed(), resource()): dispose when the enclosing effect re-runs\n// or disposes, or — if not inside an effect — when the enclosing scope disposes.\n// No-op if neither is active (the caller owns disposal directly).\n//\n// Why signal() and store() don't call this: computed()/resource() are *derived*\n// computations — recreating one on every effect re-run is normal and cheap, so\n// tying their lifetime to the enclosing context avoids leaking a fresh graph\n// node per run. signal()/store() hold raw, caller-owned state that is typically\n// created once and read across many effect re-runs; auto-disposing it on the\n// first re-run would silently break any effect that reads a signal it declared\n// itself. Callers who genuinely want scope-scoped state should use\n// `scope.add(() => mySignal.dispose())` explicitly.\n\n/**\n * Registers `dispose` to run when the enclosing effect re-runs/disposes, or —\n * if there is no enclosing effect — when the enclosing scope disposes.\n */\nexport const autoRegisterDisposal = (dispose: CleanupFn): void => {\n const ctx = getTracking();\n\n if (ctx?.kind === 'effect') {\n ctx.cleanups.push(dispose);\n } else {\n getScopeCleanups()?.push(dispose);\n }\n};\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\n// ── Source observer ───────────────────────────────────────────────────────────\n//\n// Observer is now scoped to the active TrackingCtx instead of a process-wide global.\n// This means it only fires for direct deps of the current effect/computed — nested\n// computed recomputes use their own context (no observer) so no identity check needed.\n\n/**\n * Runs `fn` while calling `observer` for every reactive source directly accessed.\n * Used by `debugEffect` to detect which sources changed between runs.\n * No-op if called outside an active tracking context.\n */\nexport const withSourceObserver = <T>(observer: SourceObserver, fn: () => T): T => {\n const current = getTracking();\n\n if (current === null) return fn();\n\n return withTracking({ ...current, sourceObserver: observer }, fn);\n};\n\n// ── untrack ───────────────────────────────────────────────────────────────────\n\n/**\n * Runs `fn` without recording any reactive reads as dependencies of the enclosing\n * effect or computed. Useful when you need to read reactive state \"silently\".\n *\n * @example\n * ```ts\n * effect(() => {\n * const a = count.value; // tracked\n * const b = untrack(() => name.value); // NOT tracked — no re-run when name changes\n * });\n * ```\n */\nexport const untrack = <T>(fn: () => T): T => withTracking(null, fn);\n\n// ── trackSource ───────────────────────────────────────────────────────────────\n//\n// Records `source` as a dependency of the currently active tracking context.\n// For computed contexts: only records the dep entry — addComputedSub is called\n// later by updateDeps() in computed.ts (only for genuinely NEW deps, preventing\n// duplicate WeakRef entries).\n// For effect contexts: immediately subscribes the effect to the source and\n// records the dep for getDependencies().\n\nexport const trackSource = (source: ReactiveBase<unknown>): void => {\n const ctx = getTracking();\n\n if (ctx === null) return;\n\n ctx.sourceObserver?.(source);\n\n if (ctx.kind === 'computed') {\n ctx.depCollector.push({ source, version: source.version });\n } else if (ctx.kind === 'effect') {\n const owner = ctx.effect;\n\n source.addEffectSub(owner);\n ctx.subscriptions.add(() => source.removeEffectSub(owner));\n ctx.deps.set(source, source.version);\n }\n};\n"],"mappings":";AASA,IAAI,IAAiB,GAER,UAA6B,EAAE,GAC/B,UAA4B,GAyD5B,WAAgD;CAC3D,aAAa;CACb,YAAY;CACZ,sCAAsB,IAAI,IAAI;CAC9B,sCAAsB,IAAI,IAAI;CAC9B,oCAAoB,IAAI,IAAI;AAC9B,IAoBI,IAAyB;CAAE,YAAY,EAAsB;CAAG,eAAe;CAAM,UAAU;AAAK,GACpG,IAA4B,MAE1B,UAAkC,MAAU,OAAqB,IAAd,EAAM,IAAI,GAGtD,UAA4C,EAAO,CAAC,CAAC,YAGrD,UAAgC,MAAU,MAI1C,UAAwC,EAAO,CAAC,CAAC,UAEjD,KAAmB,GAA8B,MAAmB;CAC/E,IAAI,MAAU,MAAM;EAClB,IAAM,IAAU,EAAM,IAAI;EAE1B,OAAO,EAAM,IAAI;GAAE,GAAG;GAAS;EAAS,GAAG,CAAE;CAC/C;CAEA,IAAM,IAAO;CAEb,IAAO;EAAE,GAAG;EAAM;CAAS;CAE3B,IAAI;EACF,OAAO,EAAG;CACZ,UAAU;EACR,IAAO;CACT;AACF,GASa,KAAwB,GAAuB,MAAmB;CAC7E,IAAI,MAAU,MAAM;EAClB,IAAM,IAAU,EAAM,IAAI;EAE1B,OAAO,EAAM,IAAI;GAAE,GAAG;GAAS,eAAe;EAAS,GAAG,CAAE;CAC9D;CAEA,IAAM,IAAO;CAEb,IAAO;EAAE,GAAG;EAAM,eAAe;CAAS;CAE1C,IAAI;EACF,OAAO,EAAG;CACZ,UAAU;EACR,IAAO;CACT;AACF,GAKa,UAA6C,EAAO,CAAC,CAAC,eAsBtD,KAAwB,MAA6B;CAChE,IAAM,IAAM,EAAY;CAExB,AAAI,GAAK,SAAS,WAChB,EAAI,SAAS,KAAK,CAAO,IAEzB,EAAiB,CAAC,EAAE,KAAK,CAAO;AAEpC,GASa,KAAuB,MAAiD;CACnF,IAAM,IAAO;CAIb,OAFA,IAAQ,GAED;AACT,GAaa,KAAyB,GAA0B,MAAmB;CACjF,IAAM,IAAU,EAAY;CAI5B,OAFI,MAAY,OAAa,EAAG,IAEzB,EAAa;EAAE,GAAG;EAAS,gBAAgB;CAAS,GAAG,CAAE;AAClE,GAgBa,KAAc,MAAmB,EAAa,MAAM,CAAE,GAWtD,KAAe,MAAwC;CAClE,IAAM,IAAM,EAAY;CAEpB,UAAQ,MAIZ;MAFA,EAAI,iBAAiB,CAAM,GAEvB,EAAI,SAAS,YACf,EAAI,aAAa,KAAK;GAAE;GAAQ,SAAS,EAAO;EAAQ,CAAC;OACpD,IAAI,EAAI,SAAS,UAAU;GAChC,IAAM,IAAQ,EAAI;GAIlB,AAFA,EAAO,aAAa,CAAK,GACzB,EAAI,cAAc,UAAU,EAAO,gBAAgB,CAAK,CAAC,GACzD,EAAI,KAAK,IAAI,GAAQ,EAAO,OAAO;EACrC;;AACF"}
@@ -1,2 +0,0 @@
1
- const e=require("./tracking.cjs"),t=require("./symbols.cjs");var n=e=>({get disposed(){return e.disposed},[t.IS_SIGNAL]:!0,get name(){return e.name},peek(){return e.peek()},subscribe(t){return e.subscribe(t)},get value(){return e.value}}),r=e=>typeof e==`object`&&!!e&&!!e[t.IS_SIGNAL],i=e=>r(e)&&!e[t.IS_COMPUTED]&&!e[t.IS_STORE],a=e=>typeof e==`object`&&!!e&&!!e[t.IS_COMPUTED],o=e=>typeof e==`object`&&!!e&&!!e[t.IS_STORE];exports.isComputed=a,exports.isReactive=r,exports.isSignal=i,exports.isStore=o,exports.readonly=n,exports.untrack=e.untrack;
2
- //# sourceMappingURL=utilities.cjs.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilities.cjs","names":[],"sources":["../src/utilities.ts"],"sourcesContent":["import type { Computed, Readable, Signal } from './types';\n\nimport { IS_COMPUTED, IS_SIGNAL, IS_STORE } from './symbols';\nimport { untrack } from './tracking';\n\nexport { untrack };\n\n// ── Readonly wrapper ──────────────────────────────────────────────────────────\n//\n// readonly() returns Readable<T> — no dispose() because the wrapper does not\n// own the source. Callers retain ownership and must dispose the source themselves.\n// The [IS_SIGNAL] brand is set so isReactive(readonly(s)) and isSignal(readonly(s))\n// both return true (it is reactive, not IS_COMPUTED, not IS_STORE).\n// [IS_COMPUTED] is intentionally NOT set — the wrapper is not a Computed<T>\n// and does not have dispose().\n\n/**\n * Wraps a reactive value to produce a structurally read-only view.\n * The `value` setter is hidden. Delegates reads directly to the source —\n * no extra reactive graph node, no extra subscription.\n *\n * The caller retains ownership of the source and is responsible for disposing it.\n *\n * @example\n * ```ts\n * const count = signal(0);\n * const readCount = readonly(count);\n * readCount.value; // fine — tracks dep on count\n * // readCount.value = 1; // TypeScript error — Readable has no setter\n * ```\n */\nexport const readonly = <T>(source: Readable<T>): Readable<T> => {\n const wrapper = {\n get disposed(): boolean {\n return source.disposed;\n },\n [IS_SIGNAL]: true as const,\n get name(): string | undefined {\n return source.name;\n },\n peek(): T {\n return source.peek();\n },\n subscribe(listener: () => void) {\n return source.subscribe(listener);\n },\n get value(): T {\n return source.value;\n },\n };\n\n return wrapper as unknown as Readable<T>;\n};\n\n// ── Type guards ───────────────────────────────────────────────────────────────\n\n/**\n * Returns `true` for any reactive value that implements `Readable<T>` — including\n * `signal()`, `computed()`, `store()`, and `readonly()` wrappers.\n *\n * This is the broad \"is this value reactive?\" check. Use `isSignal` for writable-only\n * signals, or `isComputed` to narrow to computed values.\n *\n * @example\n * ```ts\n * isReactive(signal(0)) // true\n * isReactive(computed(() => 1)) // true\n * isReactive(store({ x: 0 })) // true\n * isReactive(readonly(signal(0))) // true\n * isReactive({}) // false\n * ```\n */\nexport const isReactive = <T = unknown>(value: unknown): value is Readable<T> =>\n typeof value === 'object' && value !== null && !!(value as Record<typeof IS_SIGNAL, unknown>)[IS_SIGNAL];\n\n/**\n * Returns `true` only for writable `Signal<T>` values — excludes `computed()` and `store()`.\n * `readonly()` wrappers of a signal still report `true` since they carry the same\n * `IS_SIGNAL` brand as their source (they are not `IS_COMPUTED`/`IS_STORE`).\n *\n * Use `isReactive` for the broad \"is this reactive?\" check.\n *\n * @example\n * ```ts\n * isSignal(signal(0)) // true\n * isSignal(computed(() => 1)) // false — computed excluded\n * isSignal(store({ x: 0 })) // false — store excluded\n * isSignal(readonly(signal(0))) // true — readonly has IS_SIGNAL, not IS_COMPUTED/IS_STORE\n * isSignal({}) // false\n * ```\n */\nexport const isSignal = <T = unknown>(value: unknown): value is Signal<T> =>\n isReactive(value) &&\n !(value as unknown as Record<typeof IS_COMPUTED, unknown>)[IS_COMPUTED] &&\n !(value as unknown as Record<typeof IS_STORE, unknown>)[IS_STORE];\n\nexport const isComputed = <T = unknown>(value: unknown): value is Computed<T> =>\n typeof value === 'object' && value !== null && !!(value as Record<typeof IS_COMPUTED, unknown>)[IS_COMPUTED];\n\nexport const isStore = <T extends object = object>(value: unknown): value is import('./types').Store<T> =>\n typeof value === 'object' && value !== null && !!(value as Record<typeof IS_STORE, unknown>)[IS_STORE];\n"],"mappings":"6DA+BA,IAAa,EAAe,IAoBnB,CAlBL,IAAI,UAAoB,CACtB,OAAO,EAAO,QAChB,GACC,EAAA,WAAY,GACb,IAAI,MAA2B,CAC7B,OAAO,EAAO,IAChB,EACA,MAAU,CACR,OAAO,EAAO,KAAK,CACrB,EACA,UAAU,EAAsB,CAC9B,OAAO,EAAO,UAAU,CAAQ,CAClC,EACA,IAAI,OAAW,CACb,OAAO,EAAO,KAChB,CAGK,GAqBI,EAA2B,GACtC,OAAO,GAAU,YAAY,GAAkB,CAAC,CAAE,EAA4C,EAAA,WAkBnF,EAAyB,GACpC,EAAW,CAAK,GAChB,CAAE,EAAyD,EAAA,cAC3D,CAAE,EAAsD,EAAA,UAE7C,EAA2B,GACtC,OAAO,GAAU,YAAY,GAAkB,CAAC,CAAE,EAA8C,EAAA,aAErF,EAAsC,GACjD,OAAO,GAAU,YAAY,GAAkB,CAAC,CAAE,EAA2C,EAAA"}
@@ -1,56 +0,0 @@
1
- import type { Computed, Readable, Signal } from './types';
2
- import { untrack } from './tracking';
3
- export { untrack };
4
- /**
5
- * Wraps a reactive value to produce a structurally read-only view.
6
- * The `value` setter is hidden. Delegates reads directly to the source —
7
- * no extra reactive graph node, no extra subscription.
8
- *
9
- * The caller retains ownership of the source and is responsible for disposing it.
10
- *
11
- * @example
12
- * ```ts
13
- * const count = signal(0);
14
- * const readCount = readonly(count);
15
- * readCount.value; // fine — tracks dep on count
16
- * // readCount.value = 1; // TypeScript error — Readable has no setter
17
- * ```
18
- */
19
- export declare const readonly: <T>(source: Readable<T>) => Readable<T>;
20
- /**
21
- * Returns `true` for any reactive value that implements `Readable<T>` — including
22
- * `signal()`, `computed()`, `store()`, and `readonly()` wrappers.
23
- *
24
- * This is the broad "is this value reactive?" check. Use `isSignal` for writable-only
25
- * signals, or `isComputed` to narrow to computed values.
26
- *
27
- * @example
28
- * ```ts
29
- * isReactive(signal(0)) // true
30
- * isReactive(computed(() => 1)) // true
31
- * isReactive(store({ x: 0 })) // true
32
- * isReactive(readonly(signal(0))) // true
33
- * isReactive({}) // false
34
- * ```
35
- */
36
- export declare const isReactive: <T = unknown>(value: unknown) => value is Readable<T>;
37
- /**
38
- * Returns `true` only for writable `Signal<T>` values — excludes `computed()` and `store()`.
39
- * `readonly()` wrappers of a signal still report `true` since they carry the same
40
- * `IS_SIGNAL` brand as their source (they are not `IS_COMPUTED`/`IS_STORE`).
41
- *
42
- * Use `isReactive` for the broad "is this reactive?" check.
43
- *
44
- * @example
45
- * ```ts
46
- * isSignal(signal(0)) // true
47
- * isSignal(computed(() => 1)) // false — computed excluded
48
- * isSignal(store({ x: 0 })) // false — store excluded
49
- * isSignal(readonly(signal(0))) // true — readonly has IS_SIGNAL, not IS_COMPUTED/IS_STORE
50
- * isSignal({}) // false
51
- * ```
52
- */
53
- export declare const isSignal: <T = unknown>(value: unknown) => value is Signal<T>;
54
- export declare const isComputed: <T = unknown>(value: unknown) => value is Computed<T>;
55
- export declare const isStore: <T extends object = object>(value: unknown) => value is import("./types").Store<T>;
56
- //# sourceMappingURL=utilities.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilities.d.ts","sourceRoot":"","sources":["../src/utilities.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AAG1D,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAErC,OAAO,EAAE,OAAO,EAAE,CAAC;AAWnB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,EAAE,QAAQ,QAAQ,CAAC,CAAC,CAAC,KAAG,QAAQ,CAAC,CAAC,CAqB3D,CAAC;AAIF;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,UAAU,GAAI,CAAC,GAAG,OAAO,EAAE,OAAO,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CAC8B,CAAC;AAE3G;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,QAAQ,GAAI,CAAC,GAAG,OAAO,EAAE,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,CAAC,CAGL,CAAC;AAEpE,eAAO,MAAM,UAAU,GAAI,CAAC,GAAG,OAAO,EAAE,OAAO,OAAO,KAAG,KAAK,IAAI,QAAQ,CAAC,CAAC,CACkC,CAAC;AAE/G,eAAO,MAAM,OAAO,GAAI,CAAC,SAAS,MAAM,GAAG,MAAM,EAAE,OAAO,OAAO,KAAG,KAAK,IAAI,OAAO,SAAS,EAAE,KAAK,CAAC,CAAC,CACE,CAAC"}
package/dist/utilities.js DELETED
@@ -1,25 +0,0 @@
1
- import { untrack as e } from "./tracking.js";
2
- import { IS_COMPUTED as t, IS_SIGNAL as n, IS_STORE as r } from "./symbols.js";
3
- //#region src/utilities.ts
4
- var i = (e) => ({
5
- get disposed() {
6
- return e.disposed;
7
- },
8
- [n]: !0,
9
- get name() {
10
- return e.name;
11
- },
12
- peek() {
13
- return e.peek();
14
- },
15
- subscribe(t) {
16
- return e.subscribe(t);
17
- },
18
- get value() {
19
- return e.value;
20
- }
21
- }), a = (e) => typeof e == "object" && !!e && !!e[n], o = (e) => a(e) && !e[t] && !e[r], s = (e) => typeof e == "object" && !!e && !!e[t], c = (e) => typeof e == "object" && !!e && !!e[r];
22
- //#endregion
23
- export { s as isComputed, a as isReactive, o as isSignal, c as isStore, i as readonly, e as untrack };
24
-
25
- //# sourceMappingURL=utilities.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"utilities.js","names":[],"sources":["../src/utilities.ts"],"sourcesContent":["import type { Computed, Readable, Signal } from './types';\n\nimport { IS_COMPUTED, IS_SIGNAL, IS_STORE } from './symbols';\nimport { untrack } from './tracking';\n\nexport { untrack };\n\n// ── Readonly wrapper ──────────────────────────────────────────────────────────\n//\n// readonly() returns Readable<T> — no dispose() because the wrapper does not\n// own the source. Callers retain ownership and must dispose the source themselves.\n// The [IS_SIGNAL] brand is set so isReactive(readonly(s)) and isSignal(readonly(s))\n// both return true (it is reactive, not IS_COMPUTED, not IS_STORE).\n// [IS_COMPUTED] is intentionally NOT set — the wrapper is not a Computed<T>\n// and does not have dispose().\n\n/**\n * Wraps a reactive value to produce a structurally read-only view.\n * The `value` setter is hidden. Delegates reads directly to the source —\n * no extra reactive graph node, no extra subscription.\n *\n * The caller retains ownership of the source and is responsible for disposing it.\n *\n * @example\n * ```ts\n * const count = signal(0);\n * const readCount = readonly(count);\n * readCount.value; // fine — tracks dep on count\n * // readCount.value = 1; // TypeScript error — Readable has no setter\n * ```\n */\nexport const readonly = <T>(source: Readable<T>): Readable<T> => {\n const wrapper = {\n get disposed(): boolean {\n return source.disposed;\n },\n [IS_SIGNAL]: true as const,\n get name(): string | undefined {\n return source.name;\n },\n peek(): T {\n return source.peek();\n },\n subscribe(listener: () => void) {\n return source.subscribe(listener);\n },\n get value(): T {\n return source.value;\n },\n };\n\n return wrapper as unknown as Readable<T>;\n};\n\n// ── Type guards ───────────────────────────────────────────────────────────────\n\n/**\n * Returns `true` for any reactive value that implements `Readable<T>` — including\n * `signal()`, `computed()`, `store()`, and `readonly()` wrappers.\n *\n * This is the broad \"is this value reactive?\" check. Use `isSignal` for writable-only\n * signals, or `isComputed` to narrow to computed values.\n *\n * @example\n * ```ts\n * isReactive(signal(0)) // true\n * isReactive(computed(() => 1)) // true\n * isReactive(store({ x: 0 })) // true\n * isReactive(readonly(signal(0))) // true\n * isReactive({}) // false\n * ```\n */\nexport const isReactive = <T = unknown>(value: unknown): value is Readable<T> =>\n typeof value === 'object' && value !== null && !!(value as Record<typeof IS_SIGNAL, unknown>)[IS_SIGNAL];\n\n/**\n * Returns `true` only for writable `Signal<T>` values — excludes `computed()` and `store()`.\n * `readonly()` wrappers of a signal still report `true` since they carry the same\n * `IS_SIGNAL` brand as their source (they are not `IS_COMPUTED`/`IS_STORE`).\n *\n * Use `isReactive` for the broad \"is this reactive?\" check.\n *\n * @example\n * ```ts\n * isSignal(signal(0)) // true\n * isSignal(computed(() => 1)) // false — computed excluded\n * isSignal(store({ x: 0 })) // false — store excluded\n * isSignal(readonly(signal(0))) // true — readonly has IS_SIGNAL, not IS_COMPUTED/IS_STORE\n * isSignal({}) // false\n * ```\n */\nexport const isSignal = <T = unknown>(value: unknown): value is Signal<T> =>\n isReactive(value) &&\n !(value as unknown as Record<typeof IS_COMPUTED, unknown>)[IS_COMPUTED] &&\n !(value as unknown as Record<typeof IS_STORE, unknown>)[IS_STORE];\n\nexport const isComputed = <T = unknown>(value: unknown): value is Computed<T> =>\n typeof value === 'object' && value !== null && !!(value as Record<typeof IS_COMPUTED, unknown>)[IS_COMPUTED];\n\nexport const isStore = <T extends object = object>(value: unknown): value is import('./types').Store<T> =>\n typeof value === 'object' && value !== null && !!(value as Record<typeof IS_STORE, unknown>)[IS_STORE];\n"],"mappings":";;;AA+BA,IAAa,KAAe,OAoBnB;CAlBL,IAAI,WAAoB;EACtB,OAAO,EAAO;CAChB;EACC,IAAY;CACb,IAAI,OAA2B;EAC7B,OAAO,EAAO;CAChB;CACA,OAAU;EACR,OAAO,EAAO,KAAK;CACrB;CACA,UAAU,GAAsB;EAC9B,OAAO,EAAO,UAAU,CAAQ;CAClC;CACA,IAAI,QAAW;EACb,OAAO,EAAO;CAChB;AAGK,IAqBI,KAA2B,MACtC,OAAO,KAAU,cAAY,KAAkB,CAAC,CAAE,EAA4C,IAkBnF,KAAyB,MACpC,EAAW,CAAK,KAChB,CAAE,EAAyD,MAC3D,CAAE,EAAsD,IAE7C,KAA2B,MACtC,OAAO,KAAU,cAAY,KAAkB,CAAC,CAAE,EAA8C,IAErF,KAAsC,MACjD,OAAO,KAAU,cAAY,KAAkB,CAAC,CAAE,EAA2C"}