function / @typed/template

EventHandler.fromEffectOrEventHandler

Helper to ensure a value is an EventHandler.

If the input is already an EventHandler, it is returned as is. If it is an Effect, it is wrapped in an EventHandler that ignores the event argument.

Package version
1.0.0-beta.7
Category
Handler normalization
Since
1.0.0
Member of
EventHandler

Import

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

Access EventHandler.fromEffectOrEventHandler through the imported EventHandler export. Its declaration below describes the member.

This public exposure is a re-export. Its import path is supported; declaration documentation is shared with the other public exposures below.

Signatures

export declare function fromEffectOrEventHandler<Ev extends Event, E = never, R = never>(handler: Effect.Effect<unknown, E, R> | EventHandler<Ev, E, R>): EventHandler<Ev, E, R>;

Why

Template event parts accept either a reusable Effect or an event-aware handler without erasing either value’s error and service channels.

Ownership and lifetime

Conversion is inert. The renderer Scope owns the eventual listener and fiber.

Examples

import { Effect } from "effect"
import { fromEffectOrEventHandler } from "@typed/template/EventHandler"

const handler = fromEffectOrEventHandler(Effect.log("clicked"))

Other public imports

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

Source