do to formatters

This commit is contained in:
2026-01-24 01:22:43 +01:00
parent 891b3cf0ee
commit 705f9685b5
18 changed files with 361 additions and 760 deletions

View File

@@ -12,13 +12,15 @@ ViewData is a JSON-serializable, template-ready data structure:
- arrays and plain objects
- `null` for missing values
**Uncle Bob says**: "Data structures should not have behavior." ViewData is a dumb container.
## 2) What ViewData is NOT
ViewData is not:
- an API Transport DTO (raw transport)
- a ViewModel (client-only class)
- a Display Object instance
- a Display Object instance (rich API)
## 3) Construction rules
@@ -58,7 +60,7 @@ ViewData Builders MUST NOT call the API.
ViewData is responsible for providing **fully formatted strings** to Templates for Server-Side Rendering (SSR).
- **SEO Requirement:** All data required for search engines (prices, dates, counts, labels) MUST be formatted in the `ViewData Builder` on the server.
- **SEO Requirement:** All data required for search engines (prices, dates, counts, labels) MUST be formatted in the `ViewData Builder` on the server using **Formatters**.
- **Template Simplicity:** Templates should simply render the strings provided in `ViewData` without further processing.
## 5) Determinism rules
@@ -75,7 +77,7 @@ Reason: SSR and browser outputs can differ.
Localization MUST NOT depend on runtime locale APIs.
If localized strings are required, they MUST be provided as deterministic inputs (for example via API-provided labels or a deterministic code-to-label map) and passed through ViewData Builders into ViewData.
## 5) Relationship to ViewModels
## 6) Relationship to ViewModels
ViewData serves as the stable, serializable contract between the server and client. It is:
- The input for Templates (both SSR and Client)
@@ -88,11 +90,11 @@ ViewModels are built from ViewData, not from DTOs. This ensures:
**Important:** ViewData MUST NOT contain ViewModel instances. ViewModels are classes with logic; ViewData is plain JSON.
## 6) Relationship to Display Objects
## 7) Relationship to Formatters & Display Objects
Display Objects are used to implement formatting/mapping, but their instances MUST NOT be stored inside ViewData.
Formatters are used to implement formatting/mapping, but their instances MUST NOT be stored inside ViewData.
Only primitive outputs produced by Display Objects may appear in ViewData.
Only primitive outputs produced by Formatters may appear in ViewData.
### The "Redundancy" Question
DTOs, ViewData, and ViewModels might share similar fields, but they are NOT redundant: