do to formatters
This commit is contained in:
@@ -11,6 +11,8 @@ It answers the question:
|
||||
View Models are **UI-owned** classes.
|
||||
They do not represent business truth and do not enforce domain rules.
|
||||
|
||||
**Uncle Bob says**: "Objects expose behavior, not data." ViewModels encapsulate the behavior of the UI.
|
||||
|
||||
---
|
||||
|
||||
## Responsibilities
|
||||
@@ -22,14 +24,14 @@ A View Model MAY:
|
||||
- combine or reshape data for rendering
|
||||
- perform formatting (dates, numbers, labels), especially for **client-only context** (e.g., local timezone, relative "time ago")
|
||||
- handle localization and presentation logic
|
||||
- use Display Objects for reusable UI concerns
|
||||
- use **Display Objects** for reusable UI concerns and rich APIs
|
||||
|
||||
### Formatting Responsibility
|
||||
|
||||
While `ViewData Builders` handle formatting for SEO and initial render, `View Models` are responsible for:
|
||||
While `ViewData Builders` handle formatting for SEO and initial render using **Formatters**, `View Models` are responsible for:
|
||||
- **Client-specific formatting:** Data that depends on the browser's locale, timezone, or precise location.
|
||||
- **Interactive formatting:** Updating display values in response to user input or state changes.
|
||||
- **Consistency:** Using the same `Display Objects` as the server to ensure a consistent look and feel.
|
||||
- **Rich APIs:** Providing **Display Objects** to the UI for multi-variant formatting (e.g., `date.short`, `date.relative`).
|
||||
|
||||
In the website SSR/RSC architecture, View Models MAY compute view-only derived values, but MUST NOT be the type passed into Templates.
|
||||
|
||||
@@ -78,7 +80,7 @@ Rules (website):
|
||||
1) View Models are created in client code only.
|
||||
2) View Models are created from **ViewData** (not from DTOs).
|
||||
3) Templates MUST NOT accept View Models; Templates accept ViewData only.
|
||||
4) View Models MUST compose Display Objects and produce ViewData (primitive outputs only).
|
||||
4) View Models MUST compose Display Objects and produce rich UI APIs.
|
||||
|
||||
Authoritative reference: [plans/nextjs-rsc-viewmodels-concept.md](plans/nextjs-rsc-viewmodels-concept.md:1).
|
||||
|
||||
|
||||
Reference in New Issue
Block a user