API Reference
Key exports and types from @constela/runtime
Key Exports
| Export | Description |
|---|---|
createApp | Creates an application instance |
mount | Mounts the app to a DOM element |
hydrate | Hydrates server-rendered HTML |
applyEnterTransition | Applies enter transition to an element |
applyExitTransition | Applies exit transition to an element |
createApp
Creates a new Constela application instance:
typescript
function createApp(program: CompiledProgram): App;mount
Mounts an application to a DOM element:
typescript
function mount(app: App, container: HTMLElement): void;hydrate
Hydrates a server-rendered application:
typescript
function hydrate(app: App, container: HTMLElement): void;App Interface
typescript
interface App {
destroy(): void;
getState(): Record<string, unknown>;
dispatch(action: string, payload?: unknown): void;
}Transition Functions
Low-level transition utilities for applying CSS class-based enter/exit animations. These are called automatically by the runtime when transition is specified on if or each nodes.
applyEnterTransition
Applies an enter transition to a DOM element:
typescript
function applyEnterTransition(el: HTMLElement, config: TransitionDirective): () => void;| Parameter | Type | Description |
|---|---|---|
el | HTMLElement | Target DOM element |
config | TransitionDirective | Transition class configuration |
| Returns | () => void | Cancel function to abort the transition |
Flow:
- Apply
config.enterclass - Next animation frame: apply
config.enterActive - On
transitionend(or fallback timeout): remove both classes
applyExitTransition
Applies an exit transition to a DOM element:
typescript
function applyExitTransition(
el: HTMLElement,
config: TransitionDirective
): { promise: Promise<void>; cancel: () => void };| Parameter | Type | Description |
|---|---|---|
el | HTMLElement | Target DOM element |
config | TransitionDirective | Transition class configuration |
| Returns | { promise, cancel } | Promise resolves when transition completes; cancel aborts it |
Flow:
- Apply
config.exitclass - Next animation frame: apply
config.exitActive - On
transitionend(or fallback timeout): remove both classes and resolve
TransitionDirective
typescript
interface TransitionDirective {
enter: string;
enterActive: string;
exit: string;
exitActive: string;
duration?: number;
}Note
These functions are used internally by the runtime. Direct usage is only needed for advanced use cases such as custom renderers.