aboutsummaryrefslogtreecommitdiff
path: root/src/app/components/hello/root.zig
blob: 6dafd9894f822c4ed971eced24b4520a765b0708 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
const std = @import("std");
const z = @import("z");

const Self = @This();

pub const component: z.Component = .{
    .name = "hello",
    .html = .parse(@embedFile("index.html")),
    .css = @embedFile("index.css"),
    .link = @This(),
};

element: *z.Object,
counter: usize,

pub fn init(self: *Self, element: *z.Object) void {
    self.element = element;
    self.counter = 0;
}

pub fn clicked(self: *Self, event: *z.Object) !void {
    var env: z.Env = .init(std.heap.wasm_allocator);
    defer env.deinit();

    self.counter += 1;

    const x = event.get(&env, "x");
    const y = event.get(&env, "y");

    std.log.info("clicked {} times at ({}, {})", .{
        self.counter,
        try x.await(&env, .uint),
        try y.await(&env, .uint),
    });
}