diff options
| author | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-07 00:09:34 +0200 |
|---|---|---|
| committer | Nathan Reiner <nathan@nathanreiner.xyz> | 2026-10-07 00:09:34 +0200 |
| commit | 4e86e3e18e9b43e442a35361ac82b30dd6c0103a (patch) | |
| tree | c37d84000608386147b910dd41df5743e947fd93 /src/app | |
| parent | 12a02f161504b49a54243bed996df6b44e25b7b4 (diff) | |
wasm implement components
Diffstat (limited to 'src/app')
| -rw-r--r-- | src/app/components/hello/index.css | 0 | ||||
| -rw-r--r-- | src/app/components/hello/index.html | 0 | ||||
| -rw-r--r-- | src/app/components/hello/root.zig | 17 | ||||
| -rw-r--r-- | src/app/root.zig | 48 |
4 files changed, 22 insertions, 43 deletions
diff --git a/src/app/components/hello/index.css b/src/app/components/hello/index.css new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/app/components/hello/index.css diff --git a/src/app/components/hello/index.html b/src/app/components/hello/index.html new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/src/app/components/hello/index.html diff --git a/src/app/components/hello/root.zig b/src/app/components/hello/root.zig new file mode 100644 index 0000000..6f68550 --- /dev/null +++ b/src/app/components/hello/root.zig @@ -0,0 +1,17 @@ +const std = @import("std"); +const z = @import("z"); + +pub const component: z.Component = .{ + .name = "hello", + .html = .native( + .div, + .{ .onclick = "@clicked" }, + .content("click me"), + ), + .css = @embedFile("index.css"), + .link = @This(), +}; + +pub fn clicked() void { + z.log.js.debug("hi"); +} 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; } |