{"name":"@solidjs/signals","version":"0.10.1","author":{"name":"Ryan Carniato"},"license":"MIT","_id":"@solidjs/signals@0.10.1","maintainers":[{"name":"ryansolid","email":"ryansolid@gmail.com"},{"name":"davedbase","email":"dave.dibiase@gmail.com"}],"homepage":"https://github.com/solidjs/signals#readme","bugs":{"url":"https://github.com/solidjs/signals/issues"},"dist":{"shasum":"ec479ccead5f3a1db3d4f4ab12019fadc29aa101","tarball":"http://registry-npm.ywwl.com/@solidjs/signals/download/@solidjs/signals-0.10.1.tgz","fileCount":30,"integrity":"sha512-JlSeRLYGVZsepAJIpxzqqPT8ncrHwi8BDDYw2EgmyKgsD0F83wIV4IYqDCBQppu9GekOcwry9QTNK7hLfktA6Q==","signatures":[{"sig":"MEUCIQDu72HRqVPYN0wnDvGI+1ibYkHpBk+OJJcZeC/u3UAehAIgPcrSz2gaxbVDJ/gUY4A8tob43xik7zyF8GCsX3dWlr0=","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":266759,"size":62336,"noattachment":false,"key":"/@solidjs/signals/-/@solidjs/signals-0.10.1.tgz"},"main":"dist/node.cjs","type":"module","_from":"file:solidjs-signals-0.10.1.tgz","types":"dist/types/index.d.ts","module":"dist/prod.js","exports":{".":{"types":"./dist/types/index.d.ts","import":{"test":"./dist/dev.js","default":"./dist/prod.js","development":"./dist/dev.js"},"require":"./dist/node.cjs"}},"scripts":{"test":"vitest run","bench":"vitest bench --run","build":"rimraf dist && rollup -c && pnpm types","types":"tsc -p tsconfig.build.json","format":"prettier src tests --write --log-level warn","sandbox":"node ./.sandbox/launch.js","test:gc":"node --expose-gc ./vitest.js","test:watch":"vitest watch tests","test:coverage":"vitest run --coverage","test:gc:watch":"node --expose-gc ./vitest.js --watch"},"_npmUser":{"name":"ryansolid","email":"ryansolid@gmail.com"},"_resolved":"/private/var/folders/7b/v8txpzbd433f4c08mx7w7b880000gn/T/7d737f37c817100d95da8548266d8b3d/solidjs-signals-0.10.1.tgz","_integrity":"sha512-JlSeRLYGVZsepAJIpxzqqPT8ncrHwi8BDDYw2EgmyKgsD0F83wIV4IYqDCBQppu9GekOcwry9QTNK7hLfktA6Q==","repository":{"url":"git+https://github.com/solidjs/signals.git","type":"git"},"_npmVersion":"11.3.0","description":"SolidJS' standalone reactive implementation","directories":{},"_nodeVersion":"24.0.1","publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"vite":"^5.4.10","tslib":"^2.8.1","rimraf":"^5.0.1","rollup":"^4.53.4","vitest":"^2.0.0","typescript":"5.9.3","@types/node":"^25.0.8","@rollup/plugin-terser":"^0.4.4","@rollup/plugin-replace":"^6.0.3","rollup-plugin-prettier":"^4.1.2","@rollup/plugin-typescript":"^12.3.0","@ianvs/prettier-plugin-sort-imports":"^4.1.1"},"_npmOperationalInternal":{"tmp":"tmp/signals_0.10.1_1771006675427_0.8513391576610994","host":"s3://npm-registry-packages-npm-production"},"readme":"# @solidjs/signals\n\nThe reactive core that powers [SolidJS 2.0](https://github.com/solidjs/solid). It is developed in the Solid monorepo and includes first-class support for async, transitions, optimistic updates, and deeply reactive stores that go beyond what general-purpose signals libraries offer.\n\n> This package is the reactive foundation of SolidJS 2.0.\n\n## Installation\n\n```bash\nnpm install @solidjs/signals\n# or\npnpm add @solidjs/signals\n```\n\n## Overview\n\n`@solidjs/signals` is a push-pull hybrid reactive system. Signals hold values, computeds derive from them, and effects run side effects — all connected through an automatic dependency graph. Updates are **batched** and flushed asynchronously via microtask, giving you consistent state without glitches.\n\n```typescript\nimport { createEffect, createMemo, createRoot, createSignal, flush } from \"@solidjs/signals\";\n\ncreateRoot(() => {\n  const [count, setCount] = createSignal(0);\n  const doubled = createMemo(() => count() * 2);\n\n  createEffect(\n    () => doubled(),\n    value => {\n      console.log(\"Doubled:\", value);\n    }\n  );\n\n  setCount(5);\n  flush(); // \"Doubled: 10\"\n});\n```\n\n### Batched Updates\n\nSignal writes are batched — reads after a write won't reflect the new value until `flush()` runs. This prevents glitches and unnecessary recomputation.\n\n```typescript\nconst [a, setA] = createSignal(1);\nconst [b, setB] = createSignal(2);\n\nsetA(10);\nsetB(20);\n// Neither has updated yet — both writes are batched\nflush(); // Now both update and downstream effects run once\n```\n\n## Core Primitives\n\n### Signals\n\n```typescript\nconst [value, setValue] = createSignal(initialValue, options?);\n```\n\nReactive state with a getter/setter pair. Supports custom equality via `options.equals`.\n\n### Memos\n\n```typescript\nconst derived = createMemo(() => expensive(signal()));\n```\n\nRead-only derived values that cache their result and only recompute when dependencies change. Supports async compute functions — return a `Promise` or `AsyncIterable` and downstream consumers will wait automatically.\n\n### Effects\n\n```typescript\n// Two-phase: compute tracks dependencies, effect runs side effects\ncreateEffect(\n  () => count(),\n  value => {\n    console.log(value);\n  }\n);\n\n// Render-phase effect (runs before user effects)\ncreateRenderEffect(\n  () => count(),\n  value => {\n    updateDOM(value);\n  }\n);\n```\n\nEffects split tracking from execution. `createEffect` and `createRenderEffect` take a compute function (for tracking) and an effect function (for side effects).\n\n### Writable Memos\n\nPass a function to `createSignal` to get a writable derived value — a memo you can also set:\n\n```typescript\nconst [value, setValue] = createSignal(prev => transform(source(), prev), initialValue);\n```\n\n## Async\n\nComputeds can return promises or async iterables. The reactive graph handles this automatically — previous values are held in place until the async work resolves, so downstream consumers never see an inconsistent state.\n\n```typescript\nconst data = createMemo(async () => {\n  const response = await fetch(`/api/items?q=${query()}`);\n  return response.json();\n});\n\n// Check async state for this read\nisPending(data); // true while an unrevealed value change is in flight for this read\nlatest(data); // last resolved value; follows the not-ready path if no value has resolved yet\n```\n\nUse `action()` for mutations — imperative async workflows whose writes span an async gap. Each invocation runs as a single transaction: every write between yields batches into one atomic update, and nothing commits until the action completes or the next `yield` resolves.\n\n```typescript\nconst save = action(function* (item) {\n  yield fetch(\"/api/save\", { method: \"POST\", body: JSON.stringify(item) });\n});\n```\n\nNavigation-shaped updates don't need an action. A plain setter call is enough — reads pull the async, downstream async computeds hold their previous values until new ones are ready, and `isPending`/`latest` expose the in-flight state. Reach for `action` when writes happen *after* async work (pairing with optimistic primitives for tentative state that reverts on failure), not when the async is merely downstream of a synchronous write.\n\nFramework-level actions (router form actions, server actions) are specializations of this primitive: the same transactional semantics with form binding, serialization, and submission tracking layered on top.\n\n## Optimistic Updates\n\nOptimistic signals show an immediate value while async work is pending, then automatically revert when it settles:\n\n```typescript\nconst [optimisticCount, setOptimisticCount] = createOptimistic(0);\n\n// Immediate UI update — reverts when the async work resolves\nsetOptimisticCount(count + 1);\n```\n\nAlso available for stores via `createOptimisticStore()`.\n\n## Stores\n\nProxy-based deeply reactive objects with per-property tracking:\n\n```typescript\nimport { createStore, reconcile } from \"@solidjs/signals\";\n\nconst [store, setStore] = createStore({ todos: [], filter: \"all\" });\n\n// Setter takes a mutating callback — mutations are intercepted by the proxy\nsetStore(s => {\n  s.filter = \"active\";\n});\nsetStore(s => {\n  s.todos.push({ text: \"New\", done: false });\n});\nsetStore(s => {\n  s.todos[0].done = true;\n});\n\n// Reconcile from server data\nsetStore(s => {\n  reconcile(serverTodos, \"id\")(s.todos);\n});\n```\n\n### Projections\n\nDerived stores that transform data reactively:\n\n```typescript\nimport { createProjection } from \"@solidjs/signals\";\n\nconst filtered = createProjection(\n  draft => {\n    draft.items = store.todos.filter(t => !t.done);\n  },\n  { items: [] }\n);\n```\n\n## Boundaries\n\nIntercept async loading and error states in the reactive graph:\n\n```typescript\nimport { createErrorBoundary, createLoadingBoundary } from \"@solidjs/signals\";\n\ncreateErrorBoundary(\n  () => riskyComputation(),\n  (error, reset) => handleError(error())\n);\n\ncreateLoadingBoundary(\n  () => asyncContent(),\n  () => showFallback()\n);\n```\n\n## Ownership & Context\n\nAll reactive nodes exist within an **owner** tree that handles disposal and context propagation:\n\n```typescript\nimport { createContext, createRoot, getContext, onCleanup, setContext } from \"@solidjs/signals\";\n\nconst ThemeContext = createContext(\"light\");\n\ncreateRoot(dispose => {\n  setContext(ThemeContext, \"dark\");\n\n  createEffect(\n    () => getContext(ThemeContext),\n    theme => {\n      console.log(\"Theme:\", theme);\n    }\n  );\n\n  onCleanup(() => console.log(\"Disposed\"));\n\n  // Call dispose() to tear down the tree\n});\n```\n\n## Utilities\n\n| Function                 | Description                                                        |\n| ------------------------ | ------------------------------------------------------------------ |\n| `flush()`                | Process all pending updates                                        |\n| `untrack(fn)`            | Run `fn` without tracking dependencies                             |\n| `isPending(accessor)`    | Check if an unrevealed value change is in flight for a read        |\n| `latest(accessor)`       | Get the last resolved value, or follow not-ready if none exists    |\n| `refresh(accessor)`      | Re-trigger an async computation (a quiet re-ask — not pending)     |\n| `affects(target, key?)` | Declare that in-flight work will change the targeted data (reads pending until settle) |\n| `resolve(fn)`            | Returns a promise that resolves when a reactive expression settles |\n| `mapArray(list, mapFn)`  | Reactive array mapping with keyed reconciliation                   |\n| `repeat(count, mapFn)`   | Reactive repeat based on a reactive count                          |\n| `onSettled(fn)`          | Run a callback after the current flush cycle completes             |\n| `snapshot(store)`        | Returns a non-reactive copy of a store, preserving unmodified references |\n| `reconcile(value, key)`  | Returns a diffing function for updating stores from new data       |\n| `merge(...sources)`      | Reactively merges multiple objects/stores, last source wins        |\n| `omit(props, ...keys)`   | Creates a reactive view of an object with specified keys removed   |\n| `deep(store)`            | Tracks all nested changes on a store                               |\n| `storePath(...path)`     | Path-based setter for stores as an alternative to mutating callbacks |\n\n## Development\n\nFrom the monorepo root:\n\n```bash\npnpm install\npnpm --filter @solidjs/signals build\npnpm --filter @solidjs/signals test\npnpm --filter @solidjs/signals test:watch\npnpm --filter @solidjs/signals test:gc\npnpm --filter @solidjs/signals bench\n```\n\n## License\n\nMIT\n","publish_time":1771006675588,"_cnpm_publish_time":1771006675588,"dist-tags":{"latest":"2.0.3","next":"2.0.0-rc.23"}}