{"_id":"@dhlx/signal","_rev":"2-46548d6199404716795543534edb3e04","name":"@dhlx/signal","dist-tags":{"latest":"0.1.0"},"versions":{"0.0.1":{"name":"@dhlx/signal","version":"0.0.1","_id":"@dhlx/signal@0.0.1","maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"homepage":"https://github.com/LiDengHui/signal#readme","bugs":{"url":"https://github.com/LiDengHui/signal/issues"},"dist":{"shasum":"2523888a4af158247e11c6a37d59e50dfa52bb77","tarball":"https://registry.npmjs.org/@dhlx/signal/-/signal-0.0.1.tgz","fileCount":7,"integrity":"sha512-DlTVWDZtMhAqhWWYaq2RxwWYP5O9jiXctsjKLVOyEIbdomeW3jZE4kF8Le3466ny3r95Zi+LYUA/oXa64nXO7w==","signatures":[{"sig":"MEUCIQDPhhqoGqRufEAl9sRUScQqBJVu4bGiQ21e5l1955K84gIgRxvJr4GNxBtTCaZ73yoJnrC6yYJcaIDxrsCzid284Kg=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":9747},"main":"./dist/index.umd.cjs","type":"module","types":"./dist/lib/main.d.ts","module":"./dist/index.js","exports":{"types":"./dist/lib/main.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"gitHead":"befd1b5c8c578a1ccc06329e527c1c1081a59749","private":false,"scripts":{"dev":"vite","test":"ava","build":"tsc && vite build"},"_npmUser":{"name":"lidenghui~","email":"3379489032@qq.com"},"repository":{"url":"git+https://github.com/LiDengHui/signal.git","type":"git"},"_npmVersion":"10.8.2","description":"A lightweight reactive data library providing Signal and Computed objects for state management and automatic updates, tracking dependencies and simplifying data handling.","directories":{},"_nodeVersion":"22.8.0","dependencies":{"vite-plugin-dts":"^4.2.2"},"_hasShrinkwrap":false,"devDependencies":{"ava":"^6.1.3","vite":"^5.2.10","prettier":"^3.3.3","typescript":"^5.4.5","@dhlx/delay":"^0.0.5","@types/node":"^22.8.1"},"peerDependencies":{"@dhlx/event-target":"^0.0.1"},"_npmOperationalInternal":{"tmp":"tmp/signal_0.0.1_1730080565053_0.5485219015800669","host":"s3://npm-registry-packages"}},"0.1.0":{"name":"@dhlx/signal","private":false,"version":"0.1.0","type":"module","main":"./dist/index.umd.cjs","module":"./dist/index.js","types":"./dist/lib/main.d.ts","exports":{"types":"./dist/lib/main.d.ts","import":"./dist/index.js","require":"./dist/index.umd.cjs"},"scripts":{"dev":"vite","build":"tsc && vite build","test":"ava"},"devDependencies":{"@dhlx/delay":"^0.0.5","@types/node":"^24.1.0","ava":"^6.4.1","prettier":"^3.6.2","typescript":"^5.8.3","vite":"npm:rolldown-vite@latest"},"dependencies":{"esbuild":"^0.25.8","vite-plugin-dts":"^4.5.4"},"repository":{"type":"git","url":"git+https://github.com/LiDengHui/signal.git"},"peerDependencies":{"@dhlx/event-target":"^0.0.1"},"description":"A lightweight reactive data library providing Signal and Computed objects for state management and automatic updates, tracking dependencies and simplifying data handling.","_id":"@dhlx/signal@0.1.0","gitHead":"befd1b5c8c578a1ccc06329e527c1c1081a59749","bugs":{"url":"https://github.com/LiDengHui/signal/issues"},"homepage":"https://github.com/LiDengHui/signal#readme","_nodeVersion":"22.17.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-4zOZxU9j705W58vs5tX5KUrtN3H/l5RCvlQ5694xOqbX0hrJ1pw6h38wwOLcUsawRhxgIn1wXxsmUu6Er5mZkg==","shasum":"045398f1997409197a5e6a88fc6cb9fec545c239","tarball":"https://registry.npmjs.org/@dhlx/signal/-/signal-0.1.0.tgz","fileCount":6,"unpackedSize":9990,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIHmO2JkQuxkwTT4XvzNrgyK0do5YzAAlOB6gz4VpC17uAiAlBFH0ljJLC2xpmf+Fm/g748Xy+/KIJNsCM/v2X9lnsQ=="}]},"_npmUser":{"name":"lidenghui~","email":"3379489032@qq.com"},"directories":{},"maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/signal_0.1.0_1753434529364_0.24041541297983104"},"_hasShrinkwrap":false}},"time":{"created":"2024-10-28T01:56:04.919Z","modified":"2025-07-25T09:08:49.713Z","0.0.1":"2024-10-28T01:56:05.250Z","0.1.0":"2025-07-25T09:08:49.526Z"},"bugs":{"url":"https://github.com/LiDengHui/signal/issues"},"homepage":"https://github.com/LiDengHui/signal#readme","repository":{"type":"git","url":"git+https://github.com/LiDengHui/signal.git"},"description":"A lightweight reactive data library providing Signal and Computed objects for state management and automatic updates, tracking dependencies and simplifying data handling.","maintainers":[{"name":"lidenghui~","email":"3379489032@qq.com"}],"readme":"\n# Signal\n\nA simple reactive data library using `Signal` and `Computed` to manage state and trigger updates when values change.\n\n## Features\n\n* **Signal**: A reactive data object that allows tracking and responding to value changes.\n* **Computed**: A reactive computed value that automatically updates when its dependencies change.\n* Efficient and lightweight.\n* Supports effects to run functions when values change.\n\n## Installation\n\nYou can install this package via NPM:\n\n```bash\nnpm install @dhlx/signal\n```\n\nOr via Yarn:\n\n```bash\nyarn add @dhlx/signal\n```\n\n## Usage\n\n### Creating a Signal\n\nA `Signal` is a reactive data object that holds a value and notifies listeners when the value changes.\n\n```javascript\nimport { signal } from '@dhlx/signal'\n\n// Create a signal with an initial value\nconst temperature = signal(20)\n\n// Access the value\nconsole.log(temperature.value) // 20\n\n// Update the value\ntemperature.value = 25\n\n// Promise resolves and triggers update\nPromise.resolve().then(() => {\n  console.log(temperature.value) // 25\n})\n\n```\n\n### Using Effects\n\nYou can register effects to react to changes in a `Signal` value. The effect will be called immediately and whenever the value of the signal changes.\n\n```javascript\nimport { signal } from '@dhlx/signal';\n\nconst temperature = signal(20);\n\n// Register an effect that will be triggered on value change\ntemperature.effect(() => {\n  console.log(`Temperature changed to: ${temperature.value}`);\n});\n\n// Update the signal and trigger the effect\ntemperature.value = 30; // Output: Temperature changed to: 30\n```\n\n### Creating a Computed Value\n\nA `Computed` value depends on one or more `Signal` values and automatically updates when any of its dependencies change.\n\n```javascript\nimport { signal, computed } from '@dhlx/signal';\n\n// Create two signals\nconst temperature = signal(20);\nconst humidity = signal(50);\n\n// Create a computed value based on the signals\nconst comfortIndex = computed((temp, humid) => temp + humid, [temperature, humidity]);\n\nconsole.log(comfortIndex.value); // 70\n\n// Update the signals and the computed value will automatically update\ntemperature.value = 25;\n\nPromise.resolve().then(() => {\n  console.log(comfortIndex.value); // 75\n})\n```\n\n### Removing Effects\n\nYou can remove effects by using the function returned by the `effect` method. This allows you to stop listening for changes.\n\n```javascript\nimport { signal } from '@dhlx/signal';\n\nconst temperature = signal(20);\n\n// Register an effect\nconst stopLogging = temperature.effect(() => {\n  console.log(`Temperature is now: ${temperature.value}`);\n});\n\n// Stop listening for changes\nstopLogging();\n\ntemperature.value = 35; // No output, effect has been removed\n```\n\n## API\n\n### `signal(initialValue)`\n\nCreates a new `Signal` object.\n\n* `initialValue`: The initial value of the signal.\n\n#### Properties:\n\n* `value`: Get or set the value of the signal.\n\n#### Methods:\n\n* `effect(fn)`: Registers a function that runs when the signal value changes. Returns a function to remove the effect.\n\n### `computed(fn, deps)`\n\nCreates a new `Computed` object that automatically updates based on its dependencies.\n\n* `fn`: A function that returns the computed value based on its dependencies.\n* `deps`: An array of `Signal` objects that the computed value depends on.\n\n#### Properties:\n\n* `value`: The current computed value, updated automatically when dependencies change.\n\n## License\n\nMIT License\n\n\n","readmeFilename":"README.md"}