From 4e86e3e18e9b43e442a35361ac82b30dd6c0103a Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 7 Oct 2026 00:09:34 +0200 Subject: wasm implement components --- src/app/root.zig | 48 +++++------------------------------------------- 1 file changed, 5 insertions(+), 43 deletions(-) (limited to 'src/app/root.zig') diff --git a/src/app/root.zig b/src/app/root.zig index 6de9216..f587cfb 100644 --- a/src/app/root.zig +++ b/src/app/root.zig @@ -13,50 +13,12 @@ pub const app: z.App(.{ z.Object.global(.window), z.Object.global(.Object), }, + .components = &.{ + @import("components/hello/root.zig").component, + }, + .body = .native(.@"app-hello", .{}, .content("")), }) = .init; -fn run_wrapped() !void { - var env: z.Env = .init(std.heap.wasm_allocator); - defer env.deinit(); - - // Set and delete properties - _ = app.globals.window.set(&env, "my_prop", 45); - _ = app.globals.window.delete(&env, "my_prop"); - - // Get properties - const console = try app.globals.window.get(&env, "console").await(&env, .object); - const location = try app.globals.window.get(&env, "location").await(&env, .object); - - // Create new object - const obj = app.globals.Object.new(&env); - - // Get string, needs to be freed. - const hostname = try location.get(&env, "hostname").await(&env, .string); - defer std.heap.wasm_allocator.free(hostname); - - // Call method of an object - try console.call( - &env, - .log, - .{ - "hello, wasm!", - try obj.await(&env), - hostname, - }, - ).await(&env, .undefined); - - // Unlink Object from global store. - _ = env.free(console); -} - -fn run() callconv(.c) void { - run_wrapped() catch |e| { - std.log.err("{}", .{e}); - }; -} - comptime { - if (builtin.target.cpu.arch.isWasm()) { - @export(&run, .{ .name = "run" }); - } + _ = app; } -- cgit v1.2.3-70-g09d2