40 lines
948 B
TypeScript
40 lines
948 B
TypeScript
/**
|
|
* Formatter contract
|
|
*
|
|
* Deterministic, reusable, UI-only formatting/mapping logic.
|
|
*
|
|
* Based on FORMATTERS.md:
|
|
* - Stateless (Formatters) or Immutable (Display Objects)
|
|
* - Deterministic
|
|
* - Side-effect free
|
|
* - No business rules
|
|
*
|
|
* Uncle Bob says: "Data structures should not have behavior."
|
|
* Formatters ensure ViewData remains a dumb container of primitives.
|
|
*/
|
|
|
|
export interface Formatter {
|
|
/**
|
|
* Format or map the input to a primitive value
|
|
*
|
|
* @returns Primitive values only (strings, numbers, booleans, null)
|
|
*/
|
|
format(): string | number | boolean | null;
|
|
}
|
|
|
|
/**
|
|
* Rich Display Object contract (Client-only)
|
|
*
|
|
* Used by ViewModels to provide a rich API to the UI.
|
|
*/
|
|
export interface DisplayObject {
|
|
/**
|
|
* Primary primitive output
|
|
*/
|
|
format(): string | number | boolean | null;
|
|
|
|
/**
|
|
* Multiple primitive variants
|
|
*/
|
|
variants?(): Record<string, string | number | boolean | null>;
|
|
} |