function / @typed/template

makeEventSource

Creates a new EventSource.

The created EventSource can efficiently manage multiple event listeners, grouping them by event type and handling setup/teardown lifecycles.

Package version
1.0.0-beta.7
Category
Delegated event sources
Since
1.0.0

Import

import { makeEventSource } from "@typed/template";

Signatures

export declare function makeEventSource(): EventSource;

Why

The source is a small renderer-local registry that supports delegated listeners without requiring a component runtime.

Ownership and lifetime

Construction allocates only the in-memory registry. Each setup call ties attached native listeners and forked handler Effects to the supplied Scope; returned per-handler disposables remain independently usable.

Examples

import { Effect, Scope } from "effect"
import { makeEventSource } from "@typed/template/EventSource"
import * as EventHandler from "@typed/template/EventHandler"

const program = Effect.scoped(Effect.gen(function* () {
  const eventSource = makeEventSource()
  const element = document.createElement("div")

  // Add multiple event listeners
  eventSource.addEventListener(element, "click", EventHandler.make(() => console.log("clicked")))
  eventSource.addEventListener(element, "mouseover", EventHandler.make(() => console.log("hovered")))

  // Setup all listeners
  yield* eventSource.setup(element, yield* Scope.Scope)
}))

Other public imports

These import paths expose the same declaration. Each page retains its own public name and signature.

Source