@nickpaustian/signal
v0.1.0
Published
A small typed signal: subscribe, emit, priorities, re-entrant emits queued; and the SignalLike shape libraries code against so a host can supply its own
Maintainers
Readme
@nickpaustian/signal
A small typed signal, and the shape libraries code against.
import { Signal } from "@nickpaustian/signal"
const resized = new Signal<{ width: number; height: number }>()
const stop = resized.subscribe(({ width, height }) => console.log(width, height))
resized.emit({ width: 800, height: 600 })
stop()subscribe(listener, priority = 0)returns the unsubscribe; higher priorities run first.- An
emitmade from inside a listener is queued and delivered after the current one, so listeners never interleave. sizecounts listeners;clear()drops them all.
Libraries that use signals should import the type SignalLike<T> and take a createSignal factory so a host can supply its own implementation; nothing here checks instanceof, so two copies of the package coexist without harm.
