aboutsummaryrefslogtreecommitdiff
path: root/src/app
diff options
context:
space:
mode:
Diffstat (limited to 'src/app')
-rw-r--r--src/app/components/hello/index.css0
-rw-r--r--src/app/components/hello/index.html0
-rw-r--r--src/app/components/hello/root.zig17
-rw-r--r--src/app/root.zig48
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;
}