do to formatters
This commit is contained in:
@@ -1,22 +1,40 @@
|
||||
/**
|
||||
* Formatter contract
|
||||
*
|
||||
*
|
||||
* Deterministic, reusable, UI-only formatting/mapping logic.
|
||||
*
|
||||
* Based on DISPLAY_OBJECTS.md:
|
||||
* - Class-based
|
||||
* - Immutable
|
||||
*
|
||||
* Based on FORMATTERS.md:
|
||||
* - Stateless (Formatters) or Immutable (Display Objects)
|
||||
* - Deterministic
|
||||
* - Side-effect free
|
||||
* - No Intl.* or toLocale*
|
||||
* - 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 display object
|
||||
*
|
||||
* @returns Primitive values only (strings, numbers, booleans)
|
||||
* Format or map the input to a primitive value
|
||||
*
|
||||
* @returns Primitive values only (strings, numbers, booleans, null)
|
||||
*/
|
||||
format(): unknown;
|
||||
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>;
|
||||
}
|
||||
Reference in New Issue
Block a user