@fest-lib/object

中文文档
0.1.53发布于 2026/11/10MITES Module近 30 天下载 3110

fest-lib reactivity: observe, affected, refs, computed, collection proxies

原始使用文档
文档目录7 节
  1. Install
  2. Features
  3. Primitive refs
  4. Collections
  5. Derived & bind
  6. API map
  7. Workspace

@fest-lib/object
Level 1 — observe / affected / refs. LUR.E and FL.UI subscribe through affected.

npm MIT stars

Reactive proxies for objects, arrays, Set, and Map. Subscriptions do not retain the target. Updates fire only when the value actually changes.

core · uniform
 └── fest/object      ← you are here
      └── lure · veela · icon · image · fl-ui

Install

npm install @fest-lib/core @fest-lib/uniform @fest-lib/object

Peers: @fest-lib/core, @fest-lib/uniform (>=0.1.0). ESM, Node 20+.

import { observe, affected, ref, computed } from "@fest-lib/object";

const state = observe({ count: 0, user: { name: "Ada" } });
const stop = affected(state, (value, prop) => {
    console.log("changed:", prop, value[prop as keyof typeof value]);
});
state.count = 1;
stop?.();

Features

  • Non-intrusive subscriptions (disposer from affected).
  • observe adapts Set / Map so iteration changes notify.
  • Primitive refs with coercion (numberRef, stringRef, booleanRef).
  • computed / derivate / conditional / propRef.
  • bindBy / assign / link for shape sync.
  • safe() for JSON (cycles, WeakRef).

Primitive refs

import { numberRef, stringRef, booleanRef, autoRef, promised } from "@fest-lib/object";

const n = numberRef(0);
const s = stringRef("hello");
const b = booleanRef(false);
n.value++;
s.value = `${s}!`;
b.value = 1;                    // truthy → true

const later = promised(fetch("/api").then((r) => r.status));

autoRef(true) / autoRef(42) / autoRef("hi") pick the matching primitive ref.

Collections

const list = observe([1, 2, 3]);
const bag = observe(new Set(["a", "b"]));
const map = observe(new Map([["x", 1]]));

affected(list, (_v, prop) => console.log("list", prop));
affected([observe({ name: "Ada" }), "name"], (v) => console.log("name:", v));

observableBySet / observableByMap expose a reactive array view. iterated subscribes to iteration.

Derived & bind

const source = observe({ x: 1, y: 2 });
const total = computed(source, (s) => s.x + s.y);
const view = derivate(source, (s) => ({ sum: s.x + s.y }));

const target = { x: 0, y: 0 };
bindBy(target, source);         // two-way by shape
source.x = 3;                   // target.x === 3
const cond = booleanRef(true);
const pick = conditional(cond, "yes", "no");
cond.value = false;             // pick.value === "no"

const obj = observe({ nested: { value: 42 } });
const deep = propRef(obj, "nested.value");

API map

GroupExports
Reactivityobserve, affected, isObservable, recoverReactive, makeArrayObservable
Refsref, numberRef, stringRef, booleanRef, autoRef, promised, propRef
Derivedcomputed, derivate, conditional, remap, unified
BindbindBy, assign, link
CollectionsobservableBySet, observableByMap, iterated
TimingtriggerWithDelay, delayedBehavior, delayedOrInstantBehavior
Utilssafe, deref, unwrap, unaffected
LegacycreateReactive, createReactiveMap, createReactiveSet (deprecated)

affected(obj, cb) or affected([obj, key], cb) → unsubscribe function. Keep it and call it.

Sources: src/core/Mainline.ts (subscribe), Primitives.ts, Assigned.ts, Subscript.ts, src/wrap/*.

Workspace

cd modules/projects/object.ts
npm test                 # node + deno + browser
npm run build
npm run publish

License: MIT.

版本与发布记录

@fest-lib/object 共发布 50 个版本,首次发布于 2026/08/07;过去 12 个月发布了 50 个版本。

版本发布日期距今
0.1.53latest2026/11/104 天前
0.1.522026/11/104 天前
0.1.512026/11/086 天前
0.1.502026/11/086 天前
0.1.492026/11/0212 天前
0.1.482026/11/0212 天前

关于 @fest-lib/object 的常见问题

@fest-lib/object 是什么?

fest-lib reactivity: observe, affected, refs, computed, collection proxies

如何安装 @fest-lib/object?

在项目目录运行 npm install @fest-lib/object,或使用 pnpm add / yarn add / bun add。它还需要宿主项目提供 peer 依赖:@fest-lib/core(>=0.1.0)、@fest-lib/uniform(>=0.1.0)。npm 7 及以上与 pnpm 8 及以上默认会自动安装必需的 peer 依赖,Yarn 需要手动安装。

@fest-lib/object 支持 TypeScript 吗?

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

@fest-lib/object 支持 ESM 还是 CommonJS?

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

@fest-lib/object 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=20。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@fest-lib/object 可以商用吗?

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

@fest-lib/object 的下载量有多少?

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

@fest-lib/object 还在维护吗?

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