scaffold-frontend-feature
Guide for adding a new feature to the Web Frontend (Blazor), focusing on Reactive State, Optimistic Updates, and Cache Invalidation.
安装与使用
请根据来源仓库和你的 AI 工具说明安装此技能。先阅读技能文件和依赖要求,再添加到工作流。
查看来源 ↗使用指南技能说明
Follow this guide to implement a responsive frontend feature in src/Web/BookStore.Web.
-
Prerequisites
- Ensure the API Client exists:
src/Client/BookStore.Client/I{Resource}Client.cs. - Ensure the Shared/Response DTOs exist in
BookStore.Shared. - if NOT, run
/scaffold-reador/scaffold-writefirst.
- Ensure the API Client exists:
-
Create the Component
- Create/Update
src/Web/BookStore.Web/Components/Pages/{Feature}.razor. -
Template:
templates/Page.razor -
Lifecycle: Use
OnInitializedAsyncto start listening:EventsService.StartListening();.
- Create/Update
-
Implement Data Fetching
-
Pattern: Use
ReactiveQuery<T>. -
Setup (Template):
templates/ReactiveQueryInit.cs
-
Pattern: Use
-
Implement Optimistic Updates (Properties)
- Use Case: Toggling a boolean, changing a number (e.g., Favorites).
-
Pattern:
Mutate -> Call -> Rollback.query.MutateData(s => s with { IsFavorite = true }); // 1. Instant UI update try { await Client.UpdateAsync(); // 2. API Call } catch { query.MutateData(s => s with { IsFavorite = false }); // 3. Revert on error }
-
Implement Optimistic Updates (Lists)
- Use Case: Adding a new item to a list instantly.
-
Pattern:
OptimisticService.AddOptimisticBook(id, title); // 1. Add to separate list await Client.CreateAsync(); // 2. API Call (Event will confirm/remove it) -
UI: Merge
query.DatawithOptimisticService.GetOptimisticBooks()when rendering lists.
-
Configure Invalidation
- Open
src/Web/BookStore.Web/Services/QueryInvalidationService.cs. - Add cases to
GetInvalidationKeys(IDomainEventNotification notification). -
Rule: Map the Domain Event (e.g.,
BookCreated) to the Query Keys you defined in Step 2 (e.g.,"Books").
- Open
-
Verify
- Run the app and verify:
- Data loads.
- Mutations update UI instantly.
- SSE events (from other tabs/users) trigger auto-refetch.
- Run
/verify-featurefor complete verification.
- Run the app and verify:
Related Skills
Prerequisites:
- Backend endpoints must exist first:
-
/scaffold-write- For mutation endpoints -
/scaffold-read- For query endpoints
-
- Client SDK must be configured (usually done by scaffold-write/read)
Next Steps:
-
/scaffold-test- Create integration tests for the feature -
/verify-feature- Complete verification
Debugging:
-
/debug-sse- If real-time updates don't work -
/debug-cache- If query data is stale
See Also:
- real-time-notifications - SSE architecture
- scaffold-write - Backend mutations
- scaffold-read - Backend queries
- Web AGENTS.md - ReactiveQuery patterns and SSE integration
使用示例
查看来源仓库中的使用示例与配置说明。
查看来源 ↗来源历史
- 收录时间
- 2026-01-20
- 索引更新时间
- 2026-01-26
- Branch
- main
收录与同步日期属于本站记录。源码修改历史请查看来源仓库。
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!