feat:新增代码注释
This commit is contained in:
@@ -9,11 +9,17 @@ class AddHandler(BaseActionHandler[AddAction]):
|
||||
def apply(self, screen: Screen, action: AddAction) -> Screen:
|
||||
# 重新校验节点,避免模型创建后被修改成无效内容
|
||||
node = ScreenNode.model_validate(action.node.model_dump())
|
||||
|
||||
# 如果新节点 ID 与已有组件重复,拒绝新增,避免后续按 ID 查找时产生歧义
|
||||
if any(existing.id == node.id for existing in screen.nodes):
|
||||
raise ValueError(f"新增组件 ID 已存在: {node.id}")
|
||||
|
||||
# 深拷贝整个大屏,新增操作只影响返回的副本
|
||||
result = screen.model_copy(deep=True)
|
||||
# 追加到末尾,不共享动作中的嵌套配置
|
||||
result.nodes.append(node.model_copy(deep=True))
|
||||
|
||||
# 返回新增后的完整大屏,供后续动作继续模拟执行
|
||||
return result
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user