37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
/**
|
|
* ViewModelBase contract
|
|
*
|
|
* Base class for all ViewModels.
|
|
*
|
|
* Based on VIEW_MODELS.md:
|
|
* - Client-only classes
|
|
* - Fully prepared UI state
|
|
* - Never serialized
|
|
* - Never passed to Templates
|
|
* - Compose Display Objects for reusable formatting
|
|
* - Expose UI-specific computed properties
|
|
*
|
|
* Based on WEBSITE_CONTRACT.md:
|
|
* - ViewModels are client-only
|
|
* - Must not expose methods that return Page DTO or API DTO
|
|
*
|
|
* Architecture Flow (Website):
|
|
* 1. PageQuery/Builder returns ViewData (server)
|
|
* 2. ViewData contains plain DTOs (JSON-serializable)
|
|
* 3. Template receives ViewData (SSR)
|
|
* 4. ClientWrapper/Hook transforms DTO → ViewModel (client)
|
|
* 5. UI Components use ViewModel for computed logic
|
|
*
|
|
* ViewModels provide UI state and helpers.
|
|
* They are instantiated on the client to wrap plain data with logic.
|
|
*/
|
|
|
|
export abstract class ViewModel {
|
|
/**
|
|
* Optional: Validate the ViewModel state
|
|
*
|
|
* Can be used to ensure the ViewModel is in a valid state
|
|
* before a Presenter converts it to ViewData.
|
|
*/
|
|
validate?(): boolean;
|
|
} |