用途:按既定模式创建 Zustand store,并配合正确的 TypeScript 类型与中间件。
主要能力与用法:从 assets/template.ts 复制模板并替换占位符,{{StoreName}} 替换为 PascalCase 仓库名(如 Project),{{description}} 替换为 JSDoc 简述。始终使用 subscribeWithSelector 中间件,示例为 import { create } from 'zustand'; import { subscribeWithSelector } from 'zustand/middleware'; 并以 create()(subscribeWithSelector((set, get) => ({...}))) 形式创建。建议将状态与动作分离:分别定义 MyState、MyActions,再以 MyStore = MyState & MyActions 组合。组件内使用单独选择器,如 useMyStore((state) => state.items),避免解构整个 store 导致任意状态变化都重渲染。可在 React 之外订阅,如 useMyStore.subscribe((state) => state.selectedId, (selectedId) => console.log('Selected:', selectedId))。集成步骤:在 src/frontend/src/store/ 创建 store,从 src/frontend/src/store/index.ts 导出,并在 src/frontend/src/store/*.test.ts 添加测试。
适用场景:需要按统一模式新增或维护 Zustand 状态仓库的前端项目。
限制:仅当任务明确匹配上述范围时使用;输出不能替代针对具体环境的验证、测试或专家审查;若缺少必要输入、权限、安全边界或成功标准,应停止并请求澄清。