{"name":"alien-signals","version":"0.1.4","license":"MIT","_id":"alien-signals@0.1.4","homepage":"https://github.com/johnsoncodehk/signals#readme","bugs":{"url":"https://github.com/johnsoncodehk/signals/issues"},"dist":{"shasum":"356b70914c943955322e4e65da485ab777049a0d","tarball":"http://registry-npm.ywwl.com/alien-signals/download/alien-signals-0.1.4.tgz","fileCount":26,"integrity":"sha512-Cab3NPmztPN9OWTwtxg4anybT+IXcOPpogFZCP5s1O1B8yJdkpR3waFoVrD1WSTqc6SpCuycGDztZ5YGGCfCdw==","signatures":[{"sig":"MEQCIDV7xioHgRa7Nc65qRjVRHiQTK6leglbAdkYgM/+vwMdAiB8gsCXdB+ZrJ6MLmf16J7lJawwU0k+3QZYgP+REafGVQ==","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":69438,"size":12481,"noattachment":false,"key":"/alien-signals/-/alien-signals-0.1.4.tgz"},"type":"commonjs","exports":{".":{"types":"./cjs/index.d.ts","import":"./esm/index.mjs","require":"./cjs/index.js"}},"gitHead":"eb0eb278561703fce5c5af75af1e657ee4efd318","scripts":{"test":"vitest run","build":"tsc && esbuild src/index.ts --bundle --format=esm --outfile=esm/index.mjs","prepublishOnly":"npm run build"},"_npmUser":{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"},"repository":{"url":"git+https://github.com/johnsoncodehk/signals.git","type":"git"},"_npmVersion":"10.8.2","description":"Project Status: **Preview**","directories":{},"_nodeVersion":"20.18.0","_hasShrinkwrap":false,"packageManager":"pnpm@9.12.0","devDependencies":{"vite":"latest","vitest":"latest","esbuild":"latest","typescript":"latest"},"_npmOperationalInternal":{"tmp":"tmp/alien-signals_0.1.4_1729288472356_0.5393342505557066","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":1729288472571,"maintainers":[{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"}],"_cnpm_publish_time":1729288472571,"dist-tags":{"latest":"3.2.1"}}