import { type Signal } from "https://deno.land/x/effection@3.0.0-beta.3/lib/mod.ts";
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
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);
}
})