@actuallab/fusion

中文文档
15.1.24发布于 2026/11/07MITTypeScriptESM + CJS构建来源已验证近 30 天下载 3386

TypeScript implementation of Fusion - real-time state synchronization framework

原始使用文档
文档目录7 节
  1. Installation
  2. Compute methods
  3. Reactive states
  4. API surface
  5. Notes
  6. Documentation
  7. License

@actuallab/fusion

npm Documentation License

The TypeScript implementation of Fusion's core: memoized computations with automatic dependency tracking and cascading invalidation. It gives you Computed<T>, the @computeMethod decorator, ComputedState<T>, MutableState<T>, and UIActionTracker — the same abstractions Fusion provides on .NET.

This package works standalone (client-side reactive state, no server needed). Add @actuallab/fusion-rpc to consume invalidation-aware Compute Services from a .NET server, and @actuallab/fusion-react to render them in React.

Installation

npm install @actuallab/fusion

ESM-first with a CJS fallback; ships its own .d.ts. Depends only on @actuallab/core.

Compute methods

@computeMethod is the equivalent of .NET's [ComputeMethod] — it wraps a method with caching and dependency tracking. Results are keyed by JSON.stringify of the arguments.

import { computeMethod } from '@actuallab/fusion';

class CounterService {
    private _counters = new Map<string, number>();

    @computeMethod
    async get(key: string): Promise<number> {
        return this._counters.get(key) ?? 0;
    }

    @computeMethod
    async sum(key1: string, key2: string): Promise<number> {
        // sum() automatically depends on get(key1) and get(key2)
        return (await this.get(key1)) + (await this.get(key2));
    }

    increment(key: string): void {
        this._counters.set(key, (this._counters.get(key) ?? 0) + 1);
        (this.get as any).invalidate(key);  // cascades into sum()
    }
}

There is no Invalidation.Begin() block here: every bound compute method carries an .invalidate(...args) function. For standalone functions, use wrapComputeMethod.

Reactive states

ComputedState<T> recomputes itself whenever anything it used gets invalidated; MutableState<T> is set by hand and participates in the same dependency graph.

import { ComputedState, MutableState, FixedDelayer } from '@actuallab/fusion';

const state = new ComputedState(
    async () => `Count: ${await counters.get('a')}`,
    { initialValue: 'loading...', updateDelayer: FixedDelayer.get(500) },
);

await state.whenFirstTimeUpdated();
state.value;     // "Count: 0" — and it updates on its own from here on
state.dispose(); // required: stops the update loop

const query = new MutableState('');
query.set('fusion');  // invalidates every computation that called query.use()

API surface

APIDescription
Computed<T>, ConsistencyStateCached computation result: .value, .update(), .use(), .invalidate(), .whenInvalidated()
Computed.capture(fn)Capture the Computed<T> a compute call produced
computeMethod, wrapComputeMethodTurn a method / function into a compute function
ComputedOptionsPer-method options, e.g. errorAutoInvalidateDelay
ComputedRegistry, ComputeFunction, ComputeContextThe kernel, for advanced/custom integrations
State<T>, ComputedState<T>, MutableState<T>Reactive states
UpdateDelayer, FixedDelayer, UIUpdateDelayer, defaultUpdateDelayerRecompute pacing (≈32 ms floor, retry backoff)
UIActionTracker, uiActionsTracks running UI commands, collects errors, enables instant updates

Notes

  • Dependency tracking across await. On Node ≥ 20.16 AsyncContext is backed by AsyncLocalStorage, so it just works. In browsers the child AsyncContext is passed to your compute method as a trailing argument — accept it and forward it into nested compute calls. See AsyncContext: Why It Matters.
  • Dispose your ComputedStates. Otherwise their update loops keep running.
  • Errors. Compute methods auto-invalidate an error output after 1 s by default (configurable via @computeMethod({ errorAutoInvalidateDelay })); states never do — they retry with backoff. Cancellation-shaped errors are never cached.

Documentation

License

MIT — see LICENSE.

版本与发布记录

@actuallab/fusion 共发布 54 个版本,首次发布于 2026/02/18;过去 12 个月发布了 54 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
15.1.24latest2026/11/07今天
15.1.222026/11/07今天
15.1.152026/11/07今天
15.1.112026/11/07今天
15.1.62026/11/07今天
15.0.212026/10/2414 天前

关于 @actuallab/fusion 的常见问题

@actuallab/fusion 是什么?

TypeScript implementation of Fusion - real-time state synchronization framework

如何安装 @actuallab/fusion?

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

@actuallab/fusion 支持 TypeScript 吗?

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

@actuallab/fusion 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@actuallab/fusion 可以商用吗?

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

@actuallab/fusion 的下载量有多少?

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

@actuallab/fusion 还在维护吗?

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