website refactor
This commit is contained in:
@@ -22,17 +22,34 @@ ViewData is not:
|
||||
|
||||
## 3) Construction rules
|
||||
|
||||
ViewData MUST be created in client code:
|
||||
ViewData is created by **ViewData Builders**:
|
||||
|
||||
1) Initial SSR-safe render: `ViewData = fromDTO(PageDTO)`
|
||||
2) Post-hydration render: `ViewData = fromViewModel(ViewModel)`
|
||||
### Server Components (RSC)
|
||||
```typescript
|
||||
const apiDto = await PageQuery.execute();
|
||||
const viewData = ViewDataBuilder.build(apiDto);
|
||||
return <Template viewData={viewData} />;
|
||||
```
|
||||
|
||||
These transformations are Presenters.
|
||||
See [`PRESENTERS.md`](docs/architecture/website/PRESENTERS.md:1).
|
||||
### Client Components
|
||||
```typescript
|
||||
'use client';
|
||||
|
||||
const [viewModel, setViewModel] = useState<ViewModel | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
const apiDto = await apiClient.get();
|
||||
const vm = ViewModelBuilder.build(apiDto);
|
||||
setViewModel(vm);
|
||||
}, []);
|
||||
|
||||
// Template receives ViewModel, not ViewData
|
||||
return viewModel ? <Template viewModel={viewModel} /> : null;
|
||||
```
|
||||
|
||||
Templates MUST NOT compute derived values.
|
||||
|
||||
Presenters MUST NOT call the API.
|
||||
ViewData Builders MUST NOT call the API.
|
||||
|
||||
## 4) Determinism rules
|
||||
|
||||
@@ -46,7 +63,7 @@ Forbidden anywhere in formatting code paths:
|
||||
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 Presenters into ViewData.
|
||||
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 Display Objects
|
||||
|
||||
|
||||
Reference in New Issue
Block a user