Skip to content

MeshFlow Core API


MeshFlow Core API / useMeshFlow

Function: useMeshFlow() ​

useMeshFlow<S, T, M, NM, P>(id, Schema, options): Engine<{ batchRenderExport: { init: any; }; destroyPlugin: () => void; dispose: () => void; formExports: { }; GetAllDependency: () => number[][]; GetDependencyOrder: () => number[][]; GetGroupByPath: (path) => MeshFlowGroupNode<MeshPath>; GetValue: (path, key) => any; hasRenderGate: () => boolean; historyExports: MeshFlowHistory; notifyAll: () => Promise<void>; onError: (cb) => Unsubscribe; onStart: (cb) => () => void; onSuccess: (cb) => () => void; scheduler: MeshScheduler<T, P, any, NM>; SetRule: <K, TKeys>(outDegreePath, inDegreePath, key, options) => void; SetRules: <TKeys, K>(outDegreePaths, inDegreePath, key, options) => void; SetStrategy: (path, key, strategy) => void; SettleTasks: (array) => void; SetValue: (path, key, value) => void; SetValues: (updates) => void; SilentSet: (path, key, value) => boolean; StageValue: (path, key, value) => void; useEntangle: <State>(config) => void; usePlugin: (plugin) => () => void; validatorExports: { SetValidators?: (path, options) => void; }; }, M, P>

Defined in: engine/useEngineManager.ts:172

[BOT] 初始化并获取 MeshFlow 引擎实例——这是所有 API 的入口

返回的 Engine 对象包含五大模块 ​

模块用途核心 API
engine.config规则与拓扑编排SetRule SetRules useEntangle notifyAll
engine.data数据大盘读写SetValue GetValue StageValue SilentSet
engine.hooks生命周期钩子onError onSuccess onStart
engine.dependency图分析工具GetAllDependency GetDependencyOrder
engine.modules扩展模块history form validator render

写入 API 速查 ​

方法触发拓扑?使用场景
SetValue立即点火用户交互、表单输入
SetValues批量点火一次修改多个节点
StageValue微任务聚合WebSocket 高频推送
SilentSet不点火系统重置、背景降噪

Type Parameters ​

S ​

S extends Record<string, any> | readonly Record<string, any>[]

— Schema 类型定义(as const 可推导精确路径字面量)

T ​

T

— UI 信号类型(Vue Ref<number> 或 React ()=>void)

M ​

M extends Record<string, any>

— 扩展模块映射类型(如 { useInternalForm, useHistory })

NM ​

NM extends Record<string, any> = IsNever<NormalizeSchema<S>> extends true ? Record<KeysOfUnion<NormalizeSchema<S>>, any> : InferLeafType<S>

— MetaType,推导各节点的属性键名供 triggerKeys 自动补全

P ​

P extends MeshPath = [InferLeafPath<S>] extends [never] ? MeshPath : string & object | InferLeafPath<S>

— 路径字面量联合类型(由 Schema 自动推导)

Parameters ​

id ​

MeshPath

— 引擎实例唯一标识(字符串/数字/符号),跨组件通过此 ID 复用

Schema ​

S

— 类型定义模板(仅 TS 类型推导,运行时通过 modules 注册节点)

options ​

— 引擎配置项与扩展模块 MeshFlowOptions

config? ​

{ BACKPRESSURE_LIMIT?: number; MAX_CONCURRENT_TASKS?: number; NODE_QUOTA_PER_FRAME?: number; useEntangleStep?: number; useGreedy?: boolean; }

config.BACKPRESSURE_LIMIT? ​

number

config.MAX_CONCURRENT_TASKS? ​

number

config.NODE_QUOTA_PER_FRAME? ​

number

config.useEntangleStep? ​

number

config.useGreedy? ​

boolean

metaType? ​

NM

modules? ​

M

UITrigger? ​

{ signalCreator: () => T; signalTrigger: (signal) => void; }

UITrigger.signalCreator ​

() => T

UITrigger.signalTrigger ​

(signal) => void

Returns ​

Engine<{ batchRenderExport: { init: any; }; destroyPlugin: () => void; dispose: () => void; formExports: { }; GetAllDependency: () => number[][]; GetDependencyOrder: () => number[][]; GetGroupByPath: (path) => MeshFlowGroupNode<MeshPath>; GetValue: (path, key) => any; hasRenderGate: () => boolean; historyExports: MeshFlowHistory; notifyAll: () => Promise<void>; onError: (cb) => Unsubscribe; onStart: (cb) => () => void; onSuccess: (cb) => () => void; scheduler: MeshScheduler<T, P, any, NM>; SetRule: <K, TKeys>(outDegreePath, inDegreePath, key, options) => void; SetRules: <TKeys, K>(outDegreePaths, inDegreePath, key, options) => void; SetStrategy: (path, key, strategy) => void; SettleTasks: (array) => void; SetValue: (path, key, value) => void; SetValues: (updates) => void; SilentSet: (path, key, value) => boolean; StageValue: (path, key, value) => void; useEntangle: <State>(config) => void; usePlugin: (plugin) => () => void; validatorExports: { SetValidators?: (path, options) => void; }; }, M, P>

Engine 对象,完整类型签名见 EngineCoreAPI

Example ​

ts
const engine = useMeshFlow('my-engine', schema, {
  UITrigger: {
    signalCreator: () => ref(0),      // Vue
    signalTrigger: (s) => s.value++,
  },
  modules: { useInternalForm },
});
engine.config.SetRule('a.path', 'b.path', 'value', {
  logic: ({ slot }) => slot.triggerTargets[0].count + 1,
});
engine.config.notifyAll();

⧩ MeshFlow — 确定性拓扑编排引擎