GraphReFlyTS

API Reference

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

import { fromEvent } from "@graphrefly/ts/sources";

Signature

function fromEvent(
	target: EventTargetLike,
	type: string,
	opts: FromEventOptions = {},
): Operator<never, T>

Parameters

ParameterTypeDescription
targetEventTargetLikeEvent target implementing addEventListener and removeEventListener.
typestringEvent type to subscribe to.
optsFromEventOptionsOptional listener options and source options.

Returns

A source operator that emits each event as DATA.

Example

import { graph } from "@graphrefly/ts/graph";
import { fromEvent } from "@graphrefly/ts/sources";

const clicks = graph().initNode(fromEvent<MouseEvent>(button, "click"), []);

Source

packages/ts/src/graph/sources.ts