Create a new signal, optionally with an initial value and/or driver coroutine.
The value to return from value before the first emit.
null
by default.
If a driver coroutine is given, it is immediately run with go
passing this
as the only parameter. It can be used to associate
asynchronous logic with a new Signal.
Initial value
Driver coroutine
Private
#backPrivate
#callbacksPrivate
#emittedPrivate
#frontPrivate
#idPrivate
#valueStatic
Private
#counttrue
if this signal is in the process of emitting. Useful to determine
which signal emitted coming out of a first.
Automatically generated unique numerical IDs of the Signal
Private
#throwEmits a value through this signal, updating the stored value and notifying all listeners. Resumes any coroutines waiting on this signal and calls all subscribed callbacks.
Optional
value: T = undefinedValue to emit and store. If undefined, only triggers notifications without updating stored value
Creates a new signal that only emits values that pass the provided predicate function. Values that don't pass the predicate are filtered out and not emitted.
Predicate function to test each value
New signal that emits only filtered values
Subscribes a callback function to be called every time this signal emits.
Callback function to invoke on emission
Registers a generator to be resumed exactly once when this signal emits. Used internally by go when a coroutine yield this signal.
Generator to resume on emission
Static
Private
#generatorStatic
Private
#promiseStatic
eventCreates a signal that emits when a DOM event fires on the target element. The signal automatically cleans up its event listener when cancelled.
DOM element or event target to listen on
Event name to listen for (e.g., 'click', 'mousemove', 'keydown')
Optional
options: boolean | AddEventListenerOptions = trueEvent listener options
Signal that emits with event data when the event fires
Static
fromConverts various objects to signals for use in coroutines.
Signals pass through unchanged, Promises are wrapped in signals that emit when resolved.
Throws TypeError for generators/functions - use yield*
instead.
Object to convert to signal
Signal representation of the object
If object cannot be converted to signal
A signal represents a stream of events, a suspension point for coroutines, and a store of value. Signals can be awaited in coroutines using
yield
, emit values to notify listeners, store the most recently emitted value for reading, and accept callback subscriptions.