@effectionx/signals

中文文档
0.5.4发布于 2026/06/17MITTypeScriptES Module构建来源已验证近 30 天下载 5.2万

Reactive signals and computed values for Effection operations

原始使用文档
文档目录6 节
  1. About
  2. Included in this package
  3. Boolean Signal
  4. Array Signal
  5. Helpers
  6. is

Signals

Collection of immutable state containers for primitive data types.

About

One way to think about Effection operation is as composable components of asyncrony. They are conceptually similar to React components in that they're functions that invoke other functions. As with React's component tree, Effection operations are arranged into an operation tree. React components are designed to make it easier to compose DOM where Effection operations are designed to make it easier to compose asynchrony. Because of their simularities, it should come as no surpise that they would share patterns for state management. React Context and Effection Context is one example of this, but the benefits that unidirectional data flow provide to composition is another.

The Flux pattern, in tools like Redux and others, are "classic" ways to implement one directional data from in React applications. Over the years, these patterns involved into Signals which where implemented in variety of UI frameworks. The design of Signals in the JavaScript ecosystem assume that they will be integrated into some UI framework. Effection provides the necessary components to have robust yet simple implementation of Signals that doesn't require a UI framework.

Included in this package

The collection of Signals included in this package rely on Effection's Signal interface to provide immutable value streams with some operations. Each Signal includes set, update and valueOf methods. Each data type also includes methods provided by the primitive version of that data type. For example, ArraySignal provides push and shift, while Set provides difference. We don't implement all methods, mostly because haven't needed all of the methods. If you need a method that we didn't implement but it's available in the promitive type, please create a PR. If you need something else, use the update method.

Boolean Signal

The Boolean Signal provides a stream for a boolean value. You can set the value which will cause the new value to be sent to the stream.

import { each, run, spawn } from "effection";
import { createBooleanSignal } from "@effectionx/signals";

await run(function* () {
  const boolean = yield* createBooleanSignal(true);

  yield* spawn(function* () {
    for (const update of yield* each(boolean)) {
      console.log(update);
      yield* each.next();
    }
  });

  boolean.set(false); // this will send false to the stream
  boolean.set(true); // this will send true to the stream
  boolean.set(true); // this won't send anything since the value hasn't changed
});

For an example of Boolean Signal in action, checkout the faucet

Array Signal

The Array Signal provides a stream for the value of the array. The value is considered immutable - you shouldn't modify the value that comes through the stream, instead invoke methods on the signal to cause a new value to be sent.

import { each, run, spawn } from "effection";
import { createArraySignal } from "@effectionx/signals";

await run(function* () {
  const array = yield* createArraySignal<number>([]);

  yield* spawn(function* () {
    for (const update of yield* each(array)) {
      console.log(update);
      yield* each.next();
    }
  });

  array.push(1, 2, 3); // this will be a single update
});

For an example of Array Signl, checkout the valve and batch stream helpers.

Helpers

is

is helper returns an operation that completes when the value of the stream matches the predicate. It's useful when you want to wait for a signal to enter a specific state. Some of the common use cases are waiting for an array to reach a given length or for a boolean signal to become true or false.

is observes the signal's current state as well as any matching change, so it completes deterministically without the producer having to yield or sleep before publishing. It establishes its subscription before checking the current value, so a matching update that lands while it is starting to wait is never lost.

import { run, spawn } from "effection";
import { createBooleanSignal, is } from "@effectionx/signals";

await run(function* () {
  const open = yield* createBooleanSignal(false);

  yield* spawn(function* () {
    yield* is(open, (open) => open === true);
    console.log("floodgates are open!");
  });

  // No sleep or yield needed before publishing.
  open.set(true);
});

版本与发布记录

@effectionx/signals 共发布 10 个版本,首次发布于 2025/08/08;过去 12 个月发布了 7 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.5.4latest2026/06/174 个月前
0.5.32026/03/237 个月前
0.5.22026/02/248 个月前
0.5.12026/02/129 个月前
0.5.02026/01/199 个月前
0.4.12025/12/0811 个月前

关于 @effectionx/signals 的常见问题

@effectionx/signals 是什么?

Reactive signals and computed values for Effection operations

如何安装 @effectionx/signals?

在项目目录运行 npm install @effectionx/signals,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:effection(^3 || ^4)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@effectionx/signals 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@effectionx/signals 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@effectionx/signals 可以商用吗?

@effectionx/signals 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@effectionx/signals 的下载量有多少?

根据 npm 官方下载统计,@effectionx/signals 在 2026/10/13 – 2026/11/11 这 30 天内被下载 51,848 次,日均约 1,728 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@effectionx/signals 还在维护吗?

最新版本 0.5.4 发布于 2026/06/17(4 个月前);至今共发布 10 个版本,其中过去 12 个月发布了 7 个;首次发布于 2025/08/08。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。