📦 gloo/ ranile
A modular toolkit for building fast, reliable Web applications and libraries with Rust and WASM
Открыть на GitHub ↗обновлён 2д назад
Звёзды
★ 2.0k
Форки
165
За неделю
—
За месяц
—
Рост %
—
Язык
Rust
Установка и запуск
Example
This example uses gloo::events for adding event listeners and gloo::timers
for creating timeouts. It creates a <button> element and adds a "click" event
listener to it. Whenever the button is clicked, it starts a one second timeout,
which sets the button's text content to "Hello from one second ago!".
use gloo::{events::EventListener, timers::callback::Timeout};
use wasm_bindgen::prelude::*;
pub struct DelayedHelloButton {
button: web_sys::Element,
on_click: events::EventListener,
}
impl DelayedHelloButton {
pub fn new(document: &web_sys::Document) -> Result<DelayedHelloButton, JsValue> {
// Create a `<button>` element.
let button = document.create_element("button")?;
// Listen to "click" events on the button.
let button2 = button.clone();
let on_click = EventListener::new(&button, "click", move |_event| {
// After a one second timeout, update the button's text content.
let button3 = button2.clone();
Timeout::new(1_000, move || {
button3.set_text_content(Some("Hello from one second ago!"));
})
.forget();
});
Ok(DelayedHelloButton { button, on_click })
}
}
Из README репозитория · полный README на GitHub
Категории
Теги
rustwasmwebwebassembly