LEVIATHAN v962456e · 962456eee1

Standard Library

class DomEvent

A DOM event delivered to a handler, as a typed handle.

since 0.1.0-alpha.1wasm

Overview

The browser hands the program an event; DomEvent wraps it so a handler can read its type and, for form controls, the value of the element that received it. It is the item type of the stream returned by DomNode::events and the argument of the callback given to DomNode::on.

Examples

Reading the event a handler receives

DomNode button = Dom::create("button");
button.on("click", (e) => {
    console.writeln("got a ${e.type()} event");
});
button.click();
not run — runs only on the wasm target

Constructors

new

new(int handle)

Wrap a host event handle as a DomEvent.

The runtime creates these for you; there is rarely a reason to call this yourself.

Parameters

handle
The host handle of the event.

Fields

h

int h

The raw host handle of the event. Programs normally use handle() and never read this directly.

Methods

handle

handle() -> int

The raw host handle of the event.

Returns

The integer handle that identifies the event on the host side.

targetValue

@extern("eventTargetValue", "Str")
targetValue() -> string

The current value of the form control that received the event.

Returns

The value of the target element, or "" if it has none.

Examples

Reading a text box on input

DomNode field = Dom::create("input");
field.on("input", (e) => {
    console.writeln("typed: ${e.targetValue()}");
});
not run — runs only on the wasm target

type

@extern("eventType", "Str")
type() -> string

The kind of event, as the browser names it.

Returns

The event type, for example "click".

See also

  • DomNode — A handle to one node in the browser page.