@hyperfrontend/state-machine/lifecycle-aware-component

lifecycle-aware-component

A component base that exposes initializing, ready, starting, stopping, and active state phases plus per-phase change callbacks.

LifecycleAwareComponent models a stateful component whose visibility to consumers depends on which phase it has reached — for example, a UI element that should only render after ready or a service that needs to drain in-flight work on stopping before becoming inactive. Each phase exposes a typed change callback (InitializingChangeCallback, ReadyChangeCallback, StartingChangeCallback, StoppingChangeCallback, ActiveChangeCallback) so subclasses or wrappers can react when the component crosses a boundary. The component composes the lower-level Events registry under the hood; reach for it when you need a structured lifecycle rather than raw pub/sub.

API Reference

Classes

§class

LifecycleAwareComponent

Abstract base class for components that need lifecycle state management. Tracks initializing, ready, starting, stopping, and active states.

Properties

§init:Process<any>
§start:Process<any>
§stop:Process<any>

Methods

§clear(): void
§onActiveStatusChange(callback: ActiveChangeCallback): LifecycleAwareComponent
§onInitializingStatusChange(callback: InitializingChangeCallback): LifecycleAwareComponent
§onReadyStatusChange(callback: ReadyChangeCallback): LifecycleAwareComponent
§onStartStatusChange(callback: StartingChangeCallback): LifecycleAwareComponent
§onStopStatusChange(callback: StoppingChangeCallback): LifecycleAwareComponent
§setActive(active: boolean): void
§setInitializing(initializing: boolean): void
§setReady(ready: boolean): void
§setStarting(starting: boolean): void
§setStopping(stopping: boolean): void

Types

§type

ActiveChangeCallback

Callback invoked when active state changes
type ActiveChangeCallback = (active: boolean) => void
§type

InitializingChangeCallback

Callback invoked when initializing state changes
type InitializingChangeCallback = (initializing: boolean) => void
§type

ReadyChangeCallback

Callback invoked when ready state changes
type ReadyChangeCallback = (ready: boolean) => void
§type

StartingChangeCallback

Callback invoked when starting state changes
type StartingChangeCallback = (starting: boolean) => void
§type

StoppingChangeCallback

Callback invoked when stopping state changes
type StoppingChangeCallback = (stopping: boolean) => void