Skip to main content

Runtime API

This is the complete public surface of the tannijs package. Most apps only use the reactivity and lifecycle functions; the DOM utilities are low-level helpers that the compiler also emits.

import {
createSignal,
createEffect,
createMemo,
effect,
batch,
untrack,
onMount,
onCleanup,
template,
insert,
spread,
delegateEvents,
} from 'tannijs';

Reactivity

See the Reactivity guide for examples.

ExportSignatureDescription
createSignal<T>(initialValue: T) => [Accessor<T>, Setter<T>]Creates a reactive value as a [getter, setter] tuple.
createEffect(fn: () => void) => voidRuns fn immediately and re-runs it when its tracked signals change.
effect(fn: () => void) => voidAlias for createEffect.
createMemo<T>(fn: () => T) => Accessor<T>Cached derived value; recomputes only when dependencies change.
batch<T>(fn: () => T) => TDefers dependent computations until the batch completes.
untrack<T>(fn: () => T) => TReads signals inside fn without registering them as dependencies.

Lifecycle

See the Lifecycle guide.

ExportSignatureDescription
onMount(fn: () => void) => voidRuns fn after the component's setup completes.
onCleanup(fn: () => void) => voidRegisters teardown; must be called inside a tracked computation (effect or memo).

Types

type Accessor<T> = () => T;
type Setter<T> = (value: T | ((prev: T) => T)) => T;
  • Accessor<T> — a signal getter; call it to read the value.
  • Setter<T> — a signal setter; pass a new value or an updater function. Returns the resulting value.

DOM utilities

These low-level helpers are used by compiled component output. You generally won't call them directly, but they're part of the public API.

ExportSignatureDescription
template(html: string) => NodeBuilds a DOM node (or fragment) from an HTML string.
insert(parent: Node, value: InsertValue, marker?: Node | null) => voidInserts a value into parent; if value is a function it's tracked and updated reactively.
spread(element: Element, props: Record<string, unknown>) => voidApplies a props object to an element (attributes, style, children, and event handlers).
delegateEvents(eventNames: string[]) => voidRegisters delegated listeners on document for the given event names.

InsertValue

type InsertValue =
| Node
| string
| number
| boolean
| null
| undefined
| InsertValue[]
| (() => InsertValue);

:::note tannijs/internals Compiled components import their runtime helpers from tannijs/internals. That subpath is an implementation detail used by the compiler — in your own code, import from tannijs. :::