@effectful/es

中文文档
2.0.13发布于 2026/05/24MITCommonJS近 30 天下载 6507

Standard JavaScript effects using @effectful/core (abstract interface)

原始使用文档
文档目录8 节
  1. Why
  2. Usage
  3. Abstract interface
  4. Zero-config transformation
  5. Inlined concrete implementation
  6. Implicit parallelism
  7. Cancelation
  8. LICENSE

@effectful/es

The two-level abstract syntax for effects based on ECMAScript async, generator and async generator functions syntax overloading.

The project is a babel plugin for integrating new custom computational effects into JavaScript.

By default, it is yet another implementation of ECMAScript async, generator and async generator functions, but it also can be extended.

The project is a part of EffectfulJS tool chain.

Why

Here is a list of things not available with native or other transpiler implementations:

  • Abstract API - can be re-implemented or amended for your purposes
  • Custome Concrete API for better performance
  • Persistent state
  • Implicit parallelism
  • Deriving program's graph for static analysis

Usage

Abstract interface

$ npm install --save-dev @effectful/es
$ npm install --save @effectful/es-rt

For example:

{
  "plugins": ["@effectful/es/transform"]
}

Or:

$ babel --plugins @effectful/es/transform index.js

By default it injects imports for @effectful/es-rt.

It is an implementation of the abstract interface for EcmaScript async, generators and async functions. The interface doesn't yet have documentation. The default implementation is pretty small and can be used as a reference for now. There is importRT option to pass some overloaded concrete implementations libraries.

{
  "plugins": [["@effectful/es/transform",{"importRT":"my-custom-effects"}]]
}

Zero-config transformation

Zero-configuration using babel-plugin-macros, or any other tool where it is enabled by default (such as Create Reat App since v2).

Just import "@effectful/es/macro" module in the module you want to transpile.

Inlined concrete implementation

$ npm install --save-dev @effectful/es
$ npm install --save @effectful/es-inline-rt

This .babelrc

{
  "plugins": [["@effectful/es/transform",{"inline":true}]]
}

It is a much faster implementation, but there is no way to overload anything.

Other options are:

  • loose - like inline but it also drops a few ECMAScript compatibility features to make the generated code even more smaller and faster
  • defunct - if true state is encoded as number and a there is a single function to move between states; otherwise, the state is a state transition function callback
  • topLevel - if true moves state transition functions outside original function's body
  • par - enables implicit parallelism. It doesn't yet work with "inline", "loose" and "topLevel"

There are quite a few of lower level options described in config.js.

Their values can be provided using all, file, pure, effectful, generators, async, asyncGenerators fields in the plugin options. For example, to use CommonJS modules instead of defaulting ES for runtime injection use:

{
  "plugins": [["@effectful/es/transform",{"file":{"modules":"commonjs"}}]]
}

Implicit parallelism

If enabled the compiler will locate "par" and "seq" in the beginning of the block to switch between parallel and sequential mode resp.

For example:

async function parDemo() {
  "par";
  const a = await A;
  const b = await B(a);
  const c = await C;
}

ESLint complains about not used expressions, so as an alternative to the directives there is profile function which expects a single string literal parameter ("par" or "seq"):

import * as M from "@effectful/es"

async function parDemo() {
  M.profile("par");
  const a = await A;
  {
    M.profile("seq")
    const b = await B;
    const c = await C;
  }
}

Cancelation

By default, the runtime also adds M.cancelSymbol property to each returned Promise. It is a function and it tries to stop the execution of the corresponding async function. The cancelation is propagated to await expressions if they have this method, but it isn't propagated to children.

There is also a helper function M.cancel which simply calls promise[M.cancelSymbol]() if it exists.

LICENSE

Distributed under the terms of The MIT License (MIT).

版本与发布记录

@effectful/es 共发布 70 个版本,首次发布于 2017/11/06;过去 12 个月发布了 5 个版本。

版本发布日期距今
2.0.13latest2026/05/245 个月前
2.0.122026/05/235 个月前
2.0.92026/04/127 个月前
2.0.82025/11/2711 个月前
2.0.72025/11/2711 个月前
2.0.62025/06/051.4 年前

关于 @effectful/es 的常见问题

@effectful/es 是什么?

Standard JavaScript effects using @effectful/core (abstract interface)

如何安装 @effectful/es?

在项目目录运行 npm install @effectful/es,或使用 pnpm add / yarn add / bun add。

@effectful/es 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/effectful__es 是否存在。

@effectful/es 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@effectful/es 可以商用吗?

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

@effectful/es 的下载量有多少?

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

@effectful/es 还在维护吗?

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