view.ts
Purpose
This module defines view-related types and the contracts used to bind a controller to a UI layer.
Overview
The file contains no runtime logic, but it defines the public types used by withView(), createViewProxy(), and React integrations. Through these contracts, a controller receives view props as atoms together with lifecycle signals.
Conceptual Architecture
The module separates view concerns into three concepts:
ViewProps: input props of an arbitrary view.ViewPropAtoms<TProps>: reactive atom-based representation of those props.ViewBinding<TProps>: contract formount,update,unmount, together withpropsandstatus.
This allows UI adapters to describe lifecycle changes independently of any specific framework.
Public API Description
ViewProps
- Alias for
Record<string, unknown>. - Defines the baseline shape of view props.
ViewPropAtoms<TProps>
- Converts a props object into an object of atoms with the same keys.
ViewStatus
- One of
'unmounted','mounted', or'destroyed'.
ViewStatuses
- Constant object containing the supported
ViewStatusvalues.
ViewBinding<TProps>
props: atom-backed view props.status: atom with the current view status.onMount(listener),onUpdate(listener),onUnmount(listener): lifecycle subscriptions.
Usage Examples
ts
import type { ViewBinding } from '@nrgyjs/core';
type UserProps = { id: string };
function bindView(view: ViewBinding<UserProps>) {
view.onMount(() => {
console.log(view.props.id());
});
}