halo/signals
Functions
batch
function batch<T>(fn: () => T): TApplies 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): voidRuns 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 | nullThe current owner, to run code in it later with runWithOwner.
onCleanup
function onCleanup(fn: () => void): voidRegisters fn to run when the current component, effect or root is disposed.
root
function root<T>(fn: (dispose: () => void) => T): TRuns fn in a new ownership scope, disposed with its parent or by calling dispose.
runWithOwner
function runWithOwner<T>(owner: Owner | null, fn: () => T): TRuns 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): TReads signals without subscribing to them.
Interfaces
ExternalSignalOptions
interface ExternalSignalOptionsOptions for externalSignal().
| Property | Type | Description |
|---|---|---|
hydrate? | string | Shell command run on load (and so after every reload) to get the current state before the first event. |
initial? | T | |
parse? | (payload: Payload) => T | undefined | Turns a payload into the signal's value; returning undefined ignores the payload. |
Signal
function Signal(): TA writable reactive value.
| Property | Type | Description |
|---|---|---|
set() | (value: T): void | |
update() | (fn: (value: T) => T): void |
Types
Accessor
type Accessor<T> = () => TReads 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 = OwnerThe 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 }.