EventManager: add hasListener

Not sure if this should be in `EventTarget` or `EventManager`, here goes nothing.
This commit is contained in:
Halil Durak
2026-01-20 19:11:36 +03:00
parent 7c98a27c53
commit ffedcbc4e4

View File

@@ -203,6 +203,21 @@ pub fn dispatchWithFunction(self: *EventManager, target: *EventTarget, event: *E
try self.dispatchAll(list, target, event, &was_dispatched); try self.dispatchAll(list, target, event, &was_dispatched);
} }
/// Returns true if there's at least 1 listener for given `event_type`.
pub fn hasListener(self: *const EventManager, event_target: *const EventTarget, typ: []const u8) bool {
const list = self.lookup.get(@intFromPtr(event_target)) orelse return false;
var current_node = list.first;
while (current_node) |node| : (current_node = node.next) {
const listener: *const Listener = @alignCast(@fieldParentPtr("node", node));
if (listener.typ.eqlSlice(typ)) {
return true;
}
}
return false;
}
fn dispatchNode(self: *EventManager, target: *Node, event: *Event, was_handled: *bool) !void { fn dispatchNode(self: *EventManager, target: *Node, event: *Event, was_handled: *bool) !void {
const ShadowRoot = @import("webapi/ShadowRoot.zig"); const ShadowRoot = @import("webapi/ShadowRoot.zig");