gossamer/event_target

Types

An object that can receive events and have listeners for them.

See EventTarget on MDN.

pub type EventTarget
pub type ListenerOption {
  Capture(Bool)
  Once(Bool)
  Passive(Bool)
  Signal(abort_signal.AbortSignal)
}

Constructors

Values

pub fn add_event_listener(
  to target: EventTarget,
  on type_: String,
  run listener: fn(event.Event) -> a,
) -> Nil

Registers an event listener on the target for the given event type.

pub fn add_event_listener_with(
  to target: EventTarget,
  on type_: String,
  run listener: fn(event.Event) -> a,
  with options: List(ListenerOption),
) -> Nil

Registers an event listener on the target with additional options such as Once, Capture, Passive, or Signal.

pub fn dispatch_event(
  on target: EventTarget,
  event event: event.Event,
) -> Result(Bool, js_error.JsError)

Dispatches an event to the target, invoking any registered listeners. Returns whether prevent_default was not called by any listener. Returns an error if the event is already being dispatched.

pub fn new() -> EventTarget

Creates a new EventTarget.

pub fn remove_event_listener(
  from target: EventTarget,
  on type_: String,
  listener listener: fn(event.Event) -> a,
) -> Nil

Removes a previously registered event listener from the target. The listener must be the same function reference that was passed to add_event_listener.

pub fn remove_event_listener_with(
  from target: EventTarget,
  on type_: String,
  listener listener: fn(event.Event) -> a,
  with options: List(ListenerOption),
) -> Nil

Removes a previously registered event listener with the matching options.

Search Document