A logic orchestration engine utilizing topological scheduling and watermark control to resolve asynchronous race conditions in complex dependency linkages.”
npm install @meshflow/core@meshflow/core 专门解决以下痛点:
MeshFlow 的水位线机制确保只有对应最新操作的异步结果会被最终采纳。
if-else 和嵌套的 watch 让联动逻辑散落在各处,极难维护。
@meshflow/logger)。
bash
npm install @meshflow/core
`
#### 定义节点
`typescript
import { useMeshFlow } from "@meshflow/core";
const schema = {
type: 'group',
name: 'billing',
label: '计费与汇总',
children: [
{ type: 'number', name: 'totalPrice', label: '预估月度总价', defaultValue: 0, },
{ type: 'input', name: 'priceDetail', label: '计费项说明', defaultValue: '基础配置费用'}
]
};
const engine = useMeshFlow,AllPath>('main',schema, {
signalCreateor: () => ref(0),
signalTrigger(signal) {
signal.value++;
},
});
`
#### 添加联动依赖
`typescript
//声明联动规则:当总价 > 2000 时,自动修改描述与主题
engine.config.SetRule("billing.totalPrice", "billing.priceDetail", "defaultValue", {
logic: ({ slot }) => {
const [total] = slot.triggerTargets; // 从触发目标中解构出 totalPrice
return total > 2000 ? "大客户折扣" : undefined;
}
});
engine.config.SetRule( "billing.totalPrice", "billing.priceDetail", "theme", {
logic: (api) => {
const [value] = api.slot.triggerTargets;
return total > 2000 ? "warning" : undefined;
},
});
//触发首屏计算
engine.config.notifyAll();
`
🛠️ 为什么选择 MeshFlow?
在传统的事件驱动开发中,当 A 变化触发 B 和 C,而 B 和 C 又共同触发 D 时(钻石依赖),D 往往会被重复触发,且异步回填的顺序无法保证。
@meshflow/core` 通过内部的 DAG(有向无环图) 和 Watermark 机制,确保: