Potentially outdated documentation
You're reading API reference for version 3.0.3. The latest stable release is version 3.1.0.
interface Signal
thefrontside/effectioninterface Signal<T, TClose> extends Stream<T, TClose>
Convert plain JavaScript function calls into a Stream that can be consumed within an operation. If no operation is subscribed to a signal's stream, then sending messages to it is a no-op.
Signals are particularly suited to be installed as event listeners.
Examples
Example 1
import { createSignal, each } from "effection";
export function* logClicks(function*(button) {
let clicks = createSignal<MouseEvent>();
button.addEventListener("click", clicks.send);
try {
for (let click of yield* each(clicks)) {
console.log(`click:`, click);
yield* each.next();
}
} finally {
button.removeEventListener("click", clicks.send);
}
})
Type Parameters
T
- type of each event sent by this signal
TClose
- type of the final event sent by this signal
Methods
- send(value: T): void
Send a value to all the consumers of this signal.
- close(value: TClose): void
Send the final value of this signal to all its consumers.