@getforma/core 1.3.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 +69 -16
- package/dist/server.cjs.map +1 -1
- package/dist/server.d.cts +31 -5
- package/dist/server.d.ts +31 -5
- package/dist/server.js +64 -12
- package/dist/server.js.map +1 -1
- 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/ssr/index.cjs +22 -4
- package/dist/ssr/index.cjs.map +1 -1
- package/dist/ssr/index.d.cts +7 -0
- package/dist/ssr/index.d.ts +7 -0
- package/dist/ssr/index.js +22 -4
- package/dist/ssr/index.js.map +1 -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 +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","setActiveSub","reportError","rawEffect","getActiveSub","createComputed","startBatch","endBatch","value","createSignal"],"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;A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,MACpB;AAAA,IACF,CAAC,CAAA;AAAA,EACL,CAAA;AAGA,EAAA,cAAA,CAAe,MAAM;AACnB,IAAA,MAAA,EAAO;AACP,IAAA,OAAA,EAAQ;AAAA,EACV,CAAC,CAAA;AAKD,EAAA,IAAI,eAAc,EAAG;AACnB,IAAA,gBAAA,CAAiB,MAAM;AAGrB,MAAA,YAAA,EAAA;AACA,MAAA,IAAI,eAAA,EAAiB;AACnB,QAAA,eAAA,CAAgB,KAAA,EAAM;AACtB,QAAA,eAAA,GAAkB,IAAA;AAAA,MACpB;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAGA,EAAA,MAAM,QAAA,IAAY,MAAM,IAAA,EAAK,CAAA;AAC7B,EAAA,QAAA,CAAS,OAAA,GAAU,OAAA;AACnB,EAAA,QAAA,CAAS,KAAA,GAAQ,KAAA;AACjB,EAAA,QAAA,CAAS,OAAA,GAAU,OAAA;AACnB,EAAA,QAAA,CAAS,MAAA,GAAS,CAACD,MAAAA,KAAU,OAAA,CAAQ,MAAMA,MAAK,CAAA;AAEhD,EAAA,OAAO,QAAA;AACT","file":"chunk-KUXNZ5MG.cjs","sourcesContent":["/**\n * Forma Reactive - Root\n *\n * Explicit reactive ownership scope. 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","setActiveSub","reportError","rawEffect","getActiveSub","createComputed","startBatch","endBatch","value","createSignal"],"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,E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A,EAAS,IAAK,eAAA,KAAoB,UAAA,EAAY;AAChD,QAAA,eAAA,GAAkB,IAAA;AAAA,MACpB;AAAA,IACF,CAAC,CAAA;AAAA,EACL,CAAA;AAGA,EAAA,cAAA,CAAe,MAAM;AACnB,IAAA,MAAA,EAAO;AACP,IAAA,OAAA,EAAQ;AAAA,EACV,CAAC,CAAA;AAKD,EAAA,IAAI,eAAc,EAAG;AACnB,IAAA,gBAAA,CAAiB,MAAM;AAGrB,MAAA,YAAA,EAAA;AACA,MAAA,IAAI,eAAA,EAAiB;AACnB,QAAA,eAAA,CAAgB,KAAA,EAAM;AACtB,QAAA,eAAA,GAAkB,IAAA;AAAA,MACpB;AAAA,IACF,CAAC,CAAA;AAAA,EACH;AAGA,EAAA,MAAM,QAAA,IAAY,MAAM,IAAA,EAAK,CAAA;AAC7B,EAAA,QAAA,CAAS,OAAA,GAAU,OAAA;AACnB,EAAA,QAAA,CAAS,KAAA,GAAQ,KAAA;AACjB,EAAA,QAAA,CAAS,OAAA,GAAU,OAAA;AACnB,EAAA,QAAA,CAAS,MAAA,GAAS,CAACD,MAAAA,KAAU,OAAA,CAAQ,MAAMA,MAAK,CAAA;AAEhD,EAAA,OAAO,QAAA;AACT","file":"chunk-PAKPQRVE.cjs","sourcesContent":["/**\n * Forma Reactive - Root\n *\n * Explicit reactive ownership scope. 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"]}
|
package/dist/formajs.global.js
CHANGED
|
@@ -57,6 +57,8 @@ var FormaJS = (() => {
|
|
|
57
57
|
disposeComponent: () => disposeComponent,
|
|
58
58
|
fragment: () => fragment,
|
|
59
59
|
getBatchDepth: () => getBatchDepth,
|
|
60
|
+
getOwner: () => getOwner,
|
|
61
|
+
getSignalName: () => getSignalName,
|
|
60
62
|
h: () => h,
|
|
61
63
|
hydrateIsland: () => hydrateIsland,
|
|
62
64
|
inject: () => inject,
|
|
@@ -81,6 +83,7 @@ var FormaJS = (() => {
|
|
|
81
83
|
provide: () => provide,
|
|
82
84
|
reconcileList: () => reconcileList,
|
|
83
85
|
removeClass: () => removeClass,
|
|
86
|
+
runWithOwner: () => runWithOwner,
|
|
84
87
|
setAttr: () => setAttr,
|
|
85
88
|
setHTMLUnsafe: () => setHTMLUnsafe,
|
|
86
89
|
setStyle: () => setStyle,
|
|
@@ -93,7 +96,8 @@ var FormaJS = (() => {
|
|
|
93
96
|
trackDisposer: () => trackDisposer,
|
|
94
97
|
trigger: () => trigger,
|
|
95
98
|
unprovide: () => unprovide,
|
|
96
|
-
untrack: () => untrack
|
|
99
|
+
untrack: () => untrack,
|
|
100
|
+
value: () => value
|
|
97
101
|
});
|
|
98
102
|
|
|
99
103
|
// node_modules/alien-signals/esm/system.mjs
|
|
@@ -626,6 +630,9 @@ var FormaJS = (() => {
|
|
|
626
630
|
|
|
627
631
|
// src/reactive/signal.ts
|
|
628
632
|
var signalNames = /* @__PURE__ */ new WeakMap();
|
|
633
|
+
function getSignalName(fn) {
|
|
634
|
+
return typeof fn === "function" ? signalNames.get(fn) : void 0;
|
|
635
|
+
}
|
|
629
636
|
function value(v) {
|
|
630
637
|
return () => v;
|
|
631
638
|
}
|
|
@@ -3086,6 +3093,13 @@ var FormaJS = (() => {
|
|
|
3086
3093
|
}
|
|
3087
3094
|
currentLifecycleContext.unmountCallbacks.push(fn);
|
|
3088
3095
|
}
|
|
3096
|
+
function registerContextDisposer(dispose) {
|
|
3097
|
+
if (currentLifecycleContext !== null) {
|
|
3098
|
+
currentLifecycleContext.contextDisposers.push(dispose);
|
|
3099
|
+
return true;
|
|
3100
|
+
}
|
|
3101
|
+
return false;
|
|
3102
|
+
}
|
|
3089
3103
|
var DISPOSE_KEY = /* @__PURE__ */ Symbol("forma:component:dispose");
|
|
3090
3104
|
function defineComponent(setupOrDef) {
|
|
3091
3105
|
const setup = typeof setupOrDef === "function" ? setupOrDef : setupOrDef.setup;
|
|
@@ -3094,16 +3108,29 @@ var FormaJS = (() => {
|
|
|
3094
3108
|
const ctx = {
|
|
3095
3109
|
disposers: [],
|
|
3096
3110
|
mountCallbacks: [],
|
|
3097
|
-
unmountCallbacks: []
|
|
3111
|
+
unmountCallbacks: [],
|
|
3112
|
+
contextDisposers: []
|
|
3098
3113
|
};
|
|
3099
3114
|
pushLifecycleContext(ctx);
|
|
3100
3115
|
let dom;
|
|
3101
3116
|
try {
|
|
3102
3117
|
dom = setup();
|
|
3118
|
+
} catch (e) {
|
|
3119
|
+
for (let i = ctx.contextDisposers.length - 1; i >= 0; i--) {
|
|
3120
|
+
try {
|
|
3121
|
+
ctx.contextDisposers[i]();
|
|
3122
|
+
} catch {
|
|
3123
|
+
}
|
|
3124
|
+
}
|
|
3125
|
+
ctx.contextDisposers.length = 0;
|
|
3126
|
+
throw e;
|
|
3103
3127
|
} finally {
|
|
3104
3128
|
popLifecycleContext();
|
|
3105
3129
|
}
|
|
3130
|
+
let disposed = false;
|
|
3106
3131
|
const dispose = () => {
|
|
3132
|
+
if (disposed) return;
|
|
3133
|
+
disposed = true;
|
|
3107
3134
|
for (const cb of ctx.unmountCallbacks) {
|
|
3108
3135
|
try {
|
|
3109
3136
|
cb();
|
|
@@ -3118,20 +3145,38 @@ var FormaJS = (() => {
|
|
|
3118
3145
|
reportError(e, "component disposer");
|
|
3119
3146
|
}
|
|
3120
3147
|
}
|
|
3148
|
+
for (let i = ctx.contextDisposers.length - 1; i >= 0; i--) {
|
|
3149
|
+
try {
|
|
3150
|
+
ctx.contextDisposers[i]();
|
|
3151
|
+
} catch (e) {
|
|
3152
|
+
reportError(e, "context disposer");
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3121
3155
|
ctx.disposers.length = 0;
|
|
3122
3156
|
ctx.mountCallbacks.length = 0;
|
|
3123
3157
|
ctx.unmountCallbacks.length = 0;
|
|
3158
|
+
ctx.contextDisposers.length = 0;
|
|
3124
3159
|
};
|
|
3125
3160
|
dom[DISPOSE_KEY] = dispose;
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3161
|
+
if (dom.nodeType === 11) {
|
|
3162
|
+
for (const child of Array.from(dom.childNodes)) {
|
|
3163
|
+
child[DISPOSE_KEY] = dispose;
|
|
3164
|
+
}
|
|
3165
|
+
}
|
|
3166
|
+
pushLifecycleContext(ctx);
|
|
3167
|
+
try {
|
|
3168
|
+
for (const cb of ctx.mountCallbacks) {
|
|
3169
|
+
try {
|
|
3170
|
+
const cleanup2 = cb();
|
|
3171
|
+
if (typeof cleanup2 === "function") {
|
|
3172
|
+
ctx.unmountCallbacks.push(cleanup2);
|
|
3173
|
+
}
|
|
3174
|
+
} catch (e) {
|
|
3175
|
+
reportError(e, "onMount");
|
|
3131
3176
|
}
|
|
3132
|
-
} catch (e) {
|
|
3133
|
-
reportError(e, "onMount");
|
|
3134
3177
|
}
|
|
3178
|
+
} finally {
|
|
3179
|
+
popLifecycleContext();
|
|
3135
3180
|
}
|
|
3136
3181
|
return dom;
|
|
3137
3182
|
};
|
|
@@ -3151,6 +3196,17 @@ var FormaJS = (() => {
|
|
|
3151
3196
|
|
|
3152
3197
|
// src/component/context.ts
|
|
3153
3198
|
var contextStacks = /* @__PURE__ */ new Map();
|
|
3199
|
+
function removeFrame(id, token) {
|
|
3200
|
+
const stack = contextStacks.get(id);
|
|
3201
|
+
if (!stack) return;
|
|
3202
|
+
for (let i = stack.length - 1; i >= 0; i--) {
|
|
3203
|
+
if (stack[i].token === token) {
|
|
3204
|
+
stack.splice(i, 1);
|
|
3205
|
+
break;
|
|
3206
|
+
}
|
|
3207
|
+
}
|
|
3208
|
+
if (stack.length === 0) contextStacks.delete(id);
|
|
3209
|
+
}
|
|
3154
3210
|
function createContext(defaultValue) {
|
|
3155
3211
|
return {
|
|
3156
3212
|
id: /* @__PURE__ */ Symbol("forma:context"),
|
|
@@ -3163,14 +3219,16 @@ var FormaJS = (() => {
|
|
|
3163
3219
|
stack = [];
|
|
3164
3220
|
contextStacks.set(ctx.id, stack);
|
|
3165
3221
|
}
|
|
3166
|
-
|
|
3222
|
+
const token = /* @__PURE__ */ Symbol("forma:context-frame");
|
|
3223
|
+
stack.push({ token, value: value2 });
|
|
3224
|
+
registerContextDisposer(() => removeFrame(ctx.id, token));
|
|
3167
3225
|
}
|
|
3168
3226
|
function inject(ctx) {
|
|
3169
3227
|
const stack = contextStacks.get(ctx.id);
|
|
3170
3228
|
if (stack === void 0 || stack.length === 0) {
|
|
3171
3229
|
return ctx.defaultValue;
|
|
3172
3230
|
}
|
|
3173
|
-
return stack[stack.length - 1];
|
|
3231
|
+
return stack[stack.length - 1].value;
|
|
3174
3232
|
}
|
|
3175
3233
|
function unprovide(ctx) {
|
|
3176
3234
|
const stack = contextStacks.get(ctx.id);
|