Skip to content
PACKAGES

fromEvent()

Wrap a DOM-style event target. Each event becomes DATA; deactivation removes the listener. External callbacks are source boundaries (D43), so no polling or operator-level async leaks in.

import { fromEvent } from "@graphrefly/ts/sources";
function fromEvent(
target: EventTargetLike,
type: string,
opts: FromEventOptions = {},
): Operator<never, T>
ParameterTypeDescription
targetEventTargetLikeEvent target implementing addEventListener and removeEventListener.
typestringEvent type to subscribe to.
optsFromEventOptionsOptional listener options and source options.

A source operator that emits each event as DATA.

import { graph } from "@graphrefly/ts/graph";
import { fromEvent } from "@graphrefly/ts/sources";
const clicks = graph().initNode(fromEvent<MouseEvent>(button, "click"), []);

packages/ts/src/graph/sources.ts