{"_id":"@axel669/signal","_rev":"3-b20dfd8b03111e067d9c3a22f9af8c4b","name":"@axel669/signal","dist-tags":{"latest":"0.2.0","beta":"0.2.0-beta.0"},"versions":{"0.1.0":{"name":"@axel669/signal","version":"0.1.0","keywords":[],"author":{"name":"Axel"},"license":"MIT","_id":"@axel669/signal@0.1.0","maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"dist":{"shasum":"736eafc5c41c832c07fecf08a9ff070c0a185553","tarball":"https://registry.npmjs.org/@axel669/signal/-/signal-0.1.0.tgz","fileCount":4,"integrity":"sha512-gpDbVlcgOCeTqChdjOB5sNf1iYZ2C4SbWOCsk5c8RuqpcB7aGF+89RhjOz7Rg0FWss2RVeh7EsrLKk8DnWZDoQ==","signatures":[{"sig":"MEUCIF1OSaiy9k/sl2w+EjX1VsCj4ueolb7KN4Wh5th0h+PiAiEAoQdMNl7F1Rz4wZJkj3dpgTiTMdKUpfyGRQNWeRn0pLE=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":10559},"main":"lib/main.js","type":"module","exports":{".":"./lib/main.js"},"gitHead":"38f78f6e8684a55036f30a9bc0705bb5b4f4a6d5","scripts":{"test":"node tests/basic.js"},"_npmUser":{"name":"axel669","email":"axel@axel669.net"},"_npmVersion":"10.2.3","description":"A simple, small (< 1kb minified + gzip) library for creating and using signals.","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"_npmOperationalInternal":{"tmp":"tmp/signal_0.1.0_1730170031919_0.8094482381898309","host":"s3://npm-registry-packages"}},"0.2.0-beta.0":{"name":"@axel669/signal","version":"0.2.0-beta.0","keywords":[],"author":{"name":"Axel"},"license":"MIT","_id":"@axel669/signal@0.2.0-beta.0","maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"dist":{"shasum":"31878d692ffcde382aa9f70666bf165fcab1290c","tarball":"https://registry.npmjs.org/@axel669/signal/-/signal-0.2.0-beta.0.tgz","fileCount":4,"integrity":"sha512-JbycdL/9yJlMu5FEwM4I7tTKazLvePcHqjytn0jtLNBuxHWlgd29mwUthP7NXc2TLg4oGxzrTvdkbVKydqfQSw==","signatures":[{"sig":"MEUCIQCnoKH0TX4OG3cQVDpyC3GxGxGDUP3mnF8jO96dwrBVwQIgczXF/QydGQODhJ0V6gz+JEGWHQyhX124ZdCpN7oPFD8=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":14183},"main":"lib/main.js","type":"module","exports":{".":"./lib/main.js"},"gitHead":"6b83904b6ee8c633e4bc46396ea1ddb4bd0d9da4","scripts":{"test":"node tests/basic.js"},"_npmUser":{"name":"axel669","email":"axel@axel669.net"},"_npmVersion":"10.2.3","description":"A simple, small (< 1kb minified + gzip) library for creating and using signals.","directories":{},"_nodeVersion":"20.10.0","_hasShrinkwrap":false,"readmeFilename":"README.md","_npmOperationalInternal":{"tmp":"tmp/signal_0.2.0-beta.0_1737336524485_0.515290595684839","host":"s3://npm-registry-packages-npm-production"}},"0.2.0":{"name":"@axel669/signal","version":"0.2.0","description":"A simple, small (< 1kb minified + gzip) library for creating and using signals.","type":"module","scripts":{"test":"node tests/basic.js"},"keywords":[],"author":{"name":"Axel"},"license":"MIT","exports":{".":"./lib/main.js","./types":"./lib/types.ts"},"_id":"@axel669/signal@0.2.0","gitHead":"f548a73577cd52fe1f8c51696176c8f7e50d14c1","_nodeVersion":"24.6.0","_npmVersion":"11.5.1","dist":{"integrity":"sha512-M1D4bqF9iLccMxLGy9lZwL6LJiSiWvkqVELOib9eaxrTIjG/tDKEnO0JvNNwOqlaWhCUuLeFG79mZHzPzOhJiA==","shasum":"9ecfb52ec020a00339b21dcf541b4bf12e584caf","tarball":"https://registry.npmjs.org/@axel669/signal/-/signal-0.2.0.tgz","fileCount":5,"unpackedSize":14396,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEYCIQD2TSFAhqvu/BmXcEKjVHZ/sKHAWoH+zgqUEMooWh6HoQIhAMngLtEdBaH2WYBH53gofxw0Kv7o+IEzMSRlO0JiCVw0"}]},"_npmUser":{"name":"axel669","email":"axel@axel669.net"},"directories":{},"maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/signal_0.2.0_1756513019611_0.3088608215075188"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-29T02:47:11.731Z","modified":"2025-08-30T00:17:00.006Z","0.1.0":"2024-10-29T02:47:12.115Z","0.2.0-beta.0":"2025-01-20T01:28:44.675Z","0.2.0":"2025-08-30T00:16:59.826Z"},"author":{"name":"Axel"},"license":"MIT","keywords":[],"description":"A simple, small (< 1kb minified + gzip) library for creating and using signals.","maintainers":[{"name":"axel669","email":"axel@axel669.net"}],"readme":"# Signal\r\nA simple, small (< 1kb minified + gzip) library for creating and using signals.\r\n\r\n## Installation\r\n```bash\r\nnpm install @axel669/signal\r\n```\r\n\r\n```js\r\nimport * as signals from \"https://esm.sh/@axel669/signal@0.1.0\"\r\nimport { $signal, $derive, $effect, ... } as signals from \"https://esm.sh/@axel669/signal@0.1.0\"\r\n```\r\n\r\n## Todo\r\n- ~~maybe don't trigger updates if strict equality is true~~\r\n- is async signal processing useful?\r\n\r\n## Usage\r\n\r\n### Value Signal\r\nThe simplest form of signal. It holds a value that can be read or changed and\r\ndoes not depend on other signals directly.\r\n\r\n```js\r\nconst counter = signal(0)\r\n\r\nconsole.log(counter.value) // logs 0\r\ncounter.value += 1\r\nconsole.log(counter.value) // logs 1\r\n```\r\n\r\n### Derived Signal\r\nA signal that takes a function as its argument and calculates a value based on\r\nthe value of other signals. The function reruns every time one of the signals\r\nit relies on changes value. Async functions do not work as the signal\r\nrecalculation is done synchronously for all signals after updates happen.\r\n\r\n```js\r\nconst counter = signal(0)\r\nconst mod3 = derive(() => counter.value % 3)\r\n\r\nconsole.log(counter.value, mod3.value) // logs 0 0\r\ncounter.value = 5\r\nconsole.log(counter.value, mod3.value) // logs 5 2\r\n```\r\n\r\n### Effect Signal\r\nA signal that takes a function and runs some code based on the value of the\r\nsignals it relies on. Does not have a value output of its own, so it can never\r\nbe a dependency of another signal, which means it can also handle async\r\nfunctions, since there is no output to wait for within the signal\r\nrecalculations.\r\n\r\n```js\r\nconst counter = signal(0)\r\nconst logger = effect(() => console.log(counter.value)) // logs 0 at creation\r\n\r\ncounter.value += 1 // makes the effect signal log 1\r\n```\r\n\r\n### Batching\r\nSometimes it is useful to change more then one value signal before letting\r\ntheir subscribers update, this cam be done by wrapping the changes in a function\r\nthat is passed to batch.\r\n\r\n```js\r\nconst a = signal(0)\r\nconst b = signal(1)\r\nconst logger = effect(() => console.log(a.value, b.value)) // logs 0 1\r\n\r\na.value = 2 // makes the effect signal log 2 1\r\nb.value = 5 // makes the effect signal log 2 5\r\n// only triggers one log of 3 6\r\nbatch(\r\n    () => {\r\n        a.value = 3\r\n        b.value = 6\r\n    }\r\n)\r\n```\r\n\r\n### Disposing\r\nAll signals have a `.cleanup` function that will disable the effect from\r\nsending or receiving updates, and will remove it from all dependency trees. Any\r\nsignal that has been disposed can still have its value read (if it had one),\r\nbut the value can no longer be updated, and reading the value will no longer\r\nadd it to dependency trees.\r\n\r\n```js\r\nconst a = signal(0)\r\nconst b = signal(1)\r\nconst sum = derive(() => a.value + b.value)\r\n\r\nconsole.log(a.value, b.value, sum.value) // logs 0 1 1\r\na.value = 2\r\nconsole.log(a.value, b.value, sum.value) // logs 2 1 3\r\na.cleanup()\r\nb.value = 5\r\nconsole.log(a.value, b.value, sum.value) // logs 2 5 7 because b still updates\r\n```\r\n\r\n### Signal IDs\r\nAll signals have a `.id` that can be assigned to, all default to null. This is\r\njust a helpful debug tool, it has no functional purpose for the way signals\r\ncommunicate with each other.\r\n","readmeFilename":"README.md"}