Skip to content

Lifecycle API

Declared by <huxerui/lifecycle.h>.

Registers setup in the current scope. Setup may return void or a callable cleanup returning void. Dependencies may be equality-comparable copyable values, State<T>, or StateList<T>; setup reruns when a captured value/version changes.

The previous cleanup runs before replacement. Final cleanup runs when the declaring scope unmounts. Without dependencies, the registration follows that scope’s mount lifetime.

Lifecycle is the public entry point. Callback erasure and captured-dependency wrappers live in huxerui::detail and are not application API.

Setup and cleanup execute on the Runtime UI thread during lifecycle commit, never while a previous cleanup for that registration is still active. Dependencies are copied at declaration time and compared on later composition. A State<T> or StateList<T> dependency tracks its cell version without forcing the setup callback to read that state.

Setup exceptions propagate through the frame commit. Cleanup is required to be callable as void(); it should not throw. Use Lifecycle for external subscriptions and retained resources, an event handler for user actions, and TaskScope for cancellable coroutine work.