Skip to content

Types

Complete reference for all TypeScript types exported by Vio.

Import

All types are available as named exports from the vio package:

ts
import type {
  VioNodeDescriptor,
  VioChild,
  ComponentDef,
  ComponentContext,
  ComponentInstance,
  Route,
  StoreConfig,
  AppConfig,
  VioEvent,
  VioEventType,
  BatchOperation,
} from '@atrotos/vio'

import type { VioApp } from '@atrotos/vio'
import type { VioForm } from '@atrotos/vio'
import type { RouteMatch } from '@atrotos/vio'

VioNodeDescriptor

Describes a virtual DOM node in Vio's rendering system.

ts
interface VioNodeDescriptor {
  tag: string | RenderFunction | ComponentDef
  props?: Record<string, unknown>
  children?: VioChild[]
  key?: string | number
}
PropertyTypeRequiredDescription
tagstring | RenderFunction | ComponentDefYesHTML tag name, a render function, or a component definition
propsRecord<string, unknown>NoElement attributes and properties
childrenVioChild[]NoChild nodes
keystring | numberNoUnique key for efficient diffing
ts
const node: VioNodeDescriptor = {
  tag: 'div',
  props: { class: 'container', id: 'main' },
  children: [
    { tag: 'h1', children: ['Hello'] },
    { tag: 'p', children: ['Welcome to Vio'] }
  ]
}

VioChild

A union type representing any valid child of a VioNodeDescriptor.

ts
type VioChild = VioNodeDescriptor | string | number | boolean | null | undefined

Strings and numbers are rendered as text nodes. boolean, null, and undefined are ignored during rendering.


RenderFunction

The function signature for a component's render method.

ts
type RenderFunction = (
  state: Record<string, unknown>,
  store?: Record<string, unknown>
) => VioNodeDescriptor
ParameterTypeDescription
stateRecord<string, unknown>The component's local state
storeRecord<string, unknown>The global store state (if a store is configured)

ComponentDef

Defines the shape and behavior of a component.

ts
interface ComponentDef {
  name: string
  state?: Record<string, unknown>
  render: RenderFunction
  onMount?: (ctx: ComponentContext) => void | (() => void)
  onUpdate?: (ctx: ComponentContext, prevState: Record<string, unknown>) => void
  onUnmount?: (ctx: ComponentContext) => void
}
PropertyTypeRequiredDescription
namestringYesUnique component name
stateRecord<string, unknown>NoInitial state
renderRenderFunctionYesRender function returning a virtual node
onMount(ctx: ComponentContext) => void | (() => void)NoCalled after mount; may return cleanup function
onUpdate(ctx: ComponentContext, prevState) => voidNoCalled after state changes
onUnmount(ctx: ComponentContext) => voidNoCalled before removal

See: defineComponent


ComponentContext

Passed to lifecycle hooks, providing methods to interact with the component.

ts
interface ComponentContext {
  setState: (partial: Record<string, unknown>) => void
  getState: () => Record<string, unknown>
  emit: (event: string, payload?: unknown) => void
  getRef: (name: string) => HTMLElement | null
}
MethodDescription
setState(partial)Merge partial state and trigger re-render
getState()Get a copy of current state
emit(event, payload?)Emit an event on the application event bus
getRef(name)Get a DOM element by ref name

See: defineComponent - ComponentContext


ComponentInstance

Represents a mounted component tracked by the runtime.

ts
interface ComponentInstance {
  id: string
  def: ComponentDef
  state: Record<string, unknown>
  node: VioNodeDescriptor | null
  element: HTMLElement | null
  cleanup?: () => void
}
PropertyTypeDescription
idstringAuto-generated unique instance ID
defComponentDefThe component definition
stateRecord<string, unknown>Current state
nodeVioNodeDescriptor | nullLast rendered virtual node
elementHTMLElement | nullThe component's DOM element
cleanup(() => void) | undefinedCleanup function from onMount

See: defineComponent - ComponentInstance


Route

Defines a route mapping between a URL path and a component.

ts
interface Route {
  path: string
  component: ComponentDef
  guard?: (store: Record<string, unknown>) => boolean
}
PropertyTypeRequiredDescription
pathstringYesURL pattern (supports :param dynamic segments and * wildcard)
componentComponentDefYesComponent to render when matched
guard(store) => booleanNoGuard function; returns false to skip this route

See: Router


RouteMatch

Returned by the router when a path matches a route.

ts
interface RouteMatch {
  component: ComponentDef
  params: Record<string, string>
  path: string
  query: Record<string, string>
}
PropertyTypeDescription
componentComponentDefThe matched component
paramsRecord<string, string>Dynamic path parameters
pathstringThe matched pathname
queryRecord<string, string>Parsed query string parameters

See: Router


StoreConfig

Configuration for the global store.

ts
interface StoreConfig {
  state: Record<string, unknown>
  actions: Record<string, StoreAction>
}

interface StoreAction {
  (state: Record<string, unknown>, payload?: unknown): Record<string, unknown>
}
PropertyTypeDescription
stateRecord<string, unknown>Initial store state
actionsRecord<string, StoreAction>Map of action name to handler. Each handler receives the current state and optional payload, and returns the new state.

See: Store


AppConfig

Configuration passed to createApp.

ts
interface AppConfig {
  root: string | HTMLElement
  routes?: Route[]
  store?: StoreConfig
}
PropertyTypeRequiredDescription
rootstring | HTMLElementYesCSS selector or DOM element to mount the app into
routesRoute[]NoRoute definitions for client-side routing
storeStoreConfigNoGlobal store configuration

See: createApp


VioEvent

Represents an event emitted on the event bus.

ts
interface VioEvent {
  type: VioEventType | string
  payload: Record<string, unknown>
  timestamp: number
}
PropertyTypeDescription
typeVioEventType | stringEvent type (built-in or custom)
payloadRecord<string, unknown>Event data
timestampnumberUnix timestamp in milliseconds (Date.now())

See: EventBus


VioEventType

A union of all built-in event type strings.

ts
type VioEventType =
  | 'state:change'
  | 'store:change'
  | 'component:mount'
  | 'component:update'
  | 'component:unmount'
  | 'route:before'
  | 'route:change'
  | 'route:after'
  | 'batch:start'
  | 'batch:end'
ValueSourceDescription
state:changeRendererComponent state was updated
store:changeStoreGlobal store state changed via dispatch
component:mountRendererA component was mounted to the DOM
component:updateRendererA component was re-rendered
component:unmountRendererA component was removed from the DOM
route:beforeRouterBefore a route change
route:changeRouterRoute has changed
route:afterRouterAfter a route change
batch:startAppA batch operation started
batch:endAppA batch operation completed

See: EventBus


BatchOperation

Describes a single operation within a batch call.

ts
interface BatchOperation {
  action: 'setState' | 'addComponent' | 'removeComponent' | 'updateProps' | 'dispatch' | 'navigate'
  target?: string
  payload?: unknown
}
PropertyTypeRequiredDescription
actionstringYesThe operation type
targetstringNoInstance ID or path, depending on the action
payloadunknownNoData for the operation

Supported Actions

ActiontargetpayloadDescription
setStateInstance IDRecord<string, unknown>Merge state into a component
dispatch--{ action: string, value?: unknown }Dispatch a store action
removeComponentInstance ID--Unmount a component
navigatePath string--Navigate to a route
addComponent----Reserved for future use
updateProps----Reserved for future use

See: createApp - batch, Batch Operations guide


VioForm

Interface for form objects returned by createForm.

ts
interface VioForm {
  getValues(): Record<string, unknown>
  setValue(field: string, value: unknown): void
  validate(): Record<string, string | null>
  isValid(): boolean
  reset(): void
  toNodeDescriptor(): VioNodeDescriptor
}
MethodReturn TypeDescription
getValues()Record<string, unknown>Get all current field values
setValue(field, value)voidSet a field value
validate()Record<string, string | null>Run all validators; returns errors map
isValid()booleantrue if all fields pass validation
reset()voidReset all fields to initial values
toNodeDescriptor()VioNodeDescriptorGenerate a form node descriptor

See: Forms


FormConfig

Configuration for createForm.

ts
interface FormConfig {
  fields: Record<string, FieldDef>
  onSubmit?: (values: Record<string, unknown>) => void
}

See: Forms


FieldDef

Defines a single form field.

ts
interface FieldDef {
  initial: unknown
  validate?: (value: unknown) => string | null
  label?: string
  type?: string
}
PropertyTypeRequiredDescription
initialunknownYesInitial value
validate(value: unknown) => string | nullNoValidation function; return null for valid or an error message
labelstringNoDisplay label
typestringNoHTML input type (defaults to 'text')

See: Forms


HttpResponse

Response object returned by all HttpClient methods.

ts
interface HttpResponse<T = unknown> {
  data: T
  status: number
  headers: Headers
}
PropertyTypeDescription
dataTParsed response body
statusnumberHTTP status code
headersHeadersStandard Headers object

See: HttpClient

Released under the MIT License.