@getforma/core 1.4.0 → 1.5.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.
- package/dist/{chunk-AJP4OVCN.js → chunk-3U2IQIKB.js} +4 -4
- package/dist/{chunk-AJP4OVCN.js.map → chunk-3U2IQIKB.js.map} +1 -1
- package/dist/{chunk-FBM7V4NE.cjs → chunk-D46EJ3VS.cjs} +43 -43
- package/dist/{chunk-FBM7V4NE.cjs.map → chunk-D46EJ3VS.cjs.map} +1 -1
- package/dist/{chunk-Y3A2EVVS.js → chunk-F5QUU76U.js} +4 -4
- package/dist/{chunk-Y3A2EVVS.js.map → chunk-F5QUU76U.js.map} +1 -1
- package/dist/{chunk-ETPJTPYD.js → chunk-FAIWRZKJ.js} +6 -3
- package/dist/chunk-FAIWRZKJ.js.map +1 -0
- package/dist/{chunk-H7MDUHS5.cjs → chunk-HAULTMNX.cjs} +6 -2
- package/dist/chunk-HAULTMNX.cjs.map +1 -0
- package/dist/{chunk-KUXNZ5MG.cjs → chunk-PAKPQRVE.cjs} +14 -12
- package/dist/{chunk-KUXNZ5MG.cjs.map → chunk-PAKPQRVE.cjs.map} +1 -1
- package/dist/formajs.global.js +69 -11
- package/dist/formajs.global.js.map +1 -1
- package/dist/http.cjs +11 -11
- package/dist/http.js +2 -2
- package/dist/index.cjs +143 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +39 -5
- package/dist/index.d.ts +39 -5
- package/dist/index.js +67 -16
- package/dist/index.js.map +1 -1
- package/dist/{resource-D6HfVgiA.d.cts → resource-CBTcorBJ.d.ts} +2 -2
- package/dist/{resource-ljs2X5NM.d.ts → resource-CaFfIB5i.d.cts} +2 -2
- package/dist/runtime.cjs +28 -28
- package/dist/runtime.js +3 -3
- package/dist/server.cjs +7 -7
- package/dist/server.d.cts +2 -2
- package/dist/server.d.ts +2 -2
- package/dist/server.js +2 -2
- package/dist/{signal-CRBJYQ6B.d.cts → signal-CIXTR4Qz.d.cts} +29 -1
- package/dist/{signal-CRBJYQ6B.d.ts → signal-CIXTR4Qz.d.ts} +29 -1
- package/dist/storage.cjs +66 -16
- package/dist/storage.cjs.map +1 -1
- package/dist/storage.js +66 -16
- package/dist/storage.js.map +1 -1
- package/dist/tc39-compat.cjs +3 -3
- package/dist/tc39-compat.d.cts +1 -1
- package/dist/tc39-compat.d.ts +1 -1
- package/dist/tc39-compat.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-ETPJTPYD.js.map +0 -1
- package/dist/chunk-H7MDUHS5.cjs.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createComputed, createSignal, reportError } from './chunk-
|
|
1
|
+
import { createComputed, createSignal, reportError } from './chunk-FAIWRZKJ.js';
|
|
2
2
|
import { effect, startBatch, endBatch, setActiveSub, getActiveSub, effectScope } from 'alien-signals';
|
|
3
3
|
export { getBatchDepth, isComputed, isEffect, isEffectScope, isSignal, trigger } from 'alien-signals';
|
|
4
4
|
|
|
@@ -405,6 +405,6 @@ function createResource(source, fetcher, options) {
|
|
|
405
405
|
return resource;
|
|
406
406
|
}
|
|
407
407
|
|
|
408
|
-
export { batch, createEffect, createMemo, createReducer, createRef, createResource, createRoot, createUnownedRoot, internalEffect, on, onCleanup, popSuspenseContext, pushSuspenseContext, registerDisposer, untrack };
|
|
409
|
-
//# sourceMappingURL=chunk-
|
|
410
|
-
//# sourceMappingURL=chunk-
|
|
408
|
+
export { batch, createEffect, createMemo, createReducer, createRef, createResource, createRoot, createUnownedRoot, getOwner, internalEffect, on, onCleanup, popSuspenseContext, pushSuspenseContext, registerDisposer, runWithOwner, untrack };
|
|
409
|
+
//# sourceMappingURL=chunk-F5QUU76U.js.map
|
|
410
|
+
//# sourceMappingURL=chunk-F5QUU76U.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/reactive/root.ts","../src/reactive/cleanup.ts","../src/reactive/effect.ts","../src/reactive/memo.ts","../src/reactive/batch.ts","../src/reactive/untrack.ts","../src/reactive/on.ts","../src/reactive/ref.ts","../src/reactive/reducer.ts","../src/reactive/suspense-context.ts","../src/reactive/resource.ts"],"names":["rawEffectScope","rawEffect","setActiveSub","value"],"mappings":";;;;AAsBA,IAAI,WAAA,GAAgC,IAAA;AACpC,IAAM,YAAkC,EAAC;AAsBzC,IAAI,YAAA,GAA6B,IAAA;AAG1B,SAAS,QAAA,GAAyB;AACvC,EAAA,OAAO,YAAA;AACT;AAOO,SAAS,YAAA,CAAgB,OAAqB,EAAA,EAAgB;AACnE,EAAA,MAAM,IAAA,GAAO,YAAA;AACb,EAAA,YAAA,GAAe,KAAA;AACf,EAAA,IAAI;AACF,IAAA,OAAO,EAAA,EAAG;AAAA,EACZ,CAAA,SAAE;AACA,IAAA,YAAA,GAAe,IAAA;AAAA,EACjB;AACF;AAGO,SAAS,qBAAA,CAAsB,OAAc,OAAA,EAA2B;AAC7E,EAAA,KAAA,CAAM,SAAA,CAAU,KAAK,OAAO,CAAA;AAC9B;AAGO,SAAS,gBAAA,GAA0B;AACxC,EAAA,OAAO,EAAE,SAAA,EAAW,EAAC,EAAE;AACzB;AAGO,SAAS,aAAa,KAAA,EAAoB;AAC/C,EAAA,MAAM,KAAK,KAAA,CAAM,SAAA;AACjB,EAAA,KAAA,MAAW,KAAK,EAAA,EAAI;AAClB,IAAA,IAAI;AAAE,MAAA,CAAA,EAAE;AAAA,IAAG,CAAA,CAAA,MAAQ;AAAA,IAAiC;AAAA,EACtD;AACA,EAAA,EAAA,CAAG,MAAA,GAAS,CAAA;AACd;AAMA,SAAS,cAAA,CAAkB,IAAgC,KAAA,EAAmB;AAC5E,EAAA,MAAM,QAAmB,EAAE,SAAA,EAAW,EAAC,EAAG,cAAc,IAAA,EAAK;AAC7D,EAAA,MAAM,UAAA,GAAa,QAAQ,WAAA,GAAc,IAAA;AAEzC,EAAA,SAAA,CAAU,KAAK,WAAW,CAAA;AAC1B,EAAA,WAAA,GAAc,KAAA;AACd,EAAA,MA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ope. All effects created inside a root\n * are automatically disposed when the root is torn down.\n *\n * Uses alien-signals' `effectScope` under the hood for native graph-level\n * effect tracking, with a userland disposer list for non-effect cleanup\n * (e.g., event listeners, DOM references, timers).\n *\n * Roots created inside another root are automatically owned by the parent\n * (Solid-style). When the parent is disposed, all child roots are disposed\n * too. Use {@link createUnownedRoot} for roots that must outlive their\n * lexical parent (e.g., mount points, test harnesses).\n */\n\nimport { effectScope as rawEffectScope, setActiveSub } from 'alien-signals';\n\n// ---------------------------------------------------------------------------\n// Root scope tracking\n// ---------------------------------------------------------------------------\n\nlet currentRoot: RootScope | null = null;\nconst rootStack: (RootScope | null)[] = [];\n\n/**\n * The minimal ownership unit: something that holds disposers. A {@link RootScope}\n * is an Owner with an extra alien-signals scope dispose. Effects use lightweight\n * child owners (no scopeDispose) to own their nested effects generation-by-generation.\n */\nexport interface Owner {\n /** Disposers to run when this owner is torn down. */\n disposers: (() => void)[];\n}\n\ninterface RootScope extends Owner {\n /** alien-signals effect scope dispose — tears down all reactive effects */\n scopeDispose: (() => void) | null;\n}\n\n/**\n * The owner that new disposers register with. Inside a root this equals the\n * current {@link RootScope}; {@link runWithOwner} can temporarily point it at any\n * owner so work created outside the original synchronous scope is still owned.\n */\nlet currentOwner: Owner | null = null;\n\n/** @internal — the owner disposers currently register with (or null). */\nexport function getOwner(): Owner | null {\n return currentOwner;\n}\n\n/**\n * Run `fn` with `owner` installed as the current owner, restoring the previous\n * owner afterwards. Lets effects/roots created asynchronously (after the\n * original root callback returned) still be owned and disposed.\n */\nexport function runWithOwner<T>(owner: Owner | null, fn: () => T): T {\n const prev = currentOwner;\n currentOwner = owner;\n try {\n return fn();\n } finally {\n currentOwner = prev;\n }\n}\n\n/** @internal — register a disposer directly with a specific owner. */\nexport function registerOwnerDisposer(owner: Owner, dispose: () => void): void {\n owner.disposers.push(dispose);\n}\n\n/** @internal — a fresh lightweight owner (no alien scope). Used per effect run. */\nexport function createChildOwner(): Owner {\n return { disposers: [] };\n}\n\n/** @internal — run and clear an owner's disposers (guarded so one throw doesn't abort the rest). */\nexport function disposeOwner(owner: Owner): void {\n const ds = owner.disposers;\n for (const d of ds) {\n try { d(); } catch { /* ensure all disposers run */ }\n }\n ds.length = 0;\n}\n\n// ---------------------------------------------------------------------------\n// Shared implementation\n// ---------------------------------------------------------------------------\n\nfunction createRootImpl<T>(fn: (dispose: () => void) => T, owned: boolean): T {\n const scope: RootScope = { disposers: [], scopeDispose: null };\n const parentRoot = owned ? currentRoot : null;\n\n rootStack.push(currentRoot);\n currentRoot = scope;\n const prevOwner = currentOwner;\n currentOwner = scope;\n\n let disposed = false;\n let setupComplete = false;\n let disposeRequestedDuringSetup = false;\n\n const runDisposers = () => {\n // Run userland disposers (includes child root disposes), guarded so one\n // throw does not abort the rest. Draining means a later runTeardown only\n // sees disposers registered since this drain.\n for (const d of scope.disposers) {\n try { d(); } catch { /* ensure all disposers run */ }\n }\n scope.disposers.length = 0;\n };\n\n const runTeardown = () => {\n // Dispose alien-signals effect scope first (reactive graph cleanup)\n if (scope.scopeDispose) {\n try { scope.scopeDispose(); } catch { /* ensure userland disposers still run */ }\n scope.scopeDispose = null;\n }\n runDisposers();\n };\n\n const dispose = () => {\n if (disposed) return; // idempotent — safe to call after parent already disposed this\n disposed = true;\n // dispose() called synchronously DURING setup: scope.scopeDispose is not yet\n // assigned and anything created AFTER this call has not registered. Eagerly\n // run the disposers already registered (so cleanup for work created BEFORE\n // this call is synchronous, Solid-style), and defer the rest — the alien\n // scope dispose plus any after-created disposers — until setup finishes.\n // Without the deferral, everything created afterward would leak.\n if (!setupComplete) {\n disposeRequestedDuringSetup = true;\n runDisposers();\n return;\n }\n runTeardown();\n };\n\n // Auto-register with parent root so child dies when parent dies (Solid-style)\n if (parentRoot) {\n parentRoot.disposers.push(dispose);\n }\n\n let result: T;\n try {\n if (owned) {\n // Owned: alien-signals nesting is kept (belt + suspenders with Forma cascade)\n scope.scopeDispose = rawEffectScope(() => {\n result = fn(dispose);\n });\n } else {\n // Unowned: break alien-signals scope nesting so this scope is NOT\n // disposed when the lexical parent scope is disposed.\n const prevSub = setActiveSub(undefined);\n try {\n scope.scopeDispose = rawEffectScope(() => {\n result = fn(dispose);\n });\n } finally {\n setActiveSub(prevSub);\n }\n }\n // Setup finished: scope.scopeDispose is assigned and all in-setup effects /\n // child-roots have registered. If dispose() was requested during setup, run\n // the deferred teardown now so everything created in the callback is torn down.\n setupComplete = true;\n if (disposeRequestedDuringSetup) {\n runTeardown();\n }\n } finally {\n currentRoot = rootStack.pop() ?? null;\n currentOwner = prevOwner;\n }\n\n return result!;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Create a reactive root scope.\n *\n * All effects created (via `createEffect`) inside the callback are tracked\n * at both the reactive graph level (via alien-signals effectScope) and the\n * userland level (via registerDisposer). The returned `dispose` function\n * tears down everything.\n *\n * Roots created inside another root are automatically owned by the parent.\n * When the parent is disposed, this root is disposed too.\n *\n * ```ts\n * const dispose = createRoot(() => {\n * createEffect(() => console.log(count()));\n * createEffect(() => console.log(name()));\n * });\n * // later: dispose() stops both effects\n * ```\n */\nexport function createRoot<T>(fn: (dispose: () => void) => T): T {\n return createRootImpl(fn, true);\n}\n\n/**\n * Create a reactive root that is NOT owned by any parent root.\n *\n * Use this for roots that must outlive their lexical parent:\n * top-level mount points, island hydration, test harnesses, etc.\n *\n * ```ts\n * createRoot(() => {\n * // This root outlives the parent even though it's nested:\n * createUnownedRoot((dispose) => {\n * // effects here survive parent disposal\n * });\n * });\n * ```\n */\nexport function createUnownedRoot<T>(fn: (dispose: () => void) => T): T {\n return createRootImpl(fn, false);\n}\n\n/**\n * @internal — called by createEffect and DOM primitives to register disposers\n * with the current owner (a root scope, or an owner installed via runWithOwner).\n */\nexport function registerDisposer(dispose: () => void): void {\n if (currentOwner) {\n currentOwner.disposers.push(dispose);\n }\n}\n\n/**\n * @internal — check if we're inside an owner scope (root or runWithOwner).\n */\nexport function hasActiveRoot(): boolean {\n return currentOwner !== null;\n}\n","/**\n * Forma Reactive - Cleanup\n *\n * Register cleanup functions within reactive scopes.\n * Inspired by SolidJS onCleanup().\n */\n\n// ---------------------------------------------------------------------------\n// Cleanup context tracking\n// ---------------------------------------------------------------------------\n\ntype CleanupCollector = ((fn: () => void) => void) | null;\n\nlet currentCleanupCollector: CleanupCollector = null;\n\n/**\n * Register a cleanup function in the current reactive scope.\n * The cleanup runs before the effect re-executes and on disposal.\n *\n * More composable than returning a cleanup from the effect function,\n * since it can be called from helper functions.\n *\n * ```ts\n * createEffect(() => {\n * const timer = setInterval(tick, 1000);\n * onCleanup(() => clearInterval(timer));\n * });\n * ```\n */\nexport function onCleanup(fn: () => void): void {\n currentCleanupCollector?.(fn);\n}\n\n/**\n * @internal — Set the cleanup collector for the current effect execution.\n */\nexport function setCleanupCollector(collector: CleanupCollector): CleanupCollector {\n const prev = currentCleanupCollector;\n currentCleanupCollector = collector;\n return prev;\n}\n","/**\n * Forma Reactive - Effect\n *\n * Side-effectful reactive computation that auto-tracks signal dependencies.\n * Backed by alien-signals for automatic dependency tracking.\n *\n * TC39 Signals equivalent: Signal.subtle.Watcher (effect is a userland concept)\n */\n\nimport { effect as rawEffect, getActiveSub } from 'alien-signals';\nimport {\n hasActiveRoot,\n registerDisposer,\n getOwner,\n runWithOwner,\n registerOwnerDisposer,\n createChildOwner,\n disposeOwner,\n type Owner,\n} from './root.js';\nimport { setCleanupCollector } from './cleanup.js';\nimport { reportError } from './dev.js';\n\n// ---------------------------------------------------------------------------\n// Cleanup array pool — avoids allocating a new array every effect re-run\n// ---------------------------------------------------------------------------\n\nconst POOL_SIZE = 32;\nconst MAX_REENTRANT_RUNS = 100;\nconst pool: (() => void)[][] = [];\nfor (let i = 0; i < POOL_SIZE; i++) pool.push([]);\nlet poolIdx = POOL_SIZE;\n\n// ---------------------------------------------------------------------------\n// Self-write detection — alien-signals' propagate() never notifies a subscriber\n// that is currently running, so an effect writing a signal it depends on is left\n// stale. When that happens alien-signals still sets the Pending flag on the\n// running subscriber's node (but skips the re-run). We read that flag on the\n// EFFECT's own node after each run and loop, so a self-dependent effect\n// converges. Reading the effect's own node (not a global) makes this precise:\n// writes to signals the effect does not depend on, writes from a nested computed,\n// and a nested effect's self-write never set THIS node's Pending, so they cause\n// no spurious re-run. It also works through batch() (Pending is set at flush).\n// ---------------------------------------------------------------------------\n\n// alien-signals ReactiveFlags.Pending (not exported from the package root).\nconst PENDING = 32;\n\ninterface SubNode { flags: number; }\n\nfunction acquireArray(): (() => void)[] {\n if (poolIdx > 0) {\n const arr = pool[--poolIdx]!;\n arr.length = 0;\n return arr;\n }\n return [];\n}\n\nfunction releaseArray(arr: (() => void)[]): void {\n arr.length = 0;\n if (poolIdx < POOL_SIZE) {\n pool[poolIdx++] = arr;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Unified cleanup runner — single function for both re-run and dispose paths\n// ---------------------------------------------------------------------------\n\nfunction runCleanup(fn: (() => void) | undefined): void {\n if (fn === undefined) return;\n try {\n fn();\n } catch (e) {\n reportError(e, 'effect cleanup');\n }\n}\n\nfunction runCleanups(bag: (() => void)[] | undefined): void {\n if (bag === undefined) return;\n for (let i = 0; i < bag.length; i++) {\n try { bag[i]!(); } catch (e) { reportError(e, 'effect cleanup'); }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Create a reactive effect that auto-tracks signal dependencies.\n *\n * The provided function runs immediately and re-runs whenever any signal it\n * reads changes. If the function returns a cleanup function, that cleanup is\n * called before each re-run and on disposal.\n *\n * Additionally, `onCleanup()` can be called inside the effect to register\n * cleanup functions composably.\n *\n * Returns a dispose function that stops the effect.\n */\n/**\n * @internal — Lightweight effect for Forma's internal DOM bindings.\n *\n * Bypasses createEffect's cleanup infrastructure (pool, collector, error\n * reporting, engine compression) since internal effects never use\n * onCleanup() or return cleanup functions. This saves ~4 function calls\n * per effect creation and per re-run.\n *\n * ONLY use for effects that:\n * 1. Never call onCleanup()\n * 2. Never return a cleanup function\n * 3. Contain simple \"read signal → write DOM\" logic\n */\nexport function internalEffect(fn: () => void): () => void {\n const dispose = rawEffect(fn);\n if (hasActiveRoot()) {\n registerDisposer(dispose);\n }\n return dispose;\n}\n\nexport function createEffect(fn: () => void | (() => void)): () => void {\n // Capture the owner active at creation time so this effect's disposer is owned\n // by whatever created it — a root, or (for a nested effect) the parent effect's\n // current child-owner. This replaces a hasActiveRoot() snapshot so nested\n // effects created during a parent re-run (when no root is lexically active) are\n // still owned and disposed.\n const ownerAtCreate = getOwner();\n\n // This effect owns its nested effects/roots via a reusable child-owner: it is\n // disposed (nested cleanups run) at the top of each run and on disposal, then\n // reused for the next generation. One small allocation per createEffect; the\n // hot DOM path uses internalEffect, which has no child-owner.\n const childOwner: Owner = createChildOwner();\n\n // Most effects have zero or one cleanup. Track the single-cleanup case\n // without array allocation; only promote to pooled array when needed.\n let cleanup: (() => void) | undefined;\n let cleanupBag: (() => void)[] | undefined;\n let nextCleanup: (() => void) | undefined;\n let nextCleanupBag: (() => void)[] | undefined;\n\n const addCleanup = (cb: () => void) => {\n if (nextCleanupBag !== undefined) {\n nextCleanupBag.push(cb);\n return;\n }\n if (nextCleanup !== undefined) {\n const bag = acquireArray();\n bag.push(nextCleanup, cb);\n nextCleanup = undefined;\n nextCleanupBag = bag;\n return;\n }\n nextCleanup = cb;\n };\n\n const runOnce = () => {\n // Dispose the previous generation of nested effects/roots (running their\n // cleanups) FIRST — children before parents, matching wrappedDispose so the\n // teardown order is consistent between the re-run and dispose paths and a\n // nested cleanup never observes parent-owned state already freed. (alien's\n // raw unwatched teardown of a nested effect bypasses our cleanup, so we own\n // nested work explicitly.)\n disposeOwner(childOwner);\n\n // Run and clear this effect's own previous cleanups.\n if (cleanup !== undefined) {\n runCleanup(cleanup);\n cleanup = undefined;\n }\n if (cleanupBag !== undefined) {\n runCleanups(cleanupBag);\n releaseArray(cleanupBag);\n cleanupBag = undefined;\n }\n\n nextCleanup = undefined;\n nextCleanupBag = undefined;\n\n // Always install the collector so onCleanup()/returned cleanups are captured\n // on EVERY run. (The old skipCleanupInfra fast-path latched after a clean\n // first run and then silently dropped — or cross-registered — cleanups\n // registered on later runs.) The single-cleanup/pooled-array promotion below\n // keeps the zero/one-cleanup case allocation-free.\n const prevCollector = setCleanupCollector(addCleanup);\n\n try {\n // Run the body with this effect's child-owner installed so any nested\n // effects/roots it creates are owned by this generation.\n const result = runWithOwner(childOwner, fn);\n if (typeof result === 'function') {\n addCleanup(result as () => void);\n }\n // Commit this run's cleanups. When none were registered, both stay\n // undefined (allocation-free).\n if (nextCleanupBag !== undefined) {\n cleanupBag = nextCleanupBag;\n } else if (nextCleanup !== undefined) {\n cleanup = nextCleanup;\n }\n } catch (e) {\n reportError(e, 'effect');\n if (nextCleanupBag !== undefined) {\n cleanupBag = nextCleanupBag;\n } else if (nextCleanup !== undefined) {\n cleanup = nextCleanup;\n }\n } finally {\n setCleanupCollector(prevCollector);\n }\n };\n\n const safeFn = () => {\n // alien-signals sets activeSub to this effect's node for the duration of this\n // callback, so getActiveSub() is our own node. If the body writes a signal we\n // depend on, alien-signals marks this node Pending but skips the re-run; we\n // detect that and run again, bounded so a genuine cycle is reported instead of\n // hanging.\n const node = getActiveSub() as SubNode | undefined;\n let reentrantRuns = 0;\n do {\n if (node) node.flags &= ~PENDING; // clear before running so we detect a fresh set\n runOnce();\n if (node === undefined || (node.flags & PENDING) === 0) break;\n if (++reentrantRuns >= MAX_REENTRANT_RUNS) {\n node.flags &= ~PENDING;\n reportError(\n new Error(`createEffect exceeded ${MAX_REENTRANT_RUNS} self-triggered re-runs (cycle?)`),\n 'effect',\n );\n break;\n }\n } while (true);\n };\n\n const dispose = rawEffect(safeFn);\n\n // Wrap dispose to also run final cleanups\n let disposed = false;\n const wrappedDispose = () => {\n if (disposed) return;\n disposed = true;\n dispose();\n // Dispose nested effects/roots this effect owns, then run its own cleanups.\n disposeOwner(childOwner);\n if (cleanup !== undefined) {\n runCleanup(cleanup);\n cleanup = undefined;\n }\n if (cleanupBag !== undefined) {\n runCleanups(cleanupBag);\n releaseArray(cleanupBag);\n cleanupBag = undefined;\n }\n };\n\n // Register this effect's disposer with the owner active at creation (a root, or\n // a parent effect's child-owner).\n if (ownerAtCreate) {\n registerOwnerDisposer(ownerAtCreate, wrappedDispose);\n }\n\n return wrappedDispose;\n}\n","/**\n * Forma Reactive - Memo\n *\n * Alias for createComputed with SolidJS/React-familiar naming.\n * A memoized derived value that only recomputes when its dependencies change.\n *\n * TC39 Signals equivalent: Signal.Computed\n */\n\nimport { createComputed } from './computed.js';\n\n/**\n * Create a memoized computed value.\n * Identical to `createComputed` — provided for React/SolidJS familiarity.\n *\n * Note: Unlike SolidJS's createComputed (which is an eager synchronous\n * side effect), both createComputed and createMemo in FormaJS are lazy\n * cached derivations — equivalent to SolidJS's createMemo. They are\n * identical.\n *\n * The computation runs lazily and caches the result. It only recomputes\n * when a signal it reads during computation changes.\n *\n * ```ts\n * const [count, setCount] = createSignal(0);\n * const doubled = createMemo(() => count() * 2);\n * console.log(doubled()); // 0\n * setCount(5);\n * console.log(doubled()); // 10\n * ```\n */\nexport const createMemo: typeof createComputed = createComputed;\n","/**\n * Forma Reactive - Batch\n *\n * Groups multiple signal updates and defers effect execution until the\n * outermost batch completes. Prevents intermediate re-renders.\n * Backed by alien-signals.\n *\n * TC39 Signals: no built-in batch — this is a userland optimization.\n */\n\nimport { startBatch, endBatch } from 'alien-signals';\n\n/**\n * Group multiple signal updates so that effects only run once after all\n * updates have been applied.\n *\n * ```ts\n * batch(() => {\n * setA(1);\n * setB(2);\n * // effects that depend on A and B won't run yet\n * });\n * // effects run here, once\n * ```\n *\n * Batches are nestable — only the outermost batch triggers the flush.\n */\nexport function batch(fn: () => void): void {\n startBatch();\n try {\n fn();\n } finally {\n endBatch();\n }\n}\n","/**\n * Forma Reactive - Untrack\n *\n * Read signals without subscribing to them in the reactive graph.\n * Essential for reading values inside effects without creating dependencies.\n *\n * TC39 Signals equivalent: Signal.subtle.untrack()\n */\n\nimport { setActiveSub } from 'alien-signals';\n\n/**\n * Execute a function without tracking signal reads.\n * Any signals read inside `fn` will NOT become dependencies of the\n * surrounding effect or computed.\n *\n * ```ts\n * createEffect(() => {\n * const a = count(); // tracked — effect re-runs when count changes\n * const b = untrack(() => other()); // NOT tracked — effect ignores other changes\n * });\n * ```\n */\nexport function untrack<T>(fn: () => T): T {\n const prev = setActiveSub(undefined);\n try {\n return fn();\n } finally {\n setActiveSub(prev);\n }\n}\n","/**\n * Forma Reactive - On\n *\n * Explicit dependency tracking for effects.\n * Only re-runs when the specified signals change, ignoring all other reads.\n *\n * SolidJS equivalent: on()\n * Vue equivalent: watch() with explicit deps\n * React equivalent: useEffect dependency array\n */\n\nimport { untrack } from './untrack.js';\n\n/**\n * Create a tracked effect body that only fires when specific dependencies change.\n *\n * Wraps a function so that only the `deps` signals are tracked.\n * All signal reads inside `fn` are untracked (won't cause re-runs).\n *\n * Use with `createEffect`:\n *\n * ```ts\n * const [a, setA] = createSignal(1);\n * const [b, setB] = createSignal(2);\n *\n * // Only re-runs when `a` changes, NOT when `b` changes:\n * createEffect(on(a, (value, prev) => {\n * console.log(`a changed: ${prev} → ${value}, b is ${b()}`);\n * }));\n *\n * setA(10); // fires: \"a changed: 1 → 10, b is 2\"\n * setB(20); // does NOT fire\n * ```\n *\n * Multiple dependencies:\n * ```ts\n * createEffect(on(\n * () => [a(), b()] as const,\n * ([aVal, bVal], prev) => { ... }\n * ));\n * ```\n */\nexport function on<T, U>(\n deps: () => T,\n fn: (value: T, prev: T | undefined) => U,\n options?: { defer?: boolean },\n): () => U | undefined {\n let prev: T | undefined;\n let isFirst = true;\n\n return () => {\n // Track only the deps\n const value = deps();\n\n if (options?.defer && isFirst) {\n isFirst = false;\n prev = value;\n return undefined;\n }\n\n // Run the body untracked so it doesn't add extra dependencies\n const result = untrack(() => fn(value, prev));\n prev = value;\n return result;\n };\n}\n","/**\n * Forma Reactive - Ref\n *\n * Mutable container that does NOT trigger reactivity.\n * Use for DOM references, previous values, instance variables —\n * anything that needs to persist across effect re-runs without\n * causing re-execution.\n *\n * React equivalent: useRef\n * SolidJS equivalent: (none — uses plain variables in setup)\n */\n\n/** A mutable container that does NOT trigger reactivity when written to. */\nexport interface Ref<T> {\n /** The stored value. Mutating this does not notify effects. */\n current: T;\n}\n\n/**\n * Create a mutable ref container.\n *\n * Unlike signals, writing to `.current` does NOT trigger effects.\n * Use when you need a stable reference across reactive scopes.\n *\n * ```ts\n * const timerRef = createRef<number | null>(null);\n *\n * createEffect(() => {\n * timerRef.current = setInterval(tick, 1000);\n * onCleanup(() => clearInterval(timerRef.current!));\n * });\n *\n * // DOM ref pattern:\n * const elRef = createRef<HTMLElement | null>(null);\n * h('div', { ref: (el) => { elRef.current = el; } });\n * ```\n */\nexport function createRef<T>(initialValue: T): Ref<T> {\n return { current: initialValue };\n}\n","/**\n * Forma Reactive - Reducer\n *\n * State machine pattern — dispatch actions to a pure reducer function.\n * Fine-grained: only the resulting state signal is reactive.\n *\n * React equivalent: useReducer\n * SolidJS equivalent: (none — uses createSignal + helpers)\n */\n\nimport { createSignal, type SignalGetter } from './signal.js';\n\n/** A function that dispatches an action to a reducer. */\nexport type Dispatch<A> = (action: A) => void;\n\n/**\n * Create a reducer — predictable state updates via dispatched actions.\n *\n * The reducer function must be pure: `(state, action) => newState`.\n * Returns a [state, dispatch] tuple.\n *\n * ```ts\n * type Action = { type: 'increment' } | { type: 'decrement' } | { type: 'reset' };\n *\n * const [count, dispatch] = createReducer(\n * (state: number, action: Action) => {\n * switch (action.type) {\n * case 'increment': return state + 1;\n * case 'decrement': return state - 1;\n * case 'reset': return 0;\n * }\n * },\n * 0,\n * );\n *\n * dispatch({ type: 'increment' }); // count() === 1\n * dispatch({ type: 'increment' }); // count() === 2\n * dispatch({ type: 'reset' }); // count() === 0\n * ```\n */\nexport function createReducer<S, A>(\n reducer: (state: S, action: A) => S,\n initialState: S,\n): [state: SignalGetter<S>, dispatch: Dispatch<A>] {\n const [state, setState] = createSignal(initialState);\n\n const dispatch: Dispatch<A> = (action) => {\n setState((prev) => reducer(prev, action));\n };\n\n return [state, dispatch];\n}\n","/**\n * Forma Reactive - Suspense Context\n *\n * Shared context stack for Suspense boundaries. Lives in the reactive layer\n * (not DOM) so that createResource can import it without circular dependencies.\n *\n * The pattern mirrors the lifecycle context stack in component/define.ts.\n */\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** Context object for a Suspense boundary, tracking pending async resources. */\nexport interface SuspenseContext {\n /** Increment when a resource starts loading inside this boundary. */\n increment(): void;\n /** Decrement when a resource resolves/rejects inside this boundary. */\n decrement(): void;\n}\n\n// ---------------------------------------------------------------------------\n// Context stack\n// ---------------------------------------------------------------------------\n\nlet currentSuspenseContext: SuspenseContext | null = null;\nconst suspenseStack: (SuspenseContext | null)[] = [];\n\nexport function pushSuspenseContext(ctx: SuspenseContext): void {\n suspenseStack.push(currentSuspenseContext);\n currentSuspenseContext = ctx;\n}\n\nexport function popSuspenseContext(): void {\n currentSuspenseContext = suspenseStack.pop() ?? null;\n}\n\n/** Get the current Suspense context (if any). Called by createResource. */\nexport function getSuspenseContext(): SuspenseContext | null {\n return currentSuspenseContext;\n}\n","/**\n * Forma Reactive - Resource\n *\n * Async data fetching primitive with reactive loading/error state.\n * Tracks a source signal and refetches when it changes.\n *\n * SolidJS equivalent: createResource\n * React equivalent: use() + Suspense (React 19), or useSWR/react-query\n */\n\nimport { createSignal, type SignalGetter } from './signal.js';\nimport { internalEffect } from './effect.js';\nimport { untrack } from './untrack.js';\nimport { batch } from './batch.js';\nimport { hasActiveRoot, registerDisposer } from './root.js';\nimport { getSuspenseContext } from './suspense-context.js';\n\n/** Info passed to a resource fetcher — carries the AbortSignal for this fetch. */\nexport interface ResourceFetcherInfo {\n /** Aborted when the source changes / the resource refetches or is disposed. */\n signal: AbortSignal;\n}\n\n/** An async data resource with reactive loading and error state. */\nexport interface Resource<T> {\n /** The resolved data (or undefined while loading). */\n (): T | undefined;\n /** True while the fetcher is running. */\n loading: SignalGetter<boolean>;\n /** The error if the fetcher rejected (or undefined). */\n error: SignalGetter<unknown>;\n /** Manually refetch with the current source value. */\n refetch: () => void;\n /** Manually set the data (overrides fetcher result). */\n mutate: (value: T | undefined) => void;\n}\n\n/** Options for {@link createResource}. */\nexport interface ResourceOptions<T> {\n /** Initial value before first fetch resolves. */\n initialValue?: T;\n}\n\n/**\n * Create an async resource that fetches data reactively.\n *\n * When `source` changes, the fetcher re-runs automatically.\n * Provides reactive `loading` and `error` signals.\n *\n * ```ts\n * const [userId, setUserId] = createSignal(1);\n *\n * const user = createResource(\n * userId, // source signal\n * (id) => fetch(`/api/users/${id}`).then(r => r.json()), // fetcher\n * );\n *\n * internalEffect(() => {\n * if (user.loading()) console.log('Loading...');\n * else if (user.error()) console.log('Error:', user.error());\n * else console.log('User:', user());\n * });\n *\n * setUserId(2); // automatically refetches\n * ```\n *\n * Without a source signal (static fetch):\n * ```ts\n * const posts = createResource(\n * () => true, // constant source — fetches once\n * () => fetch('/api/posts').then(r => r.json()),\n * );\n * ```\n */\nexport function createResource<T, S = true>(\n source: SignalGetter<S>,\n fetcher: (source: S, info: ResourceFetcherInfo) => Promise<T>,\n options?: ResourceOptions<T>,\n): Resource<T> {\n const [data, setData] = createSignal<T | undefined>(options?.initialValue);\n const [loading, setLoading] = createSignal(false);\n const [error, setError] = createSignal<unknown>(undefined);\n\n // Capture the Suspense context at creation time (not at fetch time).\n // This is critical because the Suspense boundary pushes/pops its context\n // synchronously during children() execution.\n const suspenseCtx = getSuspenseContext();\n\n let abortController: AbortController | null = null;\n let fetchVersion = 0;\n\n const doFetch = () => {\n // Read source outside tracking to get current value\n const sourceValue = untrack(source);\n\n // Abort previous in-flight request\n if (abortController) {\n abortController.abort();\n }\n const controller = new AbortController();\n abortController = controller;\n\n const version = ++fetchVersion;\n const isLatest = () => version === fetchVersion;\n let suspensePending = false;\n\n // Notify Suspense boundary that a fetch has started\n if (suspenseCtx) {\n suspenseCtx.increment();\n suspensePending = true;\n }\n\n // Batch the paired start writes so subscribers never see a glitch frame\n // (loading=true with a stale error from the previous fetch).\n batch(() => {\n setLoading(true);\n setError(undefined);\n });\n\n // Route a synchronously-thrown fetcher through the same rejection path so the\n // .catch/.finally below run — otherwise loading stays true forever and the\n // Suspense increment is never matched by a decrement.\n let promise: Promise<T>;\n try {\n promise = Promise.resolve(fetcher(sourceValue, { signal: controller.signal }));\n } catch (err) {\n promise = Promise.reject(err);\n }\n\n promise\n .then((result) => {\n // Only apply if this is still the latest fetch and wasn't aborted.\n // Batch data + loading so subscribers see one atomic settled frame.\n if (isLatest() && !controller.signal.aborted) {\n batch(() => {\n setData(() => result);\n setLoading(false);\n });\n }\n })\n .catch((err) => {\n if (isLatest() && !controller.signal.aborted && err?.name !== 'AbortError') {\n batch(() => {\n setError(err);\n setLoading(false);\n });\n }\n })\n .finally(() => {\n if (suspensePending) suspenseCtx?.decrement();\n // loading is cleared atomically in .then/.catch above; a stale/aborted\n // settlement leaves it to the newer fetch (or the dispose) and writes no\n // state here.\n if (isLatest() && abortController === controller) {\n abortController = null; // Release controller for GC\n }\n });\n };\n\n // Auto-fetch when source changes\n internalEffect(() => {\n source(); // track the source signal\n doFetch();\n });\n\n // Abort any in-flight fetch when the owning root is disposed. The fetchVersion\n // guard already neutralizes late settlements; this also cancels fetchers that\n // honor the AbortSignal.\n if (hasActiveRoot()) {\n registerDisposer(() => {\n // Invalidate any in-flight fetch so its late settlement writes no state\n // (isLatest() becomes false), then abort it.\n fetchVersion++;\n if (abortController) {\n abortController.abort();\n abortController = null;\n }\n });\n }\n\n // Build the resource object\n const resource = (() => data()) as Resource<T>;\n resource.loading = loading;\n resource.error = error;\n resource.refetch = doFetch;\n resource.mutate = (value) => setData(() => value);\n\n return resource;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/reactive/root.ts","../src/reactive/cleanup.ts","../src/reactive/effect.ts","../src/reactive/memo.ts","../src/reactive/batch.ts","../src/reactive/untrack.ts","../src/reactive/on.ts","../src/reactive/ref.ts","../src/reactive/reducer.ts","../src/reactive/suspense-context.ts","../src/reactive/resource.ts"],"names":["rawEffectScope","rawEffect","setActiveSub","value"],"mappings":";;;;AAsBA,IAAI,WAAA,GAAgC,IAAA;AACpC,IAAM,YAAkC,EAAC;AAsBzC,IAAI,YAAA,GAA6B,IAAA;AAG1B,SAAS,QAAA,GAAyB;AACvC,EAAA,OAAO,YAAA;AACT;AAOO,SAAS,YAAA,CAAgB,OAAqB,EAAA,EAAgB;AACnE,EAAA,MAAM,IAAA,GAAO,YAAA;AACb,EAAA,YAAA,GAAe,KAAA;AACf,EAAA,IAAI;AACF,IAAA,OAAO,EAAA,EAAG;AAAA,EACZ,CAAA,SAAE;AACA,IAAA,YAAA,GAAe,IAAA;AAAA,EACjB;AACF;AAGO,SAAS,qBAAA,CAAsB,OAAc,OAAA,EAA2B;AAC7E,EAAA,KAAA,CAAM,SAAA,CAAU,KAAK,OAAO,CAAA;AAC9B;AAGO,SAAS,gBAAA,GAA0B;AACxC,EAAA,OAAO,EAAE,SAAA,EAAW,EAAC,EAAE;AACzB;AAGO,SAAS,aAAa,KAAA,EAAoB;AAC/C,EAAA,MAAM,KAAK,KAAA,CAAM,SAAA;AACjB,EAAA,KAAA,MAAW,KAAK,EAAA,EAAI;AAClB,IAAA,IAAI;AAAE,MAAA,CAAA,EAAE;AAAA,IAAG,CAAA,CAAA,MAAQ;AAAA,IAAiC;AAAA,EACtD;AACA,EAAA,EAAA,CAAG,MAAA,GAAS,CAAA;AACd;AAMA,SAAS,cAAA,CAAkB,IAAgC,KAAA,EAAmB;AAC5E,EAAA,MAAM,QAAmB,EAAE,SAAA,EAAW,EAAC,EAAG,cAAc,IAAA,EAAK;AAC7D,EAAA,MAAM,UAAA,GAAa,QAAQ,WAAA,GAAc,IAAA;AAEzC,EAAA,SAAA,CAAU,KAAK,WAAW,CAAA;AAC1B,EAAA,WAAA,GAAc,KAAA;AACd,EAAA,MAAM,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created inside a root\n * are automatically disposed when the root is torn down.\n *\n * Uses alien-signals' `effectScope` under the hood for native graph-level\n * effect tracking, with a userland disposer list for non-effect cleanup\n * (e.g., event listeners, DOM references, timers).\n *\n * Roots created inside another root are automatically owned by the parent\n * (Solid-style). When the parent is disposed, all child roots are disposed\n * too. Use {@link createUnownedRoot} for roots that must outlive their\n * lexical parent (e.g., mount points, test harnesses).\n */\n\nimport { effectScope as rawEffectScope, setActiveSub } from 'alien-signals';\n\n// ---------------------------------------------------------------------------\n// Root scope tracking\n// ---------------------------------------------------------------------------\n\nlet currentRoot: RootScope | null = null;\nconst rootStack: (RootScope | null)[] = [];\n\n/**\n * The minimal ownership unit: something that holds disposers. A {@link RootScope}\n * is an Owner with an extra alien-signals scope dispose. Effects use lightweight\n * child owners (no scopeDispose) to own their nested effects generation-by-generation.\n */\nexport interface Owner {\n /** Disposers to run when this owner is torn down. */\n disposers: (() => void)[];\n}\n\ninterface RootScope extends Owner {\n /** alien-signals effect scope dispose — tears down all reactive effects */\n scopeDispose: (() => void) | null;\n}\n\n/**\n * The owner that new disposers register with. Inside a root this equals the\n * current {@link RootScope}; {@link runWithOwner} can temporarily point it at any\n * owner so work created outside the original synchronous scope is still owned.\n */\nlet currentOwner: Owner | null = null;\n\n/** @internal — the owner disposers currently register with (or null). */\nexport function getOwner(): Owner | null {\n return currentOwner;\n}\n\n/**\n * Run `fn` with `owner` installed as the current owner, restoring the previous\n * owner afterwards. Lets effects/roots created asynchronously (after the\n * original root callback returned) still be owned and disposed.\n */\nexport function runWithOwner<T>(owner: Owner | null, fn: () => T): T {\n const prev = currentOwner;\n currentOwner = owner;\n try {\n return fn();\n } finally {\n currentOwner = prev;\n }\n}\n\n/** @internal — register a disposer directly with a specific owner. */\nexport function registerOwnerDisposer(owner: Owner, dispose: () => void): void {\n owner.disposers.push(dispose);\n}\n\n/** @internal — a fresh lightweight owner (no alien scope). Used per effect run. */\nexport function createChildOwner(): Owner {\n return { disposers: [] };\n}\n\n/** @internal — run and clear an owner's disposers (guarded so one throw doesn't abort the rest). */\nexport function disposeOwner(owner: Owner): void {\n const ds = owner.disposers;\n for (const d of ds) {\n try { d(); } catch { /* ensure all disposers run */ }\n }\n ds.length = 0;\n}\n\n// ---------------------------------------------------------------------------\n// Shared implementation\n// ---------------------------------------------------------------------------\n\nfunction createRootImpl<T>(fn: (dispose: () => void) => T, owned: boolean): T {\n const scope: RootScope = { disposers: [], scopeDispose: null };\n const parentRoot = owned ? currentRoot : null;\n\n rootStack.push(currentRoot);\n currentRoot = scope;\n const prevOwner = currentOwner;\n currentOwner = scope;\n\n let disposed = false;\n let setupComplete = false;\n let disposeRequestedDuringSetup = false;\n\n const runDisposers = () => {\n // Run userland disposers (includes child root disposes), guarded so one\n // throw does not abort the rest. Draining means a later runTeardown only\n // sees disposers registered since this drain.\n for (const d of scope.disposers) {\n try { d(); } catch { /* ensure all disposers run */ }\n }\n scope.disposers.length = 0;\n };\n\n const runTeardown = () => {\n // Dispose alien-signals effect scope first (reactive graph cleanup)\n if (scope.scopeDispose) {\n try { scope.scopeDispose(); } catch { /* ensure userland disposers still run */ }\n scope.scopeDispose = null;\n }\n runDisposers();\n };\n\n const dispose = () => {\n if (disposed) return; // idempotent — safe to call after parent already disposed this\n disposed = true;\n // dispose() called synchronously DURING setup: scope.scopeDispose is not yet\n // assigned and anything created AFTER this call has not registered. Eagerly\n // run the disposers already registered (so cleanup for work created BEFORE\n // this call is synchronous, Solid-style), and defer the rest — the alien\n // scope dispose plus any after-created disposers — until setup finishes.\n // Without the deferral, everything created afterward would leak.\n if (!setupComplete) {\n disposeRequestedDuringSetup = true;\n runDisposers();\n return;\n }\n runTeardown();\n };\n\n // Auto-register with parent root so child dies when parent dies (Solid-style)\n if (parentRoot) {\n parentRoot.disposers.push(dispose);\n }\n\n let result: T;\n try {\n if (owned) {\n // Owned: alien-signals nesting is kept (belt + suspenders with Forma cascade)\n scope.scopeDispose = rawEffectScope(() => {\n result = fn(dispose);\n });\n } else {\n // Unowned: break alien-signals scope nesting so this scope is NOT\n // disposed when the lexical parent scope is disposed.\n const prevSub = setActiveSub(undefined);\n try {\n scope.scopeDispose = rawEffectScope(() => {\n result = fn(dispose);\n });\n } finally {\n setActiveSub(prevSub);\n }\n }\n // Setup finished: scope.scopeDispose is assigned and all in-setup effects /\n // child-roots have registered. If dispose() was requested during setup, run\n // the deferred teardown now so everything created in the callback is torn down.\n setupComplete = true;\n if (disposeRequestedDuringSetup) {\n runTeardown();\n }\n } finally {\n currentRoot = rootStack.pop() ?? null;\n currentOwner = prevOwner;\n }\n\n return result!;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Create a reactive root scope.\n *\n * All effects created (via `createEffect`) inside the callback are tracked\n * at both the reactive graph level (via alien-signals effectScope) and the\n * userland level (via registerDisposer). The returned `dispose` function\n * tears down everything.\n *\n * Roots created inside another root are automatically owned by the parent.\n * When the parent is disposed, this root is disposed too.\n *\n * ```ts\n * const dispose = createRoot(() => {\n * createEffect(() => console.log(count()));\n * createEffect(() => console.log(name()));\n * });\n * // later: dispose() stops both effects\n * ```\n */\nexport function createRoot<T>(fn: (dispose: () => void) => T): T {\n return createRootImpl(fn, true);\n}\n\n/**\n * Create a reactive root that is NOT owned by any parent root.\n *\n * Use this for roots that must outlive their lexical parent:\n * top-level mount points, island hydration, test harnesses, etc.\n *\n * ```ts\n * createRoot(() => {\n * // This root outlives the parent even though it's nested:\n * createUnownedRoot((dispose) => {\n * // effects here survive parent disposal\n * });\n * });\n * ```\n */\nexport function createUnownedRoot<T>(fn: (dispose: () => void) => T): T {\n return createRootImpl(fn, false);\n}\n\n/**\n * @internal — called by createEffect and DOM primitives to register disposers\n * with the current owner (a root scope, or an owner installed via runWithOwner).\n */\nexport function registerDisposer(dispose: () => void): void {\n if (currentOwner) {\n currentOwner.disposers.push(dispose);\n }\n}\n\n/**\n * @internal — check if we're inside an owner scope (root or runWithOwner).\n */\nexport function hasActiveRoot(): boolean {\n return currentOwner !== null;\n}\n","/**\n * Forma Reactive - Cleanup\n *\n * Register cleanup functions within reactive scopes.\n * Inspired by SolidJS onCleanup().\n */\n\n// ---------------------------------------------------------------------------\n// Cleanup context tracking\n// ---------------------------------------------------------------------------\n\ntype CleanupCollector = ((fn: () => void) => void) | null;\n\nlet currentCleanupCollector: CleanupCollector = null;\n\n/**\n * Register a cleanup function in the current reactive scope.\n * The cleanup runs before the effect re-executes and on disposal.\n *\n * More composable than returning a cleanup from the effect function,\n * since it can be called from helper functions.\n *\n * ```ts\n * createEffect(() => {\n * const timer = setInterval(tick, 1000);\n * onCleanup(() => clearInterval(timer));\n * });\n * ```\n */\nexport function onCleanup(fn: () => void): void {\n currentCleanupCollector?.(fn);\n}\n\n/**\n * @internal — Set the cleanup collector for the current effect execution.\n */\nexport function setCleanupCollector(collector: CleanupCollector): CleanupCollector {\n const prev = currentCleanupCollector;\n currentCleanupCollector = collector;\n return prev;\n}\n","/**\n * Forma Reactive - Effect\n *\n * Side-effectful reactive computation that auto-tracks signal dependencies.\n * Backed by alien-signals for automatic dependency tracking.\n *\n * TC39 Signals equivalent: Signal.subtle.Watcher (effect is a userland concept)\n */\n\nimport { effect as rawEffect, getActiveSub } from 'alien-signals';\nimport {\n hasActiveRoot,\n registerDisposer,\n getOwner,\n runWithOwner,\n registerOwnerDisposer,\n createChildOwner,\n disposeOwner,\n type Owner,\n} from './root.js';\nimport { setCleanupCollector } from './cleanup.js';\nimport { reportError } from './dev.js';\n\n// ---------------------------------------------------------------------------\n// Cleanup array pool — avoids allocating a new array every effect re-run\n// ---------------------------------------------------------------------------\n\nconst POOL_SIZE = 32;\nconst MAX_REENTRANT_RUNS = 100;\nconst pool: (() => void)[][] = [];\nfor (let i = 0; i < POOL_SIZE; i++) pool.push([]);\nlet poolIdx = POOL_SIZE;\n\n// ---------------------------------------------------------------------------\n// Self-write detection — alien-signals' propagate() never notifies a subscriber\n// that is currently running, so an effect writing a signal it depends on is left\n// stale. When that happens alien-signals still sets the Pending flag on the\n// running subscriber's node (but skips the re-run). We read that flag on the\n// EFFECT's own node after each run and loop, so a self-dependent effect\n// converges. Reading the effect's own node (not a global) makes this precise:\n// writes to signals the effect does not depend on, writes from a nested computed,\n// and a nested effect's self-write never set THIS node's Pending, so they cause\n// no spurious re-run. It also works through batch() (Pending is set at flush).\n// ---------------------------------------------------------------------------\n\n// alien-signals ReactiveFlags.Pending (not exported from the package root).\nconst PENDING = 32;\n\ninterface SubNode { flags: number; }\n\nfunction acquireArray(): (() => void)[] {\n if (poolIdx > 0) {\n const arr = pool[--poolIdx]!;\n arr.length = 0;\n return arr;\n }\n return [];\n}\n\nfunction releaseArray(arr: (() => void)[]): void {\n arr.length = 0;\n if (poolIdx < POOL_SIZE) {\n pool[poolIdx++] = arr;\n }\n}\n\n// ---------------------------------------------------------------------------\n// Unified cleanup runner — single function for both re-run and dispose paths\n// ---------------------------------------------------------------------------\n\nfunction runCleanup(fn: (() => void) | undefined): void {\n if (fn === undefined) return;\n try {\n fn();\n } catch (e) {\n reportError(e, 'effect cleanup');\n }\n}\n\nfunction runCleanups(bag: (() => void)[] | undefined): void {\n if (bag === undefined) return;\n for (let i = 0; i < bag.length; i++) {\n try { bag[i]!(); } catch (e) { reportError(e, 'effect cleanup'); }\n }\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/**\n * Create a reactive effect that auto-tracks signal dependencies.\n *\n * The provided function runs immediately and re-runs whenever any signal it\n * reads changes. If the function returns a cleanup function, that cleanup is\n * called before each re-run and on disposal.\n *\n * Additionally, `onCleanup()` can be called inside the effect to register\n * cleanup functions composably.\n *\n * Returns a dispose function that stops the effect.\n */\n/**\n * @internal — Lightweight effect for Forma's internal DOM bindings.\n *\n * Bypasses createEffect's cleanup infrastructure (pool, collector, error\n * reporting, engine compression) since internal effects never use\n * onCleanup() or return cleanup functions. This saves ~4 function calls\n * per effect creation and per re-run.\n *\n * ONLY use for effects that:\n * 1. Never call onCleanup()\n * 2. Never return a cleanup function\n * 3. Contain simple \"read signal → write DOM\" logic\n */\nexport function internalEffect(fn: () => void): () => void {\n const dispose = rawEffect(fn);\n if (hasActiveRoot()) {\n registerDisposer(dispose);\n }\n return dispose;\n}\n\nexport function createEffect(fn: () => void | (() => void)): () => void {\n // Capture the owner active at creation time so this effect's disposer is owned\n // by whatever created it — a root, or (for a nested effect) the parent effect's\n // current child-owner. This replaces a hasActiveRoot() snapshot so nested\n // effects created during a parent re-run (when no root is lexically active) are\n // still owned and disposed.\n const ownerAtCreate = getOwner();\n\n // This effect owns its nested effects/roots via a reusable child-owner: it is\n // disposed (nested cleanups run) at the top of each run and on disposal, then\n // reused for the next generation. One small allocation per createEffect; the\n // hot DOM path uses internalEffect, which has no child-owner.\n const childOwner: Owner = createChildOwner();\n\n // Most effects have zero or one cleanup. Track the single-cleanup case\n // without array allocation; only promote to pooled array when needed.\n let cleanup: (() => void) | undefined;\n let cleanupBag: (() => void)[] | undefined;\n let nextCleanup: (() => void) | undefined;\n let nextCleanupBag: (() => void)[] | undefined;\n\n const addCleanup = (cb: () => void) => {\n if (nextCleanupBag !== undefined) {\n nextCleanupBag.push(cb);\n return;\n }\n if (nextCleanup !== undefined) {\n const bag = acquireArray();\n bag.push(nextCleanup, cb);\n nextCleanup = undefined;\n nextCleanupBag = bag;\n return;\n }\n nextCleanup = cb;\n };\n\n const runOnce = () => {\n // Dispose the previous generation of nested effects/roots (running their\n // cleanups) FIRST — children before parents, matching wrappedDispose so the\n // teardown order is consistent between the re-run and dispose paths and a\n // nested cleanup never observes parent-owned state already freed. (alien's\n // raw unwatched teardown of a nested effect bypasses our cleanup, so we own\n // nested work explicitly.)\n disposeOwner(childOwner);\n\n // Run and clear this effect's own previous cleanups.\n if (cleanup !== undefined) {\n runCleanup(cleanup);\n cleanup = undefined;\n }\n if (cleanupBag !== undefined) {\n runCleanups(cleanupBag);\n releaseArray(cleanupBag);\n cleanupBag = undefined;\n }\n\n nextCleanup = undefined;\n nextCleanupBag = undefined;\n\n // Always install the collector so onCleanup()/returned cleanups are captured\n // on EVERY run. (The old skipCleanupInfra fast-path latched after a clean\n // first run and then silently dropped — or cross-registered — cleanups\n // registered on later runs.) The single-cleanup/pooled-array promotion below\n // keeps the zero/one-cleanup case allocation-free.\n const prevCollector = setCleanupCollector(addCleanup);\n\n try {\n // Run the body with this effect's child-owner installed so any nested\n // effects/roots it creates are owned by this generation.\n const result = runWithOwner(childOwner, fn);\n if (typeof result === 'function') {\n addCleanup(result as () => void);\n }\n // Commit this run's cleanups. When none were registered, both stay\n // undefined (allocation-free).\n if (nextCleanupBag !== undefined) {\n cleanupBag = nextCleanupBag;\n } else if (nextCleanup !== undefined) {\n cleanup = nextCleanup;\n }\n } catch (e) {\n reportError(e, 'effect');\n if (nextCleanupBag !== undefined) {\n cleanupBag = nextCleanupBag;\n } else if (nextCleanup !== undefined) {\n cleanup = nextCleanup;\n }\n } finally {\n setCleanupCollector(prevCollector);\n }\n };\n\n const safeFn = () => {\n // alien-signals sets activeSub to this effect's node for the duration of this\n // callback, so getActiveSub() is our own node. If the body writes a signal we\n // depend on, alien-signals marks this node Pending but skips the re-run; we\n // detect that and run again, bounded so a genuine cycle is reported instead of\n // hanging.\n const node = getActiveSub() as SubNode | undefined;\n let reentrantRuns = 0;\n do {\n if (node) node.flags &= ~PENDING; // clear before running so we detect a fresh set\n runOnce();\n if (node === undefined || (node.flags & PENDING) === 0) break;\n if (++reentrantRuns >= MAX_REENTRANT_RUNS) {\n node.flags &= ~PENDING;\n reportError(\n new Error(`createEffect exceeded ${MAX_REENTRANT_RUNS} self-triggered re-runs (cycle?)`),\n 'effect',\n );\n break;\n }\n } while (true);\n };\n\n const dispose = rawEffect(safeFn);\n\n // Wrap dispose to also run final cleanups\n let disposed = false;\n const wrappedDispose = () => {\n if (disposed) return;\n disposed = true;\n dispose();\n // Dispose nested effects/roots this effect owns, then run its own cleanups.\n disposeOwner(childOwner);\n if (cleanup !== undefined) {\n runCleanup(cleanup);\n cleanup = undefined;\n }\n if (cleanupBag !== undefined) {\n runCleanups(cleanupBag);\n releaseArray(cleanupBag);\n cleanupBag = undefined;\n }\n };\n\n // Register this effect's disposer with the owner active at creation (a root, or\n // a parent effect's child-owner).\n if (ownerAtCreate) {\n registerOwnerDisposer(ownerAtCreate, wrappedDispose);\n }\n\n return wrappedDispose;\n}\n","/**\n * Forma Reactive - Memo\n *\n * Alias for createComputed with SolidJS/React-familiar naming.\n * A memoized derived value that only recomputes when its dependencies change.\n *\n * TC39 Signals equivalent: Signal.Computed\n */\n\nimport { createComputed } from './computed.js';\n\n/**\n * Create a memoized computed value.\n * Identical to `createComputed` — provided for React/SolidJS familiarity.\n *\n * Note: Unlike SolidJS's createComputed (which is an eager synchronous\n * side effect), both createComputed and createMemo in FormaJS are lazy\n * cached derivations — equivalent to SolidJS's createMemo. They are\n * identical.\n *\n * The computation runs lazily and caches the result. It only recomputes\n * when a signal it reads during computation changes.\n *\n * ```ts\n * const [count, setCount] = createSignal(0);\n * const doubled = createMemo(() => count() * 2);\n * console.log(doubled()); // 0\n * setCount(5);\n * console.log(doubled()); // 10\n * ```\n */\nexport const createMemo: typeof createComputed = createComputed;\n","/**\n * Forma Reactive - Batch\n *\n * Groups multiple signal updates and defers effect execution until the\n * outermost batch completes. Prevents intermediate re-renders.\n * Backed by alien-signals.\n *\n * TC39 Signals: no built-in batch — this is a userland optimization.\n */\n\nimport { startBatch, endBatch } from 'alien-signals';\n\n/**\n * Group multiple signal updates so that effects only run once after all\n * updates have been applied.\n *\n * ```ts\n * batch(() => {\n * setA(1);\n * setB(2);\n * // effects that depend on A and B won't run yet\n * });\n * // effects run here, once\n * ```\n *\n * Batches are nestable — only the outermost batch triggers the flush.\n */\nexport function batch(fn: () => void): void {\n startBatch();\n try {\n fn();\n } finally {\n endBatch();\n }\n}\n","/**\n * Forma Reactive - Untrack\n *\n * Read signals without subscribing to them in the reactive graph.\n * Essential for reading values inside effects without creating dependencies.\n *\n * TC39 Signals equivalent: Signal.subtle.untrack()\n */\n\nimport { setActiveSub } from 'alien-signals';\n\n/**\n * Execute a function without tracking signal reads.\n * Any signals read inside `fn` will NOT become dependencies of the\n * surrounding effect or computed.\n *\n * ```ts\n * createEffect(() => {\n * const a = count(); // tracked — effect re-runs when count changes\n * const b = untrack(() => other()); // NOT tracked — effect ignores other changes\n * });\n * ```\n */\nexport function untrack<T>(fn: () => T): T {\n const prev = setActiveSub(undefined);\n try {\n return fn();\n } finally {\n setActiveSub(prev);\n }\n}\n","/**\n * Forma Reactive - On\n *\n * Explicit dependency tracking for effects.\n * Only re-runs when the specified signals change, ignoring all other reads.\n *\n * SolidJS equivalent: on()\n * Vue equivalent: watch() with explicit deps\n * React equivalent: useEffect dependency array\n */\n\nimport { untrack } from './untrack.js';\n\n/**\n * Create a tracked effect body that only fires when specific dependencies change.\n *\n * Wraps a function so that only the `deps` signals are tracked.\n * All signal reads inside `fn` are untracked (won't cause re-runs).\n *\n * Use with `createEffect`:\n *\n * ```ts\n * const [a, setA] = createSignal(1);\n * const [b, setB] = createSignal(2);\n *\n * // Only re-runs when `a` changes, NOT when `b` changes:\n * createEffect(on(a, (value, prev) => {\n * console.log(`a changed: ${prev} → ${value}, b is ${b()}`);\n * }));\n *\n * setA(10); // fires: \"a changed: 1 → 10, b is 2\"\n * setB(20); // does NOT fire\n * ```\n *\n * Multiple dependencies:\n * ```ts\n * createEffect(on(\n * () => [a(), b()] as const,\n * ([aVal, bVal], prev) => { ... }\n * ));\n * ```\n */\nexport function on<T, U>(\n deps: () => T,\n fn: (value: T, prev: T | undefined) => U,\n options?: { defer?: boolean },\n): () => U | undefined {\n let prev: T | undefined;\n let isFirst = true;\n\n return () => {\n // Track only the deps\n const value = deps();\n\n if (options?.defer && isFirst) {\n isFirst = false;\n prev = value;\n return undefined;\n }\n\n // Run the body untracked so it doesn't add extra dependencies\n const result = untrack(() => fn(value, prev));\n prev = value;\n return result;\n };\n}\n","/**\n * Forma Reactive - Ref\n *\n * Mutable container that does NOT trigger reactivity.\n * Use for DOM references, previous values, instance variables —\n * anything that needs to persist across effect re-runs without\n * causing re-execution.\n *\n * React equivalent: useRef\n * SolidJS equivalent: (none — uses plain variables in setup)\n */\n\n/** A mutable container that does NOT trigger reactivity when written to. */\nexport interface Ref<T> {\n /** The stored value. Mutating this does not notify effects. */\n current: T;\n}\n\n/**\n * Create a mutable ref container.\n *\n * Unlike signals, writing to `.current` does NOT trigger effects.\n * Use when you need a stable reference across reactive scopes.\n *\n * ```ts\n * const timerRef = createRef<number | null>(null);\n *\n * createEffect(() => {\n * timerRef.current = setInterval(tick, 1000);\n * onCleanup(() => clearInterval(timerRef.current!));\n * });\n *\n * // DOM ref pattern:\n * const elRef = createRef<HTMLElement | null>(null);\n * h('div', { ref: (el) => { elRef.current = el; } });\n * ```\n */\nexport function createRef<T>(initialValue: T): Ref<T> {\n return { current: initialValue };\n}\n","/**\n * Forma Reactive - Reducer\n *\n * State machine pattern — dispatch actions to a pure reducer function.\n * Fine-grained: only the resulting state signal is reactive.\n *\n * React equivalent: useReducer\n * SolidJS equivalent: (none — uses createSignal + helpers)\n */\n\nimport { createSignal, type SignalGetter } from './signal.js';\n\n/** A function that dispatches an action to a reducer. */\nexport type Dispatch<A> = (action: A) => void;\n\n/**\n * Create a reducer — predictable state updates via dispatched actions.\n *\n * The reducer function must be pure: `(state, action) => newState`.\n * Returns a [state, dispatch] tuple.\n *\n * ```ts\n * type Action = { type: 'increment' } | { type: 'decrement' } | { type: 'reset' };\n *\n * const [count, dispatch] = createReducer(\n * (state: number, action: Action) => {\n * switch (action.type) {\n * case 'increment': return state + 1;\n * case 'decrement': return state - 1;\n * case 'reset': return 0;\n * }\n * },\n * 0,\n * );\n *\n * dispatch({ type: 'increment' }); // count() === 1\n * dispatch({ type: 'increment' }); // count() === 2\n * dispatch({ type: 'reset' }); // count() === 0\n * ```\n */\nexport function createReducer<S, A>(\n reducer: (state: S, action: A) => S,\n initialState: S,\n): [state: SignalGetter<S>, dispatch: Dispatch<A>] {\n const [state, setState] = createSignal(initialState);\n\n const dispatch: Dispatch<A> = (action) => {\n setState((prev) => reducer(prev, action));\n };\n\n return [state, dispatch];\n}\n","/**\n * Forma Reactive - Suspense Context\n *\n * Shared context stack for Suspense boundaries. Lives in the reactive layer\n * (not DOM) so that createResource can import it without circular dependencies.\n *\n * The pattern mirrors the lifecycle context stack in component/define.ts.\n */\n\n// ---------------------------------------------------------------------------\n// Types\n// ---------------------------------------------------------------------------\n\n/** Context object for a Suspense boundary, tracking pending async resources. */\nexport interface SuspenseContext {\n /** Increment when a resource starts loading inside this boundary. */\n increment(): void;\n /** Decrement when a resource resolves/rejects inside this boundary. */\n decrement(): void;\n}\n\n// ---------------------------------------------------------------------------\n// Context stack\n// ---------------------------------------------------------------------------\n\nlet currentSuspenseContext: SuspenseContext | null = null;\nconst suspenseStack: (SuspenseContext | null)[] = [];\n\nexport function pushSuspenseContext(ctx: SuspenseContext): void {\n suspenseStack.push(currentSuspenseContext);\n currentSuspenseContext = ctx;\n}\n\nexport function popSuspenseContext(): void {\n currentSuspenseContext = suspenseStack.pop() ?? null;\n}\n\n/** Get the current Suspense context (if any). Called by createResource. */\nexport function getSuspenseContext(): SuspenseContext | null {\n return currentSuspenseContext;\n}\n","/**\n * Forma Reactive - Resource\n *\n * Async data fetching primitive with reactive loading/error state.\n * Tracks a source signal and refetches when it changes.\n *\n * SolidJS equivalent: createResource\n * React equivalent: use() + Suspense (React 19), or useSWR/react-query\n */\n\nimport { createSignal, type SignalGetter } from './signal.js';\nimport { internalEffect } from './effect.js';\nimport { untrack } from './untrack.js';\nimport { batch } from './batch.js';\nimport { hasActiveRoot, registerDisposer } from './root.js';\nimport { getSuspenseContext } from './suspense-context.js';\n\n/** Info passed to a resource fetcher — carries the AbortSignal for this fetch. */\nexport interface ResourceFetcherInfo {\n /** Aborted when the source changes / the resource refetches or is disposed. */\n signal: AbortSignal;\n}\n\n/** An async data resource with reactive loading and error state. */\nexport interface Resource<T> {\n /** The resolved data (or undefined while loading). */\n (): T | undefined;\n /** True while the fetcher is running. */\n loading: SignalGetter<boolean>;\n /** The error if the fetcher rejected (or undefined). */\n error: SignalGetter<unknown>;\n /** Manually refetch with the current source value. */\n refetch: () => void;\n /** Manually set the data (overrides fetcher result). */\n mutate: (value: T | undefined) => void;\n}\n\n/** Options for {@link createResource}. */\nexport interface ResourceOptions<T> {\n /** Initial value before first fetch resolves. */\n initialValue?: T;\n}\n\n/**\n * Create an async resource that fetches data reactively.\n *\n * When `source` changes, the fetcher re-runs automatically.\n * Provides reactive `loading` and `error` signals.\n *\n * ```ts\n * const [userId, setUserId] = createSignal(1);\n *\n * const user = createResource(\n * userId, // source signal\n * (id) => fetch(`/api/users/${id}`).then(r => r.json()), // fetcher\n * );\n *\n * internalEffect(() => {\n * if (user.loading()) console.log('Loading...');\n * else if (user.error()) console.log('Error:', user.error());\n * else console.log('User:', user());\n * });\n *\n * setUserId(2); // automatically refetches\n * ```\n *\n * Without a source signal (static fetch):\n * ```ts\n * const posts = createResource(\n * () => true, // constant source — fetches once\n * () => fetch('/api/posts').then(r => r.json()),\n * );\n * ```\n */\nexport function createResource<T, S = true>(\n source: SignalGetter<S>,\n fetcher: (source: S, info: ResourceFetcherInfo) => Promise<T>,\n options?: ResourceOptions<T>,\n): Resource<T> {\n const [data, setData] = createSignal<T | undefined>(options?.initialValue);\n const [loading, setLoading] = createSignal(false);\n const [error, setError] = createSignal<unknown>(undefined);\n\n // Capture the Suspense context at creation time (not at fetch time).\n // This is critical because the Suspense boundary pushes/pops its context\n // synchronously during children() execution.\n const suspenseCtx = getSuspenseContext();\n\n let abortController: AbortController | null = null;\n let fetchVersion = 0;\n\n const doFetch = () => {\n // Read source outside tracking to get current value\n const sourceValue = untrack(source);\n\n // Abort previous in-flight request\n if (abortController) {\n abortController.abort();\n }\n const controller = new AbortController();\n abortController = controller;\n\n const version = ++fetchVersion;\n const isLatest = () => version === fetchVersion;\n let suspensePending = false;\n\n // Notify Suspense boundary that a fetch has started\n if (suspenseCtx) {\n suspenseCtx.increment();\n suspensePending = true;\n }\n\n // Batch the paired start writes so subscribers never see a glitch frame\n // (loading=true with a stale error from the previous fetch).\n batch(() => {\n setLoading(true);\n setError(undefined);\n });\n\n // Route a synchronously-thrown fetcher through the same rejection path so the\n // .catch/.finally below run — otherwise loading stays true forever and the\n // Suspense increment is never matched by a decrement.\n let promise: Promise<T>;\n try {\n promise = Promise.resolve(fetcher(sourceValue, { signal: controller.signal }));\n } catch (err) {\n promise = Promise.reject(err);\n }\n\n promise\n .then((result) => {\n // Only apply if this is still the latest fetch and wasn't aborted.\n // Batch data + loading so subscribers see one atomic settled frame.\n if (isLatest() && !controller.signal.aborted) {\n batch(() => {\n setData(() => result);\n setLoading(false);\n });\n }\n })\n .catch((err) => {\n if (isLatest() && !controller.signal.aborted && err?.name !== 'AbortError') {\n batch(() => {\n setError(err);\n setLoading(false);\n });\n }\n })\n .finally(() => {\n if (suspensePending) suspenseCtx?.decrement();\n // loading is cleared atomically in .then/.catch above; a stale/aborted\n // settlement leaves it to the newer fetch (or the dispose) and writes no\n // state here.\n if (isLatest() && abortController === controller) {\n abortController = null; // Release controller for GC\n }\n });\n };\n\n // Auto-fetch when source changes\n internalEffect(() => {\n source(); // track the source signal\n doFetch();\n });\n\n // Abort any in-flight fetch when the owning root is disposed. The fetchVersion\n // guard already neutralizes late settlements; this also cancels fetchers that\n // honor the AbortSignal.\n if (hasActiveRoot()) {\n registerDisposer(() => {\n // Invalidate any in-flight fetch so its late settlement writes no state\n // (isLatest() becomes false), then abort it.\n fetchVersion++;\n if (abortController) {\n abortController.abort();\n abortController = null;\n }\n });\n }\n\n // Build the resource object\n const resource = (() => data()) as Resource<T>;\n resource.loading = loading;\n resource.error = error;\n resource.refetch = doFetch;\n resource.mutate = (value) => setData(() => value);\n\n return resource;\n}\n"]}
|
|
@@ -27,6 +27,9 @@ function reportError(error, source) {
|
|
|
27
27
|
}
|
|
28
28
|
}
|
|
29
29
|
var signalNames = /* @__PURE__ */ new WeakMap();
|
|
30
|
+
function getSignalName(fn) {
|
|
31
|
+
return typeof fn === "function" ? signalNames.get(fn) : void 0;
|
|
32
|
+
}
|
|
30
33
|
function value(v) {
|
|
31
34
|
return () => v;
|
|
32
35
|
}
|
|
@@ -98,6 +101,6 @@ function createComputed(fn) {
|
|
|
98
101
|
return reader;
|
|
99
102
|
}
|
|
100
103
|
|
|
101
|
-
export { __DEV__, createComputed, createSignal, onError, reportError, value };
|
|
102
|
-
//# sourceMappingURL=chunk-
|
|
103
|
-
//# sourceMappingURL=chunk-
|
|
104
|
+
export { __DEV__, createComputed, createSignal, getSignalName, onError, reportError, value };
|
|
105
|
+
//# sourceMappingURL=chunk-FAIWRZKJ.js.map
|
|
106
|
+
//# sourceMappingURL=chunk-FAIWRZKJ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/reactive/dev.ts","../src/reactive/signal.ts","../src/reactive/computed.ts"],"names":["prevSub","prev","createRawSignal","rawComputed"],"mappings":";;;AAmBA,SAAS,KAAA,GAAiB;AACxB,EAAA,IAAI,OAAO,YAAY,WAAA,EAAa;AAClC,IAAA,OAAO,OAAA,CAAS,KAAK,QAAA,KAAa,YAAA;AAAA,EACpC;AACA,EAAA,OAAO,OAAO,aAAA,KAAkB,WAAA,GAAc,CAAC,CAAC,aAAA,GAAgB,KAAA;AAClE;AAEO,IAAM,UAAmB,KAAA;AAShC,IAAM,cAAA,uBAAqB,GAAA,EAAkB;AActC,SAAS,QAAQ,OAAA,EAAmC;AACzD,EAAA,cAAA,CAAe,IAAI,OAAO,CAAA;AAC1B,EAAA,OAAO,MAAM;AAAE,IAAA,cAAA,CAAe,OAAO,OAAO,CAAA;AAAA,EAAG,CAAA;AACjD;AAGO,SAAS,WAAA,CAAY,OAAgB,MAAA,EAAuB;AACjE,EAAA,KAAA,MAAW,WAAW,cAAA,EAAgB;AACpC,IAAA,IAAI;AAAE,MAAA,OAAA,CAAQ,OAAO,MAAA,GAAS,EAAE,MAAA,EAAO,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AU,IAAA;AACV,MAAA,KAAA,GAAQ,CAAA;AACR,MAAA,WAAA,CAAY,GAAG,UAAU,CAAA;AACzB,MAAA,OAAO,EAAE,CAAC,GAAG,GAAG,CAAA,EAAE;AAAA,IACpB;AAAA,EACF,CAAC,CAAA;AAED,EAAA,MAAM,SAAS,MAAM;AACnB,IAAA,MAAM,IAAI,GAAA,EAAI;AACd,IAAA,IAAI,OAAA,IAAW,QAAA,CAAS,CAAC,CAAA,EAAG,MAAM,KAAA;AAClC,IAAA,OAAO,CAAA;AAAA,EACT,CAAA;AAIA,EAAA,MAAA,CAAO,cAAA,CAAe,QAAQ,MAAA,EAAQ,EAAE,OAAO,GAAA,CAAI,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,CAAA;AAC7E,EAAA,OAAO,MAAA;AACT","file":"chunk-FAIWRZKJ.js","sourcesContent":["/**\n * Forma Reactive - Dev Mode\n *\n * Development utilities stripped from production builds via __DEV__ flag.\n * Bundlers replace __DEV__ with false → dead-code elimination removes all dev paths.\n */\n\n// __DEV__ is replaced by the bundler (tsup define) for dead-code elimination in\n// dist. For unbundled/raw-source usage it derives from NODE_ENV, and — when the\n// environment is indeterminate — defaults to *false* (production-safe: no console\n// noise) unless a consumer opts in via a global __FORMA_DEV__.\ndeclare const process: { env?: Record<string, string | undefined> } | undefined;\ndeclare const __FORMA_DEV__: boolean | undefined;\n\n/**\n * Lazily evaluate whether we're in a dev environment. Read per-call (not frozen\n * at import) so runtime NODE_ENV changes are honored and so official prod dist\n * builds — where tsup hard-defines __DEV__ = false — stay quiet regardless.\n */\nfunction isDev(): boolean {\n if (typeof process !== 'undefined') {\n return process!.env?.NODE_ENV !== 'production';\n }\n return typeof __FORMA_DEV__ !== 'undefined' ? !!__FORMA_DEV__ : false;\n}\n\nexport const __DEV__: boolean = isDev();\n\n// ---------------------------------------------------------------------------\n// Global error handlers\n// ---------------------------------------------------------------------------\n\n/** Callback signature for a global {@link onError} handler. */\nexport type ErrorHandler = (error: unknown, info?: { source?: string }) => void;\n\nconst _errorHandlers = new Set<ErrorHandler>();\n\n/**\n * Install a global error handler for FormaJS reactive errors. Called when\n * effects, computeds, or event handlers throw. Multiple handlers may be\n * registered; returns an unsubscribe function that removes only this handler.\n *\n * ```ts\n * const off = onError((err, info) => {\n * Sentry.captureException(err, { tags: { source: info?.source } });\n * });\n * // later: off();\n * ```\n */\nexport function onError(handler: ErrorHandler): () => void {\n _errorHandlers.add(handler);\n return () => { _errorHandlers.delete(handler); };\n}\n\n/** @internal */\nexport function reportError(error: unknown, source?: string): void {\n for (const handler of _errorHandlers) {\n try { handler(error, source ? { source } : {}); } catch { /* prevent infinite loop */ }\n }\n if (isDev()) {\n console.error(`[forma] ${source ?? 'Unknown'} error:`, error);\n }\n}\n","/**\n * Forma Reactive - Signal\n *\n * Fine-grained reactive primitive backed by alien-signals.\n * API: createSignal returns [getter, setter] tuple following SolidJS conventions.\n *\n * TC39 Signals equivalent: Signal.State\n */\n\nimport { signal as createRawSignal, setActiveSub, trigger } from 'alien-signals';\nimport { __DEV__ } from './dev.js';\n\n// Debug names live in a side table rather than on the getter's `.name`, so\n// alien-signals' isSignal() (which keys off the bound function name) still\n// recognizes named signals.\nconst signalNames = new WeakMap<object, string>();\n\n/** Debug name of a signal getter, if one was provided (dev-only). */\nexport function getSignalName(fn: unknown): string | undefined {\n return typeof fn === 'function' ? signalNames.get(fn as object) : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/** A function that reads the current value of a signal. */\nexport type SignalGetter<T> = () => T;\n/** A function that updates a signal — accepts a value or an updater function. */\nexport type SignalSetter<T> = (v: T | ((prev: T) => T)) => void;\n\nexport interface SignalOptions<T> {\n /** Debug name — attached to getter in dev mode for devtools inspection. */\n name?: string;\n /**\n * Custom equality check. When provided, the setter will read the current\n * value and only update the signal if `equals(prev, next)` returns `false`.\n *\n * Default: none (alien-signals uses strict inequality `!==` internally).\n *\n * ```ts\n * const [pos, setPos] = createSignal(\n * { x: 0, y: 0 },\n * { equals: (a, b) => a.x === b.x && a.y === b.y },\n * );\n *\n * setPos({ x: 0, y: 0 }); // skipped — equals returns true\n * setPos({ x: 1, y: 0 }); // applied — equals returns false\n * ```\n */\n equals?: (prev: T, next: T) => boolean;\n}\n\n/**\n * Wrap a value so the setter treats it as a literal value, not a functional updater.\n *\n * When `T` is itself a function type, passing a function to the setter is\n * ambiguous -- it looks like a functional update (`prev => next`). Use\n * `value()` to disambiguate:\n *\n * ```ts\n * const [getFn, setFn] = createSignal<() => void>(() => console.log('a'));\n *\n * // BUG: interpreted as a functional update -- calls the arrow with prev\n * // setFn(() => console.log('b'));\n *\n * // Correct: wraps in a thunk so the setter stores it as-is\n * setFn(value(() => console.log('b')));\n * ```\n */\nexport function value<T>(v: T): () => T {\n return () => v;\n}\n\ntype RawSignal<T> = {\n (): T;\n (value: T): void;\n};\n\nfunction applySignalSet<T>(\n s: RawSignal<T>,\n v: T | ((prev: T) => T),\n equals?: (prev: T, next: T) => boolean,\n): void {\n // Fast path: plain value, no equals — no prev read needed. (A running effect\n // writing its own dependency is detected at the effect level via the Pending\n // flag, so signal.ts does not need to do anything special here.)\n if (typeof v !== 'function') {\n if (!equals) {\n s(v);\n return;\n }\n const prevSub = setActiveSub(undefined);\n const prev = s();\n setActiveSub(prevSub);\n if (equals(prev, v)) return; // suppressed by custom equality\n s(v);\n if (Object.is(prev, v)) forceNotify(s);\n return;\n }\n\n // Functional update: read prev without tracking.\n const prevSub = setActiveSub(undefined);\n const prev = s();\n setActiveSub(prevSub);\n const next = (v as (prev: T) => T)(prev);\n if (equals && equals(prev, next)) return; // suppressed by custom equality\n s(next);\n if (equals && Object.is(prev, next)) forceNotify(s);\n}\n\n/**\n * When a custom `equals` decided to APPLY (returned false) but the value is the\n * identical reference, alien-signals suppresses propagation (its guard is\n * `pendingValue !== value`). Force-notify subscribers so `equals: () => false`\n * (\"always notify\") works for mutate-in-place patterns.\n */\nfunction forceNotify<T>(s: RawSignal<T>): void {\n trigger(() => { s(); });\n}\n\n/**\n * Create a reactive signal.\n *\n * ```ts\n * const [count, setCount] = createSignal(0);\n * console.log(count()); // 0\n * setCount(1);\n * setCount(prev => prev + 1);\n * ```\n *\n * With custom equality:\n *\n * ```ts\n * const [pos, setPos] = createSignal(\n * { x: 0, y: 0 },\n * { equals: (a, b) => a.x === b.x && a.y === b.y },\n * );\n * ```\n */\nexport function createSignal<T>(initialValue: T, options?: SignalOptions<T>): [get: SignalGetter<T>, set: SignalSetter<T>] {\n const s = createRawSignal<T>(initialValue) as RawSignal<T>;\n const getter = s as unknown as SignalGetter<T>;\n if (__DEV__ && options?.name) {\n signalNames.set(getter as object, options.name);\n }\n const eq = options?.equals;\n const setter: SignalSetter<T> = (v: T | ((prev: T) => T)) => applySignalSet(s, v, eq);\n\n return [getter, setter];\n}\n","/**\n * Forma Reactive - Computed\n *\n * Lazy, cached derived value that participates in the reactive graph.\n * Backed by alien-signals for automatic dependency tracking\n * and cache invalidation.\n *\n * TC39 Signals equivalent: Signal.Computed\n */\n\nimport { computed as rawComputed } from 'alien-signals';\nimport { reportError } from './dev.js';\n\n/** Unique per-throw marker so alien-signals sees a value change and propagates. */\nconst ERR = Symbol('formaComputedError');\ninterface ErrBox { [ERR]: unknown; }\nfunction isErrBox(v: unknown): v is ErrBox {\n return typeof v === 'object' && v !== null && ERR in (v as object);\n}\n\n/**\n * Create a lazy, cached computed value.\n *\n * Note: Unlike SolidJS's createComputed (which is an eager synchronous\n * side effect), this is a lazy cached derivation — equivalent to\n * SolidJS's createMemo. Both createComputed and createMemo in FormaJS\n * are identical.\n *\n * The getter receives the previous value as an argument, enabling\n * efficient diffing patterns without a separate signal:\n *\n * ```ts\n * const [count, setCount] = createSignal(0);\n * const doubled = createComputed(() => count() * 2);\n * console.log(doubled()); // 0\n * setCount(5);\n * console.log(doubled()); // 10\n * ```\n *\n * With previous value (for diffing):\n *\n * ```ts\n * const changes = createComputed((prev) => {\n * const next = items();\n * if (prev) console.log(`changed from ${prev.length} to ${next.length} items`);\n * return next;\n * });\n * ```\n */\nexport function createComputed<T>(fn: (previousValue?: T) => T): () => T {\n // alien-signals' updateComputed leaves a throwing computed flagged clean with a\n // stale value, so a later read silently returns the stale value and never\n // rethrows. We cache the error in closure and rethrow on read until a\n // dependency changes (TC39/Solid). On throw we return a FRESH sentinel object so\n // alien-signals sees a value change and propagates the error to subscribers; the\n // user getter only ever sees the last GOOD value as `previousValue`.\n let errored = false;\n let error: unknown;\n let lastGood: T | undefined;\n\n const raw = rawComputed<T | ErrBox>(() => {\n try {\n const v = fn(lastGood);\n errored = false;\n error = undefined;\n lastGood = v;\n return v;\n } catch (e) {\n errored = true;\n error = e;\n reportError(e, 'computed');\n return { [ERR]: e };\n }\n });\n\n const reader = () => {\n const v = raw();\n if (errored || isErrBox(v)) throw error;\n return v as T;\n };\n // Preserve alien-signals' isComputed() recognition, which keys off the bound\n // function name (`bound computedOper`). Our reader wraps the raw computed, so\n // copy the raw name onto it.\n Object.defineProperty(reader, 'name', { value: raw.name, configurable: true });\n return reader;\n}\n"]}
|
|
@@ -29,6 +29,9 @@ function reportError(error, source) {
|
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
31
|
var signalNames = /* @__PURE__ */ new WeakMap();
|
|
32
|
+
function getSignalName(fn) {
|
|
33
|
+
return typeof fn === "function" ? signalNames.get(fn) : void 0;
|
|
34
|
+
}
|
|
32
35
|
function value(v) {
|
|
33
36
|
return () => v;
|
|
34
37
|
}
|
|
@@ -103,8 +106,9 @@ function createComputed(fn) {
|
|
|
103
106
|
exports.__DEV__ = __DEV__;
|
|
104
107
|
exports.createComputed = createComputed;
|
|
105
108
|
exports.createSignal = createSignal;
|
|
109
|
+
exports.getSignalName = getSignalName;
|
|
106
110
|
exports.onError = onError;
|
|
107
111
|
exports.reportError = reportError;
|
|
108
112
|
exports.value = value;
|
|
109
|
-
//# sourceMappingURL=chunk-
|
|
110
|
-
//# sourceMappingURL=chunk-
|
|
113
|
+
//# sourceMappingURL=chunk-HAULTMNX.cjs.map
|
|
114
|
+
//# sourceMappingURL=chunk-HAULTMNX.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/reactive/dev.ts","../src/reactive/signal.ts","../src/reactive/computed.ts"],"names":["prevSub","setActiveSub","prev","trigger","createRawSignal","rawComputed"],"mappings":";;;;;AAmBA,SAAS,KAAA,GAAiB;AACxB,EAAA,IAAI,OAAO,YAAY,WAAA,EAAa;AAClC,IAAA,OAAO,OAAA,CAAS,KAAK,QAAA,KAAa,YAAA;AAAA,EACpC;AACA,EAAA,OAAO,OAAO,aAAA,KAAkB,WAAA,GAAc,CAAC,CAAC,aAAA,GAAgB,KAAA;AAClE;AAEO,IAAM,UAAmB,KAAA;AAShC,IAAM,cAAA,uBAAqB,GAAA,EAAkB;AActC,SAAS,QAAQ,OAAA,EAAmC;AACzD,EAAA,cAAA,CAAe,IAAI,OAAO,CAAA;AAC1B,EAAA,OAAO,MAAM;AAAE,IAAA,cAAA,CAAe,OAAO,OAAO,CAAA;AAAA,EAAG,CAAA;AACjD;AAGO,SAAS,WAAA,CAAY,OAAgB,MAAA,EAAuB;AACjE,EAAA,KAAA,MAAW,WAAW,cAAA,EAAgB;AACpC,IAAA,IAAI;AAAE,MAAA,OAAA,CAAQ,OAAO,MAAA,GAAS,EAAE,MAAA,EAAO,GAAI,EAAE,CAAA;AAAA,IAAG,CAAA,CAAA,MAAQ;AAAA,IAA8B;AAAA,EACxF;AACA,EAAA,IAAI,OAAM,EAAG;AACX,IAAA,OAAA,CAAQ,KAAA,CAAM,CAAA,QAAA,EAAW,MAAA,IAAU,SAAS,WAAW,KAAK,CAAA;AAAA,EAC9D;AACF;AC/CA,IAAM,WAAA,uBAAkB,OAAA,EAAwB;AAGzC,SAAS,cAAc,EAAA,EAAiC;AAC7D,EAAA,OAAO,OAAO,EAAA,KAAO,UAAA,GAAa,WAAA,CAAY,GAAA,CAAI,EAAY,CAAA,GAAI,MAAA;AACpE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AA,CAAe,QAAQ,MAAA,EAAQ,EAAE,OAAO,GAAA,CAAI,IAAA,EAAM,YAAA,EAAc,IAAA,EAAM,CAAA;AAC7E,EAAA,OAAO,MAAA;AACT","file":"chunk-HAULTMNX.cjs","sourcesContent":["/**\n * Forma Reactive - Dev Mode\n *\n * Development utilities stripped from production builds via __DEV__ flag.\n * Bundlers replace __DEV__ with false → dead-code elimination removes all dev paths.\n */\n\n// __DEV__ is replaced by the bundler (tsup define) for dead-code elimination in\n// dist. For unbundled/raw-source usage it derives from NODE_ENV, and — when the\n// environment is indeterminate — defaults to *false* (production-safe: no console\n// noise) unless a consumer opts in via a global __FORMA_DEV__.\ndeclare const process: { env?: Record<string, string | undefined> } | undefined;\ndeclare const __FORMA_DEV__: boolean | undefined;\n\n/**\n * Lazily evaluate whether we're in a dev environment. Read per-call (not frozen\n * at import) so runtime NODE_ENV changes are honored and so official prod dist\n * builds — where tsup hard-defines __DEV__ = false — stay quiet regardless.\n */\nfunction isDev(): boolean {\n if (typeof process !== 'undefined') {\n return process!.env?.NODE_ENV !== 'production';\n }\n return typeof __FORMA_DEV__ !== 'undefined' ? !!__FORMA_DEV__ : false;\n}\n\nexport const __DEV__: boolean = isDev();\n\n// ---------------------------------------------------------------------------\n// Global error handlers\n// ---------------------------------------------------------------------------\n\n/** Callback signature for a global {@link onError} handler. */\nexport type ErrorHandler = (error: unknown, info?: { source?: string }) => void;\n\nconst _errorHandlers = new Set<ErrorHandler>();\n\n/**\n * Install a global error handler for FormaJS reactive errors. Called when\n * effects, computeds, or event handlers throw. Multiple handlers may be\n * registered; returns an unsubscribe function that removes only this handler.\n *\n * ```ts\n * const off = onError((err, info) => {\n * Sentry.captureException(err, { tags: { source: info?.source } });\n * });\n * // later: off();\n * ```\n */\nexport function onError(handler: ErrorHandler): () => void {\n _errorHandlers.add(handler);\n return () => { _errorHandlers.delete(handler); };\n}\n\n/** @internal */\nexport function reportError(error: unknown, source?: string): void {\n for (const handler of _errorHandlers) {\n try { handler(error, source ? { source } : {}); } catch { /* prevent infinite loop */ }\n }\n if (isDev()) {\n console.error(`[forma] ${source ?? 'Unknown'} error:`, error);\n }\n}\n","/**\n * Forma Reactive - Signal\n *\n * Fine-grained reactive primitive backed by alien-signals.\n * API: createSignal returns [getter, setter] tuple following SolidJS conventions.\n *\n * TC39 Signals equivalent: Signal.State\n */\n\nimport { signal as createRawSignal, setActiveSub, trigger } from 'alien-signals';\nimport { __DEV__ } from './dev.js';\n\n// Debug names live in a side table rather than on the getter's `.name`, so\n// alien-signals' isSignal() (which keys off the bound function name) still\n// recognizes named signals.\nconst signalNames = new WeakMap<object, string>();\n\n/** Debug name of a signal getter, if one was provided (dev-only). */\nexport function getSignalName(fn: unknown): string | undefined {\n return typeof fn === 'function' ? signalNames.get(fn as object) : undefined;\n}\n\n// ---------------------------------------------------------------------------\n// Public API\n// ---------------------------------------------------------------------------\n\n/** A function that reads the current value of a signal. */\nexport type SignalGetter<T> = () => T;\n/** A function that updates a signal — accepts a value or an updater function. */\nexport type SignalSetter<T> = (v: T | ((prev: T) => T)) => void;\n\nexport interface SignalOptions<T> {\n /** Debug name — attached to getter in dev mode for devtools inspection. */\n name?: string;\n /**\n * Custom equality check. When provided, the setter will read the current\n * value and only update the signal if `equals(prev, next)` returns `false`.\n *\n * Default: none (alien-signals uses strict inequality `!==` internally).\n *\n * ```ts\n * const [pos, setPos] = createSignal(\n * { x: 0, y: 0 },\n * { equals: (a, b) => a.x === b.x && a.y === b.y },\n * );\n *\n * setPos({ x: 0, y: 0 }); // skipped — equals returns true\n * setPos({ x: 1, y: 0 }); // applied — equals returns false\n * ```\n */\n equals?: (prev: T, next: T) => boolean;\n}\n\n/**\n * Wrap a value so the setter treats it as a literal value, not a functional updater.\n *\n * When `T` is itself a function type, passing a function to the setter is\n * ambiguous -- it looks like a functional update (`prev => next`). Use\n * `value()` to disambiguate:\n *\n * ```ts\n * const [getFn, setFn] = createSignal<() => void>(() => console.log('a'));\n *\n * // BUG: interpreted as a functional update -- calls the arrow with prev\n * // setFn(() => console.log('b'));\n *\n * // Correct: wraps in a thunk so the setter stores it as-is\n * setFn(value(() => console.log('b')));\n * ```\n */\nexport function value<T>(v: T): () => T {\n return () => v;\n}\n\ntype RawSignal<T> = {\n (): T;\n (value: T): void;\n};\n\nfunction applySignalSet<T>(\n s: RawSignal<T>,\n v: T | ((prev: T) => T),\n equals?: (prev: T, next: T) => boolean,\n): void {\n // Fast path: plain value, no equals — no prev read needed. (A running effect\n // writing its own dependency is detected at the effect level via the Pending\n // flag, so signal.ts does not need to do anything special here.)\n if (typeof v !== 'function') {\n if (!equals) {\n s(v);\n return;\n }\n const prevSub = setActiveSub(undefined);\n const prev = s();\n setActiveSub(prevSub);\n if (equals(prev, v)) return; // suppressed by custom equality\n s(v);\n if (Object.is(prev, v)) forceNotify(s);\n return;\n }\n\n // Functional update: read prev without tracking.\n const prevSub = setActiveSub(undefined);\n const prev = s();\n setActiveSub(prevSub);\n const next = (v as (prev: T) => T)(prev);\n if (equals && equals(prev, next)) return; // suppressed by custom equality\n s(next);\n if (equals && Object.is(prev, next)) forceNotify(s);\n}\n\n/**\n * When a custom `equals` decided to APPLY (returned false) but the value is the\n * identical reference, alien-signals suppresses propagation (its guard is\n * `pendingValue !== value`). Force-notify subscribers so `equals: () => false`\n * (\"always notify\") works for mutate-in-place patterns.\n */\nfunction forceNotify<T>(s: RawSignal<T>): void {\n trigger(() => { s(); });\n}\n\n/**\n * Create a reactive signal.\n *\n * ```ts\n * const [count, setCount] = createSignal(0);\n * console.log(count()); // 0\n * setCount(1);\n * setCount(prev => prev + 1);\n * ```\n *\n * With custom equality:\n *\n * ```ts\n * const [pos, setPos] = createSignal(\n * { x: 0, y: 0 },\n * { equals: (a, b) => a.x === b.x && a.y === b.y },\n * );\n * ```\n */\nexport function createSignal<T>(initialValue: T, options?: SignalOptions<T>): [get: SignalGetter<T>, set: SignalSetter<T>] {\n const s = createRawSignal<T>(initialValue) as RawSignal<T>;\n const getter = s as unknown as SignalGetter<T>;\n if (__DEV__ && options?.name) {\n signalNames.set(getter as object, options.name);\n }\n const eq = options?.equals;\n const setter: SignalSetter<T> = (v: T | ((prev: T) => T)) => applySignalSet(s, v, eq);\n\n return [getter, setter];\n}\n","/**\n * Forma Reactive - Computed\n *\n * Lazy, cached derived value that participates in the reactive graph.\n * Backed by alien-signals for automatic dependency tracking\n * and cache invalidation.\n *\n * TC39 Signals equivalent: Signal.Computed\n */\n\nimport { computed as rawComputed } from 'alien-signals';\nimport { reportError } from './dev.js';\n\n/** Unique per-throw marker so alien-signals sees a value change and propagates. */\nconst ERR = Symbol('formaComputedError');\ninterface ErrBox { [ERR]: unknown; }\nfunction isErrBox(v: unknown): v is ErrBox {\n return typeof v === 'object' && v !== null && ERR in (v as object);\n}\n\n/**\n * Create a lazy, cached computed value.\n *\n * Note: Unlike SolidJS's createComputed (which is an eager synchronous\n * side effect), this is a lazy cached derivation — equivalent to\n * SolidJS's createMemo. Both createComputed and createMemo in FormaJS\n * are identical.\n *\n * The getter receives the previous value as an argument, enabling\n * efficient diffing patterns without a separate signal:\n *\n * ```ts\n * const [count, setCount] = createSignal(0);\n * const doubled = createComputed(() => count() * 2);\n * console.log(doubled()); // 0\n * setCount(5);\n * console.log(doubled()); // 10\n * ```\n *\n * With previous value (for diffing):\n *\n * ```ts\n * const changes = createComputed((prev) => {\n * const next = items();\n * if (prev) console.log(`changed from ${prev.length} to ${next.length} items`);\n * return next;\n * });\n * ```\n */\nexport function createComputed<T>(fn: (previousValue?: T) => T): () => T {\n // alien-signals' updateComputed leaves a throwing computed flagged clean with a\n // stale value, so a later read silently returns the stale value and never\n // rethrows. We cache the error in closure and rethrow on read until a\n // dependency changes (TC39/Solid). On throw we return a FRESH sentinel object so\n // alien-signals sees a value change and propagates the error to subscribers; the\n // user getter only ever sees the last GOOD value as `previousValue`.\n let errored = false;\n let error: unknown;\n let lastGood: T | undefined;\n\n const raw = rawComputed<T | ErrBox>(() => {\n try {\n const v = fn(lastGood);\n errored = false;\n error = undefined;\n lastGood = v;\n return v;\n } catch (e) {\n errored = true;\n error = e;\n reportError(e, 'computed');\n return { [ERR]: e };\n }\n });\n\n const reader = () => {\n const v = raw();\n if (errored || isErrBox(v)) throw error;\n return v as T;\n };\n // Preserve alien-signals' isComputed() recognition, which keys off the bound\n // function name (`bound computedOper`). Our reader wraps the raw computed, so\n // copy the raw name onto it.\n Object.defineProperty(reader, 'name', { value: raw.name, configurable: true });\n return reader;\n}\n"]}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var chunkHAULTMNX_cjs = require('./chunk-HAULTMNX.cjs');
|
|
4
4
|
var alienSignals = require('alien-signals');
|
|
5
5
|
|
|
6
6
|
var currentRoot = null;
|
|
@@ -152,7 +152,7 @@ function runCleanup(fn) {
|
|
|
152
152
|
try {
|
|
153
153
|
fn();
|
|
154
154
|
} catch (e) {
|
|
155
|
-
|
|
155
|
+
chunkHAULTMNX_cjs.reportError(e, "effect cleanup");
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
158
|
function runCleanups(bag) {
|
|
@@ -161,7 +161,7 @@ function runCleanups(bag) {
|
|
|
161
161
|
try {
|
|
162
162
|
bag[i]();
|
|
163
163
|
} catch (e) {
|
|
164
|
-
|
|
164
|
+
chunkHAULTMNX_cjs.reportError(e, "effect cleanup");
|
|
165
165
|
}
|
|
166
166
|
}
|
|
167
167
|
}
|
|
@@ -218,7 +218,7 @@ function createEffect(fn) {
|
|
|
218
218
|
cleanup = nextCleanup;
|
|
219
219
|
}
|
|
220
220
|
} catch (e) {
|
|
221
|
-
|
|
221
|
+
chunkHAULTMNX_cjs.reportError(e, "effect");
|
|
222
222
|
if (nextCleanupBag !== void 0) {
|
|
223
223
|
cleanupBag = nextCleanupBag;
|
|
224
224
|
} else if (nextCleanup !== void 0) {
|
|
@@ -237,7 +237,7 @@ function createEffect(fn) {
|
|
|
237
237
|
if (node === void 0 || (node.flags & PENDING) === 0) break;
|
|
238
238
|
if (++reentrantRuns >= MAX_REENTRANT_RUNS) {
|
|
239
239
|
node.flags &= ~PENDING;
|
|
240
|
-
|
|
240
|
+
chunkHAULTMNX_cjs.reportError(
|
|
241
241
|
new Error(`createEffect exceeded ${MAX_REENTRANT_RUNS} self-triggered re-runs (cycle?)`),
|
|
242
242
|
"effect"
|
|
243
243
|
);
|
|
@@ -269,7 +269,7 @@ function createEffect(fn) {
|
|
|
269
269
|
}
|
|
270
270
|
|
|
271
271
|
// src/reactive/memo.ts
|
|
272
|
-
var createMemo =
|
|
272
|
+
var createMemo = chunkHAULTMNX_cjs.createComputed;
|
|
273
273
|
function batch(fn) {
|
|
274
274
|
alienSignals.startBatch();
|
|
275
275
|
try {
|
|
@@ -311,7 +311,7 @@ function createRef(initialValue) {
|
|
|
311
311
|
|
|
312
312
|
// src/reactive/reducer.ts
|
|
313
313
|
function createReducer(reducer, initialState) {
|
|
314
|
-
const [state, setState] =
|
|
314
|
+
const [state, setState] = chunkHAULTMNX_cjs.createSignal(initialState);
|
|
315
315
|
const dispatch = (action) => {
|
|
316
316
|
setState((prev) => reducer(prev, action));
|
|
317
317
|
};
|
|
@@ -334,9 +334,9 @@ function getSuspenseContext() {
|
|
|
334
334
|
|
|
335
335
|
// src/reactive/resource.ts
|
|
336
336
|
function createResource(source, fetcher, options) {
|
|
337
|
-
const [data, setData] =
|
|
338
|
-
const [loading, setLoading] =
|
|
339
|
-
const [error, setError] =
|
|
337
|
+
const [data, setData] = chunkHAULTMNX_cjs.createSignal(options?.initialValue);
|
|
338
|
+
const [loading, setLoading] = chunkHAULTMNX_cjs.createSignal(false);
|
|
339
|
+
const [error, setError] = chunkHAULTMNX_cjs.createSignal(void 0);
|
|
340
340
|
const suspenseCtx = getSuspenseContext();
|
|
341
341
|
let abortController = null;
|
|
342
342
|
let fetchVersion = 0;
|
|
@@ -438,12 +438,14 @@ exports.createRef = createRef;
|
|
|
438
438
|
exports.createResource = createResource;
|
|
439
439
|
exports.createRoot = createRoot;
|
|
440
440
|
exports.createUnownedRoot = createUnownedRoot;
|
|
441
|
+
exports.getOwner = getOwner;
|
|
441
442
|
exports.internalEffect = internalEffect;
|
|
442
443
|
exports.on = on;
|
|
443
444
|
exports.onCleanup = onCleanup;
|
|
444
445
|
exports.popSuspenseContext = popSuspenseContext;
|
|
445
446
|
exports.pushSuspenseContext = pushSuspenseContext;
|
|
446
447
|
exports.registerDisposer = registerDisposer;
|
|
448
|
+
exports.runWithOwner = runWithOwner;
|
|
447
449
|
exports.untrack = untrack;
|
|
448
|
-
//# sourceMappingURL=chunk-
|
|
449
|
-
//# sourceMappingURL=chunk-
|
|
450
|
+
//# sourceMappingURL=chunk-PAKPQRVE.cjs.map
|
|
451
|
+
//# sourceMappingURL=chunk-PAKPQRVE.cjs.map
|