{"name":"alien-signals","version":"0.0.6","license":"MIT","_id":"alien-signals@0.0.6","homepage":"https://github.com/johnsoncodehk/signals#readme","bugs":{"url":"https://github.com/johnsoncodehk/signals/issues"},"dist":{"shasum":"fa2dd51da5b0d7e0f7c9e767b6afcce94a20b7cf","tarball":"http://registry-npm.ywwl.com/alien-signals/download/alien-signals-0.0.6.tgz","fileCount":23,"integrity":"sha512-xAe7bc56tmNRsgKjx2fojOOH+TB7y83cRaKsazo9cGyaojHaRsR62chnLPBoT3kpJvvKKHd9pmA2f/C1CNgZFA==","signatures":[{"sig":"MEYCIQDr9aExjOsfVVUUx40D1oBHSEbcc54gkUgaJ8spm0dHzQIhANNtKNPp/1KFryrO/ZOU0+cm1x6f07eCudUx6I49ghOD","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":35641,"size":7594,"noattachment":false,"key":"/alien-signals/-/alien-signals-0.0.6.tgz"},"main":"index.js","type":"module","types":"./index.d.ts","gitHead":"330a6084296e41a1b727f5dd49379eece5541e7d","scripts":{"test":"vitest run","build":"tsc"},"_npmUser":{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"},"repository":{"url":"git+https://github.com/johnsoncodehk/signals.git","type":"git"},"_npmVersion":"10.7.0","description":"Project Status: **Preview**","directories":{},"_nodeVersion":"20.14.0","_hasShrinkwrap":false,"packageManager":"pnpm@9.12.0","devDependencies":{"vite":"latest","vitest":"latest","typescript":"latest"},"_npmOperationalInternal":{"tmp":"tmp/alien-signals_0.0.6_1728786895381_0.23726147322538926","host":"s3://npm-registry-packages"},"readme":"<p align=\"center\">\n\t<img src=\"assets/logo.png\" width=\"250\"><br>\n<p>\n\n<p align=\"center\">\n\t<a href=\"https://npmjs.com/package/alien-signals\"><img src=\"https://badgen.net/npm/v/alien-signals\" alt=\"npm package\"></a>\n</p>\n\n# alien-signals\n\nProject Status: **Preview**\n\nThe goal of `alien-signals` is to create a push-pull model based signal library with the lowest overhead.\n\nWe have set the following scheduling logic constraints:\n\n1. No dynamic object fields\n2. No use of Array/Set/Map\n3. No recursion calls\n4. Class properties must be fewer than 10 (https://v8.dev/blog/fast-properties)\n\nExperimental results have shown that with these constraints, it is possible to achieve excellent performance for a Signal library without using sophisticated scheduling strategies. The overall performance of `alien-signals` is approximately 400% that of Vue 3.4's reactivity system.\n\nFor more detailed performance comparisons, please visit: https://github.com/transitive-bullshit/js-reactivity-benchmark\n\n## Motivation\n\nTo achieve high-performance code generation in https://github.com/vuejs/language-tools, I needed to write some on-demand computed logic using Signals, but I couldn't find a low-cost Signal library that satisfied me.\n\nIn the past, I accumulated some knowledge of reactivity systems in https://github.com/vuejs/core/pull/5912, so I attempted to develop `alien-signals` with the goal of creating a Signal library with minimal memory usage and excellent performance.\n\nSince Vue 3.5 switched to a Pull reactivity system in https://github.com/vuejs/core/pull/10397, I continued to research the Push-Pull reactivity system here. It is worth mentioning that I was inspired by the doubly-linked concept, but `alien-signals` does not use a similar implementation.\n\n## Adoptions\n\n- Used in Vue language tools (https://github.com/vuejs/language-tools) for virtual code generation.\n\n- The core reactivity system code was ported to Vue 3.6 and later. (https://github.com/vuejs/core/pull/12349)\n\n## Usage\n\n### Basic\n\n```ts\nimport { signal, computed, effect } from 'alien-signals';\n\nconst count = signal(1);\nconst doubleCount = computed(() => count.get() * 2);\n\neffect(() => {\n  console.log(`Count is: ${count.get()}`);\n}); // Console: Count is: 1\n\nconsole.log(doubleCount.get()); // 2\n\ncount.set(2); // Console: Count is: 2\n\nconsole.log(doubleCount.get()); // 4\n```\n\n### Effect Scope\n\n```ts\nimport { signal, effectScope } from 'alien-signals';\n\nconst count = signal(1);\nconst scope = effectScope();\n\nscope.run(() => {\n  effect(() => {\n    console.log(`Count in scope: ${count.get()}`);\n  }); // Console: Count in scope: 1\n\n  count.set(2); // Console: Count in scope: 2\n});\n\nscope.stop();\n\ncount.set(3); // No console output\n```\n\n## Roadmap\n\n| Version | Savings                                                                                       |\n|---------|-----------------------------------------------------------------------------------------------|\n| 0.3     | Satisfy all 4 constraints                                                                     |\n| 0.2     | Correctly schedule computed side effects                                                      |\n| 0.1     | Correctly schedule inner effect callbacks                                                     |\n| 0.0     | Add APIs: `signal()`, `computed()`, `effect()`, `effectScope()`, `startBatch()`, `endBatch()` |\n","publish_time":1728786895599,"maintainers":[{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"}],"_cnpm_publish_time":1728786895599,"dist-tags":{"latest":"3.2.1"}}