{"_id":"signal-polyfill","_rev":"4207307","name":"signal-polyfill","description":"A polyfill for the TC39 Signal proposal.","dist-tags":{"latest":"0.2.2"},"maintainers":[{"name":"eisenbergeffect","email":""},{"name":"nullvoxpopuli","email":""}],"time":{"modified":"2026-03-04T17:03:59.000Z","created":"2024-03-31T19:18:08.630Z","0.2.2":"2025-01-17T16:14:20.769Z","0.2.1":"2024-10-11T15:44:16.063Z","0.2.0":"2024-10-01T15:54:15.912Z","0.1.2":"2024-07-23T15:17:29.569Z","0.1.1":"2024-05-14T17:51:28.779Z","0.1.0":"2024-03-31T19:18:08.630Z"},"users":{},"author":{"name":"EisenbergEffect"},"repository":{"type":"git","url":"git+https://github.com/proposal-signals/signal-polyfill.git"},"versions":{"0.2.2":{"name":"signal-polyfill","version":"0.2.2","description":"A polyfill for the TC39 Signal proposal.","repository":{"type":"git","url":"git+https://github.com/proposal-signals/signal-polyfill.git"},"license":"Apache-2.0","author":{"name":"EisenbergEffect"},"contributors":[{"name":"Google LLC"},{"name":"Bloomberg Finance L.P."},{"name":"EisenbergEffect"}],"type":"module","main":"dist/index.js","types":"dist/index.d.ts","devDependencies":{"@types/node":"^20.11.25","@vitest/browser":"^1.5.3","concurrently":"^9.0.1","expect-type":"^1.0.0","prettier":"^3.2.5","release-plan":"^0.9.0","typescript":"latest","vite":"^5.2.6","vite-plugin-dts":"^3.7.3","vitest":"^1.4.0","webdriverio":"^8.36.1"},"volta":{"node":"22.0.0","pnpm":"9.0.6"},"scripts":{"build":"vite build","dev":"vite","watch:types":"tsc --noEmit --watch","lint":"concurrently 'npm:lint:*(!fix)' --names 'lint:' --prefixColors=auto","lint:types":"tsc --noEmit","lint:prettier":"prettier --check .","lint:fix":"prettier --write .","test":"vitest"},"bugs":{"url":"https://github.com/proposal-signals/signal-polyfill/issues"},"homepage":"https://github.com/proposal-signals/signal-polyfill#readme","_id":"signal-polyfill@0.2.2","_integrity":"sha512-p63Y4Er5/eMQ9RHg0M0Y64NlsQKpiu6MDdhBXpyywRuWiPywhJTpKJ1iB5K2hJEbFZ0BnDS7ZkJ+0AfTuL37Rg==","_resolved":"/tmp/f7ec1368b38869a27092f6c3a5513611/signal-polyfill-0.2.2.tgz","_from":"file:signal-polyfill-0.2.2.tgz","_nodeVersion":"22.0.0","_npmVersion":"10.5.1","dist":{"shasum":"722e2cd272cbd6cdc5fcc741459bd066f93d0264","size":34489,"noattachment":false,"key":"/signal-polyfill/-/signal-polyfill-0.2.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/signal-polyfill/download/signal-polyfill-0.2.2.tgz"},"_npmUser":{"name":"nullvoxpopuli","email":"theprecognition+npm@gmail.com"},"directories":{},"maintainers":[{"name":"eisenbergeffect","email":""},{"name":"nullvoxpopuli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/signal-polyfill_0.2.2_1737130460551_0.815408062866763"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2025-01-17T16:14:20.769Z","publish_time":1737130460769,"_source_registry_name":"default","_cnpm_publish_time":1737130460769},"0.2.1":{"name":"signal-polyfill","version":"0.2.1","description":"A polyfill for the TC39 Signal proposal.","repository":{"type":"git","url":"git+https://github.com/proposal-signals/signal-polyfill.git"},"license":"Apache-2.0","author":{"name":"EisenbergEffect"},"contributors":[{"name":"Google LLC"},{"name":"Bloomberg Finance L.P."},{"name":"EisenbergEffect"}],"type":"module","main":"dist/index.js","types":"dist/index.d.ts","devDependencies":{"@types/node":"^20.11.25","@vitest/browser":"^1.5.3","prettier":"^3.2.5","release-plan":"^0.9.0","typescript":"latest","vite":"^5.2.6","vite-plugin-dts":"^3.7.3","vitest":"^1.4.0","webdriverio":"^8.36.1"},"volta":{"node":"22.0.0","pnpm":"9.0.6"},"scripts":{"build":"tsc && vite build","dev":"vite","lint":"prettier --check .","lint:fix":"prettier --write .","test":"vitest"},"bugs":{"url":"https://github.com/proposal-signals/signal-polyfill/issues"},"homepage":"https://github.com/proposal-signals/signal-polyfill#readme","_id":"signal-polyfill@0.2.1","_integrity":"sha512-HtchWosT4UT1i6yIMmxjg7gqkDT9lXvQtJRGVppi2TDwVjgs8cS+7ATVFqBvgJGThludjxrxJFOvmzzGSAc8OA==","_resolved":"/tmp/3dfb8793a3ebaf232794cdf6f1d30ccd/signal-polyfill-0.2.1.tgz","_from":"file:signal-polyfill-0.2.1.tgz","_nodeVersion":"22.0.0","_npmVersion":"10.5.1","dist":{"shasum":"6c3762237e18102b9e45770233a8b131306a982d","size":32977,"noattachment":false,"key":"/signal-polyfill/-/signal-polyfill-0.2.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/signal-polyfill/download/signal-polyfill-0.2.1.tgz"},"_npmUser":{"name":"nullvoxpopuli","email":"theprecognition+npm@gmail.com"},"directories":{},"maintainers":[{"name":"eisenbergeffect","email":""},{"name":"nullvoxpopuli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/signal-polyfill_0.2.1_1728661455855_0.2490897590312191"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-10-11T15:44:16.063Z","publish_time":1728661456063,"_source_registry_name":"default","_cnpm_publish_time":1728661456063},"0.2.0":{"name":"signal-polyfill","version":"0.2.0","description":"A polyfill for the TC39 Signal proposal.","repository":{"type":"git","url":"git+https://github.com/proposal-signals/signal-polyfill.git"},"license":"Apache-2.0","author":{"name":"EisenbergEffect"},"contributors":[{"name":"Google LLC"},{"name":"Bloomberg Finance L.P."},{"name":"EisenbergEffect"}],"type":"module","main":"dist/index.js","types":"dist/index.d.ts","devDependencies":{"@types/node":"^20.11.25","@vitest/browser":"^1.5.3","prettier":"^3.2.5","release-plan":"^0.9.0","typescript":"latest","vite":"^5.2.6","vite-plugin-dts":"^3.7.3","vitest":"^1.4.0","webdriverio":"^8.36.1"},"volta":{"node":"22.0.0","pnpm":"9.0.6"},"scripts":{"build":"tsc && vite build","dev":"vite","lint":"prettier --check .","lint:fix":"prettier --write .","test":"vitest"},"bugs":{"url":"https://github.com/proposal-signals/signal-polyfill/issues"},"homepage":"https://github.com/proposal-signals/signal-polyfill#readme","_id":"signal-polyfill@0.2.0","_integrity":"sha512-EbZ5L6pm0LPVZECfzfDLQ+2tWd2xQ+iG+HfuvqWjF+pl0yvdT1rsL/YgfeBakubLbnwAd1zRvap1rYqPBG8prA==","_resolved":"/tmp/a6f06d82a91e6ca6bcc02b9ed4515e50/signal-polyfill-0.2.0.tgz","_from":"file:signal-polyfill-0.2.0.tgz","_nodeVersion":"22.0.0","_npmVersion":"10.5.1","dist":{"shasum":"634fa29f3751be28fdefeaa908bf5b6656b47863","size":32882,"noattachment":false,"key":"/signal-polyfill/-/signal-polyfill-0.2.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/signal-polyfill/download/signal-polyfill-0.2.0.tgz"},"_npmUser":{"name":"nullvoxpopuli","email":"theprecognition+npm@gmail.com"},"directories":{},"maintainers":[{"name":"eisenbergeffect","email":""},{"name":"nullvoxpopuli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/signal-polyfill_0.2.0_1727798055746_0.1793604803990101"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-10-01T15:54:15.912Z","publish_time":1727798055912,"_source_registry_name":"default","_cnpm_publish_time":1727798055912},"0.1.2":{"name":"signal-polyfill","version":"0.1.2","description":"A polyfill for the TC39 Signal proposal.","repository":{"type":"git","url":"git+https://github.com/proposal-signals/signal-polyfill.git"},"license":"Apache-2.0","author":{"name":"EisenbergEffect"},"contributors":[{"name":"Google LLC"},{"name":"Bloomberg Finance L.P."},{"name":"EisenbergEffect"}],"type":"module","main":"dist/index.js","types":"dist/index.d.ts","devDependencies":{"@types/node":"^20.11.25","@vitest/browser":"^1.5.3","prettier":"^3.2.5","release-plan":"^0.9.0","typescript":"latest","vite":"^5.2.6","vite-plugin-dts":"^3.7.3","vitest":"^1.4.0","webdriverio":"^8.36.1"},"volta":{"node":"22.0.0","pnpm":"9.0.6"},"scripts":{"build":"tsc && vite build","dev":"vite","lint":"prettier --check .","lint:fix":"prettier --write .","test":"vitest"},"bugs":{"url":"https://github.com/proposal-signals/signal-polyfill/issues"},"homepage":"https://github.com/proposal-signals/signal-polyfill#readme","_id":"signal-polyfill@0.1.2","_integrity":"sha512-HT9d+L9NMiTzMxb/tU2Baym6129ROyRETSjvchvSkQa7wN0+SrG/IUlsaBLqKn2c+4mlze6CgQBEvgBjxOpiaQ==","_resolved":"/tmp/0631fc082777599e6aac98b4bd9ebea4/signal-polyfill-0.1.2.tgz","_from":"file:signal-polyfill-0.1.2.tgz","_nodeVersion":"22.0.0","_npmVersion":"10.5.1","dist":{"shasum":"a4725b8f761278f9c666f2ce13cc9cde3ccb046d","size":32665,"noattachment":false,"key":"/signal-polyfill/-/signal-polyfill-0.1.2.tgz","tarball":"http://registry.cnpm.dingdandao.com/signal-polyfill/download/signal-polyfill-0.1.2.tgz"},"_npmUser":{"name":"nullvoxpopuli","email":"theprecognition+npm@gmail.com"},"directories":{},"maintainers":[{"name":"eisenbergeffect","email":""},{"name":"nullvoxpopuli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/signal-polyfill_0.1.2_1721747849429_0.13255593625799222"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-07-23T15:17:29.569Z","publish_time":1721747849569,"_source_registry_name":"default","_cnpm_publish_time":1721747849569},"0.1.1":{"name":"signal-polyfill","version":"0.1.1","description":"A polyfill for the TC39 Signal proposal.","repository":{"type":"git","url":"git+https://github.com/proposal-signals/signal-polyfill.git"},"license":"Apache-2.0","author":{"name":"EisenbergEffect"},"contributors":[{"name":"Google LLC"},{"name":"Bloomberg Finance L.P."},{"name":"EisenbergEffect"}],"type":"module","main":"dist/index.js","types":"dist/index.d.ts","devDependencies":{"@types/node":"^20.11.25","@vitest/browser":"^1.5.3","prettier":"^3.2.5","release-plan":"^0.9.0","typescript":"latest","vite":"^5.2.6","vite-plugin-dts":"^3.7.3","vitest":"^1.4.0","webdriverio":"^8.36.1"},"volta":{"node":"22.0.0","pnpm":"9.0.6"},"scripts":{"build":"tsc && vite build","dev":"vite","test":"vitest"},"bugs":{"url":"https://github.com/proposal-signals/signal-polyfill/issues"},"homepage":"https://github.com/proposal-signals/signal-polyfill#readme","_id":"signal-polyfill@0.1.1","_integrity":"sha512-ZihPkMjiWOCZaYOb/vi1YLj+f0GTKVF7tQVNovtK32yjqcvRvjGPTwwX3Ad45mQ8v08kLUBagsOkuyJ6gpwhWA==","_resolved":"/tmp/6009afbec9ae759193262229a6dec765/signal-polyfill-0.1.1.tgz","_from":"file:signal-polyfill-0.1.1.tgz","_nodeVersion":"22.0.0","_npmVersion":"10.5.1","dist":{"shasum":"23bf4908f91b0748f8f230561f361b087580fe23","size":30819,"noattachment":false,"key":"/signal-polyfill/-/signal-polyfill-0.1.1.tgz","tarball":"http://registry.cnpm.dingdandao.com/signal-polyfill/download/signal-polyfill-0.1.1.tgz"},"_npmUser":{"name":"nullvoxpopuli","email":"theprecognition+npm@gmail.com"},"directories":{},"maintainers":[{"name":"eisenbergeffect","email":""},{"name":"nullvoxpopuli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/signal-polyfill_0.1.1_1715709088593_0.6780294594763643"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-05-14T17:51:28.779Z","publish_time":1715709088779,"_source_registry_name":"default","_cnpm_publish_time":1715709088779},"0.1.0":{"name":"signal-polyfill","version":"0.1.0","description":"A polyfill for the TC39 Signal proposal.","contributors":[{"name":"Google LLC"},{"name":"Bloomberg Finance L.P."},{"name":"EisenbergEffect"}],"main":"dist/index.js","type":"module","types":"dist/index.d.ts","scripts":{"dev":"vite","build":"tsc && vite build","test":"vitest"},"author":{"name":"EisenbergEffect"},"license":"Apache-2.0","devDependencies":{"@types/node":"^20.11.25","typescript":"latest","vite":"^5.2.6","vite-plugin-dts":"^3.7.3","vitest":"^1.4.0"},"_id":"signal-polyfill@0.1.0","gitHead":"d811fce3c0d67529fe998f7eeaefd357f8369d01","_nodeVersion":"21.7.1","_npmVersion":"10.5.0","dist":{"shasum":"508b79978bfb2f555e4c55398f1ae5a1d5050a14","size":35116,"noattachment":false,"key":"/signal-polyfill/-/signal-polyfill-0.1.0.tgz","tarball":"http://registry.cnpm.dingdandao.com/signal-polyfill/download/signal-polyfill-0.1.0.tgz"},"_npmUser":{"name":"--explosion--","email":"explosionscratch@gmail.com"},"directories":{},"maintainers":[{"name":"eisenbergeffect","email":""},{"name":"nullvoxpopuli","email":""}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/signal-polyfill_0.1.0_1711912688423_0.596725322081838"},"_hasShrinkwrap":false,"_cnpmcore_publish_time":"2024-03-31T19:18:08.630Z","publish_time":1711912688630,"_source_registry_name":"default","_cnpm_publish_time":1711912688630}},"readme":"# Signal Polyfill\n\n## ⚠️ This polyfill is a preview of an in-progress proposal and could change at any time. Do not use this in production. ⚠️\n\nA \"signal\" is [a proposed first-class JavaScript data type](https://github.com/tc39/proposal-signals) that enables one-way data flow through cells of state or computations derived from other state/computations.\n\nThis is a polyfill for the `Signal` API.\n\n## Examples\n\n### Using signals\n\n- Use `Signal.State(value)` to create a single \"cell\" of data that can flow through the unidirectional state graph.\n- Use `Signal.Computed(callback)` to define a computation based on state or other computations flowing through the graph.\n\n```js\nimport { Signal } from \"signal-polyfill\";\nimport { effect } from \"./effect.js\";\n\nconst counter = new Signal.State(0);\nconst isEven = new Signal.Computed(() => (counter.get() & 1) == 0);\nconst parity = new Signal.Computed(() => (isEven.get() ? \"even\" : \"odd\"));\n\neffect(() => console.log(parity.get())); // Console logs \"even\" immediately.\nsetInterval(() => counter.set(counter.get() + 1), 1000); // Changes the counter every 1000ms.\n\n// effect triggers console log \"odd\"\n// effect triggers console log \"even\"\n// effect triggers console log \"odd\"\n// ...\n```\n\nThe signal proposal does not include an `effect` API, since such APIs are often deeply integrated with rendering and batch strategies that are highly framework/library dependent. However, the proposal does seek to define a set of primitives that library authors can use to implement their own effects.\n\nWhen working directly with library effect APIs, always be sure to understand the behavior of the `effect` implementation. While the signal algorithm is standardized, effects are not and may vary. To illustrate this, have a look at this code:\n\n```js\ncounter.get(); // 0\neffect(() => counter.set(counter.get() + 1)); // Infinite loop???\ncounter.get(); // 1\n```\n\nDepending on how the effect is implemented, the above code could result in an infinite loop. It's also important to note that running the effect, in this case, causes an immediate invocation of the callback, changing the value of the counter.\n\n### Creating a simple effect\n\n- You can use `Signal.subtle.Watch(callback)` combined with `Signal.Computed(callback)` to create a simple _effect_ implementation.\n- The `Signal.subtle.Watch` `callback` is invoked synchronously when a watched signal becomes dirty.\n- To batch effect updates, library authors are expected to implement their own schedulers.\n- Use `Signal.subtle.Watch#getPending()` to retrieve an array of dirty signals.\n- Calling `Signal.subtle.Watch#watch()` with no arguments will re-watch the list of tracked signals again.\n\n```js\nimport { Signal } from \"signal-polyfill\";\n\nlet needsEnqueue = true;\n\nconst w = new Signal.subtle.Watcher(() => {\n  if (needsEnqueue) {\n    needsEnqueue = false;\n    queueMicrotask(processPending);\n  }\n});\n\nfunction processPending() {\n  needsEnqueue = true;\n\n  for (const s of w.getPending()) {\n    s.get();\n  }\n\n  w.watch();\n}\n\nexport function effect(callback) {\n  let cleanup;\n\n  const computed = new Signal.Computed(() => {\n    typeof cleanup === \"function\" && cleanup();\n    cleanup = callback();\n  });\n\n  w.watch(computed);\n  computed.get();\n\n  return () => {\n    w.unwatch(computed);\n    typeof cleanup === \"function\" && cleanup();\n    cleanup = undefined;\n  };\n}\n```\n\n> [!IMPORTANT]\n> The `Signal.subtle` APIs are so named in order to communicate that their correct use requires careful attention to detail. These APIs are not targeted at application-level code, but rather at framework/library authors.\n\n### Combining signals and decorators\n\nA class accessor decorator can be combined with the `Signal.State()` API to enable improved DX.\n\n```js\nimport { Signal } from \"signal-polyfill\";\n\nexport function signal(target) {\n  const { get } = target;\n\n  return {\n    get() {\n      return get.call(this).get();\n    },\n\n    set(value) {\n      get.call(this).set(value);\n    },\n\n    init(value) {\n      return new Signal.State(value);\n    },\n  };\n}\n```\n\nThe above decorator can be used on public or **private** accessors, enabling reactivity while carefully controlling state mutations.\n\n```js\nexport class Counter {\n  @signal accessor #value = 0;\n\n  get value() {\n    return this.#value;\n  }\n\n  increment() {\n    this.#value++;\n  }\n\n  decrement() {\n    if (this.#value > 0) {\n      this.#value--;\n    }\n  }\n}\n```\n\n## Contributing\n\n- clone the repo, `git clone git@github.com:proposal-signals/signal-polyfill.git`\n- `cd signal-polyfill`\n- use your favorite package manager to install dependencies, e.g.: `pnpm install`, `npm install`, `yarn install`, etc\n- make your change\n- add and run tests\n- open a PR\n- collaborate ????\n","_attachments":{},"homepage":"https://github.com/proposal-signals/signal-polyfill#readme","bugs":{"url":"https://github.com/proposal-signals/signal-polyfill/issues"},"license":"Apache-2.0"}