{"name":"alien-signals","version":"0.4.2","license":"MIT","_id":"alien-signals@0.4.2","homepage":"https://github.com/johnsoncodehk/signals#readme","bugs":{"url":"https://github.com/johnsoncodehk/signals/issues"},"dist":{"shasum":"da9db3dbfb1ab1b9fa333a46b7a7440c60a72088","tarball":"http://registry-npm.ywwl.com/alien-signals/download/alien-signals-0.4.2.tgz","fileCount":27,"integrity":"sha512-svevUV6/up20jZJme0sh/7DgXrD6azosZgVmuLqhxYkfhWwcQeup2Qi6BLVJk3lTb8vYoQe+rpncpHFgKiUZJA==","signatures":[{"sig":"MEYCIQDU/LVgy1lNzXPAxduiWWVH/8I6qkgvN0PAX2IexXz8ZAIhAJSTZ3cqnw/ym1cfjkjfidezMoJtWPfIJRYCN5hdBiCs","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":47676,"size":8550,"noattachment":false,"key":"/alien-signals/-/alien-signals-0.4.2.tgz"},"types":"./types/index.d.ts","exports":{".":{"types":"./types/index.d.ts","import":"./esm/index.mjs","require":"./cjs/index.cjs"},"./cjs":{"types":"./types/index.d.ts","import":"./cjs/index.cjs","require":"./cjs/index.cjs"},"./esm":{"types":"./types/index.d.ts","import":"./esm/index.mjs","require":"./esm/index.mjs"}},"gitHead":"99e9029d40850319f556f09c77e6f8c09a6ee384","scripts":{"test":"vitest run","bench":"npm run build:esm && node --jitless --expose-gc benchs/propagate.mjs","build":"tsc && npm run build:esm && npm run build:cjs","build:cjs":"esbuild src/index.ts --bundle --format=cjs --outfile=cjs/index.cjs","build:esm":"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.9.0","description":"<p align=\"center\"> \t<img src=\"assets/logo.png\" width=\"250\"><br> <p>","directories":{},"_nodeVersion":"22.11.0","_hasShrinkwrap":false,"packageManager":"pnpm@9.12.0","devDependencies":{"vite":"latest","mitata":"latest","vitest":"latest","esbuild":"latest","typescript":"latest"},"_npmOperationalInternal":{"tmp":"tmp/alien-signals_0.4.2_1732438271784_0.3676790695962464","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":1732438271968,"maintainers":[{"name":"johnsoncodehk","email":"johnsoncodehk@gmail.com"}],"_cnpm_publish_time":1732438271968,"dist-tags":{"latest":"3.2.1"}}