From 91d9b6992ac0ebee13704a3faefa8fd41a00075e Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Mon, 26 Oct 2026 09:23:55 +0100 Subject: zilch: dynamic element creation --- src/zilch/App/root.zig | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'src/zilch/App/root.zig') diff --git a/src/zilch/App/root.zig b/src/zilch/App/root.zig index a7700d9..01e2695 100644 --- a/src/zilch/App/root.zig +++ b/src/zilch/App/root.zig @@ -45,7 +45,6 @@ pub fn App(comptime options: Options) type { break :g gl; }, - Methods: type = enum(u16) {}, pub const init: @This() = .{}; @@ -56,21 +55,29 @@ pub fn App(comptime options: Options) type { } }; } else { - const components: []const Element = (comp: { + const components: []const Element, const registry: []const u8 = (comp: { var cs: []const Element = &.{}; + var registry: []const u8 = "const component_registry = {"; for (options.components) |component| { cs = cs ++ component.toElement(); + registry = registry ++ std.fmt.comptimePrint("{}: '{s}-{s}',", .{ + component.id, + component.namespace, + component.name, + }); } - break :comp cs; + registry = registry ++ "};"; + + break :comp .{ cs, registry }; }); const functions: []const u8 = func: { var buf: []const u8 = "ObjectStore.methods = {"; for (options.functions) |function| { - buf = buf ++ std.fmt.comptimePrint("{}: {s},", .{function.id, function.content}); + buf = buf ++ std.fmt.comptimePrint("{}: {s},", .{ function.id, function.content }); } buf = buf ++ "}"; @@ -111,6 +118,7 @@ pub fn App(comptime options: Options) type { "body", .{}, &[_]Element{ + .node("script", .{}, &.{.text(registry)}), } ++ components ++ options.body.elements, ), }), -- cgit v1.2.3-70-g09d2