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§
- Event
Binding - One
n.on(type, handler)binding. - Event
Data - 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
keydownhaskey+ modifiers, awheelhasdelta, aninput/changehasvalue, and so on); unused fields stay at their defaults.
Enums§
- Event
Handler - 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_typebubbles (fires bubble-phase handlers on ancestors after the target). Mirrors the DOM:focus/blur, pointerenter/leave, andscrolldo 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(). Impliesstop_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 honorprevent_default. - mark_
prevented_ click - Record that a click on
target(packed handle) had its default action cancelled viaprevent_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
priorbindings forward past a hot reload, and report the tokens that were dropped instead. - set_
current_ event - Publish
dataas the current event before invoking handlers. - set_
current_ target - Update the current event’s
current_targetas 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.