Skip to content

Commit

Permalink
button
Browse files Browse the repository at this point in the history
  • Loading branch information
enghitalo committed Jan 13, 2024
1 parent b30ff7c commit 4ca2e00
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
5 changes: 5 additions & 0 deletions examples/wasm/change_color_by_id/change_color_by_id.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
<p id="description1">Some cool description</p>
<p id="description2">Some cool description</p>
<p id="description3">Some cool description</p>
<button id="myButton" onclick="click_callback()">Click here</button>

<script type="text/javascript">
var memory;
var click_callback;

function get_string(ptr, len) {
const buf = new Uint8Array(memory.buffer, ptr, len);
Expand Down Expand Up @@ -41,9 +43,12 @@
env: env,
}).then((res) => {
memory = res.instance.exports["memory"];

console.time("main.main");
res.instance.exports["main.main"]();
console.timeEnd("main.main");

click_callback = res.instance.exports["main.click_callback"];
});
</script>
</body>
Expand Down
4 changes: 4 additions & 0 deletions examples/wasm/change_color_by_id/change_color_by_id.wasm.v
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ pub fn main() {
change_color_by_id('description3', 'black')
}

pub fn click_callback() {
println('Hello from V')
}

fn change_color_by_id(id string, color string) {
JS.change_color_by_id(id.str, id.len, color.str, color.len)
}

0 comments on commit 4ca2e00

Please sign in to comment.