API Reference

Key exports and types from @constela/runtime

Key Exports

ExportDescription
createAppCreates an application instance
mountMounts the app to a DOM element
hydrateHydrates server-rendered HTML
applyEnterTransitionApplies enter transition to an element
applyExitTransitionApplies 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;
ParameterTypeDescription
elHTMLElementTarget DOM element
configTransitionDirectiveTransition class configuration
Returns() => voidCancel function to abort the transition

Flow:

  1. Apply config.enter class
  2. Next animation frame: apply config.enterActive
  3. 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 };
ParameterTypeDescription
elHTMLElementTarget DOM element
configTransitionDirectiveTransition class configuration
Returns{ promise, cancel }Promise resolves when transition completes; cancel aborts it

Flow:

  1. Apply config.exit class
  2. Next animation frame: apply config.exitActive
  3. On transitionend (or fallback timeout): remove both classes and resolve

TransitionDirective

typescript
interface TransitionDirective {
  enter: string;
  enterActive: string;
  exit: string;
  exitActive: string;
  duration?: number;
}