闲社服务运行正常AI智能体自动化平台
f

FOSMVVM视图生成器

技能标识:fosmvvm-react-view-generator

Generate React components that render FOSMVVM ViewModels. Scaffolds ViewModelView pattern with hooks, loading states, and TypeScript types.

作者:admin | 来源记录:ClawHub
登记来源
ClawHub
版本
V 2.0.6
检测标记
后台标记通过
免费
免费获取
2
收藏
来源与检测标记为平台登记信息,并不代表已展示可复核的检测报告。使用前请核对版本、依赖和所需权限,建议先在隔离环境中运行。
概述
安装方式
版本历史

FOSMVVM视图生成器

FOSMVVM React 视图生成器

生成渲染 FOSMVVM ViewModel 的 React 组件。

概念基础

完整架构上下文请参见 FOSMVVMArchitecture.md | OpenClaw 参考

在 FOSMVVM 中,React 组件是显示 ViewModel 的薄渲染层:

┌─────────────────────────────────────────────────────────────┐
│ ViewModelView 模式 │
├─────────────────────────────────────────────────────────────┤
│ │
│ ViewModel (数据) React 组件 │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ title: String │────►│

{vm.title} │ │
│ │ items: [Item] │────►│ {vm.items.map()} │ │
│ │ isEnabled: Bool │────►│ disabled={!...} │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
│ ServerRequest (操作) │
│ ┌──────────────────┐ ┌──────────────────┐ │
│ │ processRequest() │◄────│ │ │ │ │ requestType={} │ │
│ └──────────────────┘ └──────────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘

关键原则: 组件不转换或计算数据。它们渲染 ViewModel 提供的内容。



视图-ViewModel 对齐

组件文件名应与它渲染的 ViewModel 名称匹配。

src/
viewmodels/
{Feature}ViewModel.js ←──┐
{Entity}CardViewModel.js ←──┼── 相同名称
│
components/ │
{Feature}/ │
{Feature}View.jsx ────┤ (渲染 {Feature}ViewModel)
{Entity}CardView.jsx ────┘ (渲染 {Entity}CardViewModel)

这种对齐方式提供:

  • - 可发现性 - 立即找到任何 ViewModel 对应的组件
  • 一致性 - 与 SwiftUI 和 Leaf 相同的命名规范
  • 可维护性 - ViewModel 的变更反映在组件位置中



TDD 工作流

此技能在单次调用中先生成测试,后生成实现:

  1. 1. 从对话上下文中引用 ViewModel 和 ServerRequest 详情
  2. 生成 .test.js 文件 → 测试失败(尚无实现)
  3. 生成 .jsx 文件 → 测试通过
  4. 验证完整性(两个文件都存在)
  5. 用户运行 npm test → 所有测试通过 ✓

上下文感知: 技能引用对话中对需求的理解。无需文件解析或问答。



核心组件

1. viewModelComponent() 包装器

每个组件都用 viewModelComponent() 包装:

jsx
const MyView = FOSMVVM.viewModelComponent(({ viewModel }) => {
return

{viewModel.title}
;
});

export default MyView;

必需:

  • - 使用全局命名空间中的 FOSMVVM.viewModelComponent()(通过 script 标签加载)
  • 组件函数接收 { viewModel } 属性
  • 无需导入 - FOSMVVM 工具通过