Modernizing async example
This commit is contained in:
parent
ca4e9651ad
commit
85cddfabdb
|
@ -14,22 +14,24 @@ lto = true
|
|||
[lib]
|
||||
crate-type = ["cdylib"]
|
||||
|
||||
[workspace]
|
||||
|
||||
[dependencies]
|
||||
console_error_panic_hook = "0.1.5"
|
||||
dominator = "0.5.0"
|
||||
futures = "0.3.4"
|
||||
futures-signals = "0.3.0"
|
||||
wasm-bindgen-futures = "0.4.9"
|
||||
wasm-bindgen = "0.2.48"
|
||||
console_error_panic_hook = "0.1.6"
|
||||
dominator = "0.5.18"
|
||||
wasm-bindgen = "0.2.74"
|
||||
wasm-bindgen-futures = "0.4.24"
|
||||
futures = "0.3.15"
|
||||
futures-signals = "0.3.20"
|
||||
gloo-timers = { version = "0.2.1", features = ["futures"] }
|
||||
js-sys = "0.3.36"
|
||||
serde_json = "1.0.10"
|
||||
serde_derive = "1.0.27"
|
||||
serde = "1.0.27"
|
||||
lazy_static = "1.0.0"
|
||||
js-sys = "0.3.51"
|
||||
once_cell = "1.7.2"
|
||||
serde_json = "1.0.64"
|
||||
serde_derive = "1.0.126"
|
||||
serde = "1.0.126"
|
||||
|
||||
[dependencies.web-sys]
|
||||
version = "0.3.22"
|
||||
version = "0.3.51"
|
||||
features = [
|
||||
"console",
|
||||
"AbortController",
|
||||
|
|
|
@ -8,10 +8,11 @@
|
|||
"start": "rimraf dist/js && rollup --config --watch"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@wasm-tool/rollup-plugin-rust": "^1.0.0",
|
||||
"@wasm-tool/rollup-plugin-rust": "^1.0.6",
|
||||
"rimraf": "^3.0.2",
|
||||
"rollup": "^1.31.0",
|
||||
"rollup-plugin-livereload": "^1.2.0",
|
||||
"rollup-plugin-serve": "^1.0.1"
|
||||
"rollup": "^2.50.2",
|
||||
"rollup-plugin-livereload": "^2.0.0",
|
||||
"rollup-plugin-serve": "^1.1.0",
|
||||
"rollup-plugin-terser": "^7.0.2"
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import rust from "@wasm-tool/rollup-plugin-rust";
|
||||
import serve from "rollup-plugin-serve";
|
||||
import livereload from "rollup-plugin-livereload";
|
||||
import { terser } from "rollup-plugin-terser";
|
||||
|
||||
const is_watch = !!process.env.ROLLUP_WATCH;
|
||||
|
||||
|
@ -16,7 +17,6 @@ export default {
|
|||
plugins: [
|
||||
rust({
|
||||
serverPath: "js/",
|
||||
debug: false,
|
||||
}),
|
||||
|
||||
is_watch && serve({
|
||||
|
@ -25,5 +25,7 @@ export default {
|
|||
}),
|
||||
|
||||
is_watch && livereload("dist"),
|
||||
|
||||
!is_watch && terser(),
|
||||
],
|
||||
};
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
use std::rc::Rc;
|
||||
use std::sync::Arc;
|
||||
use wasm_bindgen::prelude::*;
|
||||
use gloo_timers::future::TimeoutFuture;
|
||||
use serde_derive::{Serialize, Deserialize};
|
||||
use futures_signals::signal::{Mutable, not};
|
||||
use dominator::{html, class, events, clone, with_node, Dom};
|
||||
use web_sys::HtmlInputElement;
|
||||
use lazy_static::lazy_static;
|
||||
use once_cell::sync::Lazy;
|
||||
use util::*;
|
||||
|
||||
mod util;
|
||||
|
@ -61,27 +61,25 @@ struct App {
|
|||
}
|
||||
|
||||
impl App {
|
||||
fn new(name: &str, user: Option<User>) -> Rc<Self> {
|
||||
Rc::new(Self {
|
||||
fn new(name: &str, user: Option<User>) -> Arc<Self> {
|
||||
Arc::new(Self {
|
||||
user: Mutable::new(user),
|
||||
input: Mutable::new(name.to_string()),
|
||||
loader: AsyncLoader::new(),
|
||||
})
|
||||
}
|
||||
|
||||
fn render(app: Rc<Self>) -> Dom {
|
||||
lazy_static! {
|
||||
static ref APP: String = class! {
|
||||
.style("white-space", "pre")
|
||||
};
|
||||
}
|
||||
fn render(app: Arc<Self>) -> Dom {
|
||||
static APP: Lazy<String> = Lazy::new(|| class! {
|
||||
.style("white-space", "pre")
|
||||
});
|
||||
|
||||
html!("div", {
|
||||
.class(&*APP)
|
||||
|
||||
.children(&mut [
|
||||
html!("input" => HtmlInputElement, {
|
||||
.property_signal("value", app.input.signal_cloned())
|
||||
.prop_signal("value", app.input.signal_cloned())
|
||||
|
||||
.with_node!(element => {
|
||||
.event(clone!(app => move |_: events::Input| {
|
||||
|
|
Loading…
Reference in New Issue