@ fest-lib/ 对象
1级——通过LUR.E和FL.UI订阅 affected。 。 。 .
对象、阵列的活性代理人, Set,以及 Map。订阅 没有 保留目标。 只在数值实际变化时更新起火.
core · uniform
└── fest/object ← you are here
└── lure · veela · icon · image · fl-ui
安装
npm install @fest-lib/core @fest-lib/uniform @fest-lib/object
端点 : @fest-lib/core, (中文(简体) ), @fest-lib/uniform (单位:千美元)>=0.1.0无害环境管理,节点 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?.();
特征
- 非侵入性订阅(处理自
affected) (中文(简体) ). observe适应Set编号 :Map重复改变通知.- 以胁迫为主的反驳
numberRef, (中文(简体) ),stringRef, (中文(简体) ),booleanRef) (中文(简体) ). computed编号 :derivate编号 :conditional编号 :propRef。 。 。 .bindBy编号 :assign编号 :link用于形状同步.safe()用于JSON(循环,弱参考).
初级参考
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") 选择匹配的原始参考文献 .
收款
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 显示反应阵列视图 . iterated 订阅迭代.
衍生绑定( B)
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 地图
| 组 | 出口 |
|---|---|
| 反应 | observe, (中文(简体) ), affected, (中文(简体) ), isObservable, (中文(简体) ), recoverReactive, (中文(简体) ), makeArrayObservable |
| 参考文献 | ref, (中文(简体) ), numberRef, (中文(简体) ), stringRef, (中文(简体) ), booleanRef, (中文(简体) ), autoRef, (中文(简体) ), promised, (中文(简体) ), propRef |
| 衍生 | computed, (中文(简体) ), derivate, (中文(简体) ), conditional, (中文(简体) ), remap, (中文(简体) ), unified |
| 捆绑 | bindBy, (中文(简体) ), assign, (中文(简体) ), link |
| 收款 | observableBySet, (中文(简体) ), observableByMap, (中文(简体) ), iterated |
| 时间安排 | triggerWithDelay, (中文(简体) ), delayedBehavior, (中文(简体) ), delayedOrInstantBehavior |
| 用户 | safe, (中文(简体) ), deref, (中文(简体) ), unwrap, (中文(简体) ), unaffected |
| 遗产 | createReactive, (中文(简体) ), createReactiveMap, (中文(简体) ), createReactiveSet (折旧) |
affected(obj, cb) 或者说 affected([obj, key], cb) + 未订阅函数 。 留取并称.
资料来源: src/core/Mainline.ts (订阅), Primitives.ts, (中文(简体) ), Assigned.ts, (中文(简体) ), Subscript.ts, (中文(简体) ), src/wrap/*。 。 。 .
工作空间
cd modules/projects/object.ts
npm test # node + deno + browser
npm run build
npm run publish
许可证 : 麻省理工学院。 。 。 .