Crates.io | wasm_extra |
lib.rs | wasm_extra |
version | 0.1.6 |
source | src |
created_at | 2023-02-21 13:39:46.068475 |
updated_at | 2023-05-16 20:17:08.474987 |
description | Extra utilities for WASM. |
homepage | |
repository | https://github.com/JohnScience/wasm_extra |
max_upload_size | |
id | 790683 |
size | 27,392 |
The crate provides a number of extension traits for the web-sys
types.
One of the things that this crate offers is the add_event_listener_with_callback!
macro named after the ::web_sys::EventTarget::add_event_listener_with_callback()
function.
The macro is a bit more ergonomic to use and code with it is easier to mentally parse than the corresponding code without it.
In the expanded code, the event target (open_files_btn
) appears only on line
16, whereas in the macro it's the very first argument, which then followed by
the event name, then the "closure prologue", and - lastly - the closure itself.
"Closure prologue" is a stipulative term for the code that is executed before the closure itself. It's useful for preparing the closure's environment, for example, by cloning the variables before capturing.
In the code above it's empty but in the following example it's not:
In addition, in the code above the event target is captured by the closure. This requires special handling and is done with the ampersand before the event target's variable.
At the moment, there's no any semver guarantees. The crate is being inactively developed.