aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-10-09 07:54:00 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-10-09 07:54:00 +0200
commit756957187e7a6d7c0cca932af186d1210ab4ace3 (patch)
tree0246bcbf7eb9148e5c165f4edaba873a17fc03dd /src
parent536bb55ce1d5bb23d642aa90a085548272eefba0 (diff)
cleanup
Diffstat (limited to 'src')
-rw-r--r--src/z/Component.zig31
1 files changed, 12 insertions, 19 deletions
diff --git a/src/z/Component.zig b/src/z/Component.zig
index 87001c2..11ab415 100644
--- a/src/z/Component.zig
+++ b/src/z/Component.zig
@@ -17,10 +17,15 @@ fn handlerNeedsEvent(func: anytype) bool {
return @typeInfo(T).@"fn".params.len == 2;
}
-fn handlerNeedsErrorHandling(func: anytype) bool {
- const T = @TypeOf(func);
- const ret_info = @typeInfo(@typeInfo(T).@"fn".return_type orelse void);
- return ret_info == .error_union;
+fn wrapHandler(ret: anytype) void {
+ const T = @TypeOf(ret);
+ const ret_info = @typeInfo(T);
+
+ if (ret_info == .error_union) {
+ ret catch |err| {
+ std.log.err("error: {}", .{err});
+ };
+ }
}
fn exportFromHtml(self: *const Self, element: Element) void {
@@ -34,25 +39,13 @@ fn exportFromHtml(self: *const Self, element: Element) void {
if (handlerNeedsEvent(event_handler))
struct {
pub fn func(obj: *self.link, event: *Object) callconv(.c) void {
- if (comptime handlerNeedsErrorHandling(event_handler)) {
- event_handler(obj, event) catch |err| {
- std.log.err("error: {}", .{err});
- };
- } else {
- event_handler(obj, event);
- }
+ wrapHandler(event_handler(obj, event));
}
}.func
else
struct {
pub fn func(obj: *self.link) callconv(.c) void {
- if (comptime handlerNeedsErrorHandling(event_handler)) {
- event_handler(obj) catch |err| {
- std.log.err("error: {}", .{err});
- };
- } else {
- event_handler(obj);
- }
+ wrapHandler(event_handler(obj));
}
}.func;
@@ -83,7 +76,7 @@ pub fn exportLinks(self: *const Self) void {
const init = struct {
pub fn init(element: *Object) callconv(.c) ?*self.link {
const obj = std.heap.wasm_allocator.create(self.link) catch return null;
- obj.init(element);
+ wrapHandler(obj.init(element));
return obj;
}
}.init;