Skip to content

bind · 绑定注册项 ​

把已校验的 DrawDocument 与注册表合并成 BoundDocument。

导出 ​

bindDocument、bindDocumentAsync,以及 BoundDocument、BoundNode、BoundEdge 类型。

签名 ​

ts
function bindDocument(
  document: DrawDocument,
  registry: RegistryView,
): Result<BoundDocument>;
function bindDocumentAsync(
  document: DrawDocument,
  registry: RegistryView,
): Promise<Result<BoundDocument>>;

同步入口遇到异步 Standard Schema 会发出 PROPS_INVALID 并回落;需要等待异步 schema 时用 bindDocumentAsync。layoutDocumentAsync 与 Pipeline.runAsync 会自动走异步 bind。

BoundDocument 保留原始文档,同时提供:

  • nodes:每个节点的生效 type、归一化 props、container 标记和 ShapeEntry;
  • edges:每条边的生效 type、归一化 props 和 EdgeSpec;
  • roots:根节点 id,顺序与文档一致。

为什么单独成段 ​

未知类型、props schema、children 是否允许和 marker 是否存在,都只在这里判断一次。 layout 与 build 拿到的是结论,不再各自查注册表判断“类型是否已经注册”。

诊断 ​

code场景
UNKNOWN_SHAPE / UNKNOWN_EDGE类型未注册,按内置矩形或直连折线回落
PROPS_INVALIDschema 校验失败,使用默认值或空 props
CHILDREN_ON_LEAF节点有 children,但形状未声明 container
UNKNOWN_MARKER / FALLBACK_USED端点 marker 缺失或发生了回落

bind 阶段的诊断只产生一次。后续 layout / build 接收 BoundDocument 时不会重复报同一问题。

MIT License