aboutsummaryrefslogtreecommitdiff
path: root/src/zilch/App/root.zig
diff options
context:
space:
mode:
authorNathan Reiner <nathan@nathanreiner.xyz>2026-10-15 11:25:14 +0200
committerNathan Reiner <nathan@nathanreiner.xyz>2026-10-15 11:25:14 +0200
commita1dc55be6e695a1c04e5e9e0f1ce7406a5dd3dff (patch)
tree46e78cce4fcc9ec7f04b3ae69bf53d9a81710dbe /src/zilch/App/root.zig
parent0b2af471b6d5dfc4eaf53639102c1b854bbb324b (diff)
add function struct to register js functions dynamically
Diffstat (limited to 'src/zilch/App/root.zig')
-rw-r--r--src/zilch/App/root.zig25
1 files changed, 21 insertions, 4 deletions
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 = "";