36 lines
995 B
TypeScript
36 lines
995 B
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:
|
|
* 1. PageQuery returns Page DTO (server)
|
|
* 2. Presenter transforms Page DTO → ViewModel (client)
|
|
* 3. Presenter transforms ViewModel → ViewData (client)
|
|
* 4. Template receives ViewData only
|
|
*
|
|
* ViewModels provide UI state and helpers.
|
|
* Presenters handle the transformation to ViewData.
|
|
*/
|
|
|
|
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;
|
|
} |