halo DocsGitHub

halo/signals

Functions

batch

function batch<T>(fn: () => T): T

Applies every write in fn first, then runs affected effects once.

computed

function computed<T>(fn: () => T, options?: { equals?: Equals<T> }): Accessor<T>

A derived value, recomputed only when what it reads changes, and only if something reads it.

effect

function effect(fn: () => void): void

Runs fn now and again whenever a signal it read changes. Disposed with its owner.

externalSignal

function externalSignal<T>(name: string, options?: ExternalSignalOptions<T>): Accessor<T | undefined>

The latest value pushed with halo trigger <name>. Starts from the last payload the host saw, then from hydrate — unless a live event arrives first.

getOwner

function getOwner(): Owner | null

The current owner, to run code in it later with runWithOwner.

onCleanup

function onCleanup(fn: () => void): void

Registers fn to run when the current component, effect or root is disposed.

root

function root<T>(fn: (dispose: () => void) => T): T

Runs fn in a new ownership scope, disposed with its parent or by calling dispose.

runWithOwner

function runWithOwner<T>(owner: Owner | null, fn: () => T): T

Runs fn inside owner, so effects and cleanups created there belong to it.

signal

function signal<T>(initial: T, options?: { equals?: Equals<T> }): Signal<T>

Creates a signal. Readers update when it is set to a different value.

untrack

function untrack<T>(fn: () => T): T

Reads signals without subscribing to them.

Interfaces

ExternalSignalOptions

interface ExternalSignalOptions

Options for externalSignal().

PropertyTypeDescription
hydrate?stringShell command run on load (and so after every reload) to get the current state before the first event.
initial?T
parse?(payload: Payload) => T | undefinedTurns a payload into the signal's value; returning undefined ignores the payload.

Signal

function Signal(): T

A writable reactive value.

PropertyTypeDescription
set()(value: T): void
update()(fn: (value: T) => T): void

Types

Accessor

type Accessor<T> = () => T

Reads a reactive value; reading inside an effect, computed or reactive prop subscribes to it.

Equals

type Equals<T> = false | ((a: T, b: T) => boolean)

How a signal or computed decides a new value is unchanged (Object.is by default); false always notifies.

OwnerHandle

type OwnerHandle = Owner

The scope that owns effects and cleanups.

Payload

type Payload = Record<string, string>

What halo trigger <name> key=value ... sends. Hydration results arrive as { stdout, stderr, code }.