Skip to main content

Module event

Module event 

Source
Expand description

Host-neutral event object, binding registry, and propagation driver (phase 4): n.on(type, handler) / off(), the current-event cell, and the capture -> target -> bubble dispatch. Host-neutral event object, binding registry, and propagation driver for the dynamic DOM API (phase 4).

n.on("click", handler) binds a handler to a node for an event type and returns an off token; off() unbinds. Bindings live in a process-global registry keyed by token so the generic dispatcher (and the C-ABI, which has no script host) share one source of truth. The handler itself is either a closure held by the active crate::ScriptHost (keyed by the same token) or a native Rust callback (the C-ABI / SDK path).

During dispatch the driver publishes the event into a process-global current-event cell; a handler reads target / position / key / modifiers / button / delta / value from it and mutates its prevent_default / stop_propagation / stop_immediate_propagation flags through the free functions here. A host may wrap those in a registered Event handle or call them procedurally, as the C-ABI does.

Propagation follows the DOM contract: capture from the root down to the target, dispatch at the target, then bubble back up (for events that bubble). stop_propagation halts movement to the next node after the current node’s handlers finish; stop_immediate_propagation also halts the remaining handlers on the current node.

Structs§

EventBinding
One n.on(type, handler) binding.
EventData
The full event payload delivered to a handler. Positional / key / button / delta / value fields carry meaning only for the event types that produce them (a keydown has key + modifiers, a wheel has delta, an input / change has value, and so on); unused fields stay at their defaults.

Enums§

EventHandler
How a bound handler is invoked at dispatch time.

Functions§

clear_all_bindings
Drop all bindings (mainly for test isolation).
clear_host_bindings
Drop every host-closure binding. Called on host reset, and on hot reload before the script re-runs and re-binds.
clear_prevented_clicks
Reset the per-tick prevented-click set. The dispatcher calls this before processing a tick’s events.
current_event
Read the current event (cheap clone).
dispatch
Drive a full capture -> target -> bubble dispatch for data.
event_bubbles
Whether event_type bubbles (fires bubble-phase handlers on ancestors after the target). Mirrors the DOM: focus / blur, pointer enter / leave, and scroll do not bubble; everything else does.
event_button
ev.button().
event_current_target
ev.current_target().
event_delta
ev.delta() as (x, y).
event_key
ev.key().
event_modifiers
ev.modifiers() as (shift, ctrl, alt, super).
event_position_client
Client position (x, y) (window coordinates).
event_position_local
Local position (x, y) (relative to the target).
event_prevent_default
ev.prevent_default().
event_stop_immediate_propagation
ev.stop_immediate_propagation(). Implies stop_propagation.
event_stop_propagation
ev.stop_propagation().
event_target
ev.target().
event_type
ev.type().
event_value
ev.value().
has_bindings_for
Whether any binding exists for event_type (fast dispatch gate).
is_click_default_prevented
Whether a click on target (packed handle) was default-prevented this tick. The anchor-navigation executor consults this to honor prevent_default.
mark_prevented_click
Record that a click on target (packed handle) had its default action cancelled via prevent_default.
mint_event_token
Mint a fresh, process-unique bind / off token (always >= 1).
register_host_binding
Register a host-closure binding (token, node, type, capture). The host holds the closure itself keyed by token.
register_native_binding
Register a native-callback binding (the C-ABI / SDK path). Returns the token for the caller to hand back as the off token.
restore_host_bindings
Carry prior bindings forward past a hot reload, and report the tokens that were dropped instead.
set_current_event
Publish data as the current event before invoking handlers.
set_current_target
Update the current event’s current_target as the driver moves along the propagation path.
take_host_bindings
Remove every host-closure binding and return it, in registration order.
unregister_binding
Remove the binding for token, returning it when present.