From a1dc55be6e695a1c04e5e9e0f1ce7406a5dd3dff Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Thu, 15 Oct 2026 11:25:14 +0200 Subject: add function struct to register js functions dynamically --- src/zilch/App/root.zig | 25 +++++++++++++++++++++---- 1 file changed, 21 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 52cbfc2..94f311b 100644 --- a/src/zilch/App/root.zig +++ b/src/zilch/App/root.zig @@ -1,12 +1,15 @@ const builtin = @import("builtin"); const std = @import("std"); -const Element = @import("../root.zig").html.Element; -const Document = @import("../root.zig").html.Document; -const Fragment = @import("../root.zig").html.Fragment; -const Component = @import("../root.zig").Component; +const mod = @import("../root.zig"); +const Element = mod.html.Element; +const Document = mod.html.Document; +const Fragment = mod.html.Fragment; +const Component = mod.Component; +const Env = mod.Env; pub const Options = struct { name: []const u8, + functions: []const Env.Function, globals: []const Global, components: []const Component, body: Fragment, @@ -41,6 +44,7 @@ pub fn App(comptime options: Options) type { break :g gl; }, + Methods: type = enum(u16) {}, pub const init: @This() = .{}; @@ -61,6 +65,18 @@ pub fn App(comptime options: Options) type { break :comp cs; }); + 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 ++ "}"; + + break :func buf; + }; + return struct { const node: Document = .{ .root = .node("html", .{}, &.{ @@ -73,6 +89,7 @@ pub fn App(comptime options: Options) type { .node("style", .{}, &.{.text(options.theme)}), .node("script", .{}, &.{.text(@embedFile("symbols.js"))}), .node("script", .{}, &.{.text(@embedFile("object-store.js"))}), + .node("script", .{}, &.{.text(functions)}), .node("script", .{}, &.{.text(@embedFile("main.js"))}), .node("script", .{}, &.{.text(reg: { var register_code: []const u8 = ""; -- cgit v1.2.3-70-g09d2