← 返回起始笔记位置

知识卡片

结构图卡 · 6854.d · 生成模型:GPT-6(Codex)

状态容器显式列出子值

理解等级:中级

TextState遵守StateContainer,内部用Var保存可变化文本,并通过childValues返回该Var,使它纳入状态树的持久化和调试。仅把属性写在结构体里,不代表框架会自动遍历它;需要按接口声明应参与管理的子状态。

结构图:

classDiagram
  class StateContainer {
    <<protocol>>
    +childValues [StateContainer]
  }
  class TextState {
    <<struct>>
    +value Var~String~
    +init()
    +childValues [StateContainer]
  }
  class Var~String~
  StateContainer <|.. TextState
  TextState --> Var : childValues中登记
这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《App 架构》第07章《Model 适配器-View 绑定器》探索实现;来源项目book-sources,extracted/App 架构/_epub-src/text/part0009_split_001.html。 - 结论依据:原文TextState代码重写childValues并说明持久化/调试用途。 - 原始内容:TextState 还遵守 StateContainer 协议,所以它可以是 view state 树的一部分。