Last active
October 30, 2018 00:57
-
-
Save rippinrobr/bc3d822cc07d93b619b8352179593a54 to your computer and use it in GitHub Desktop.
The index.js file for my rust-wasm cookbok blog series - handling click events
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import * as wasm from "wasmcookbook"; | |
// setup the listener to call the rust function | |
document.getElementById("btn-js-click").addEventListener('click', wasm.js_click_event_handler); | |
// This struct that is being created is used | |
// to pass the ids of the HTML elements that | |
// the code interacts with. I want to avoid | |
// hard-coding the ids in the rust code, so I | |
// decided to do it in JS | |
var elemIds = wasm.EvtElements.new( | |
"btn-rs-click", | |
"btn-handler-space" | |
); | |
// the init function is used to call the | |
// event specific init functions on the | |
// rust side of things, wiring up the ids | |
// with the handlers | |
wasm.init(elemIds); | |
// the delete button that clears out the text that is added when the Rust Click button is clicked | |
document.getElementById("btn-del-click").addEventListener('click', () => {document.getElementById("btn-handler-space").innerText = "";}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment