forked from yewstack/yew
-
Notifications
You must be signed in to change notification settings - Fork 0
/
layout.rs
80 lines (65 loc) · 1.87 KB
/
layout.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#![cfg(target_arch = "wasm32")]
mod common;
wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
use std::time::Duration;
use common::obtain_result;
use wasm_bindgen_futures::spawn_local;
use wasm_bindgen_test::*;
use yew::platform::time::sleep;
use yew::prelude::*;
#[wasm_bindgen_test]
async fn change_nested_after_append() {
#[function_component]
fn Nested() -> Html {
let delayed_trigger = use_state(|| true);
{
let delayed_trigger = delayed_trigger.clone();
use_effect_with_deps(
move |_| {
spawn_local(async move {
sleep(Duration::from_millis(50)).await;
delayed_trigger.set(false);
});
|| {}
},
(),
);
}
if *delayed_trigger {
html! { <div>{"failure"}</div> }
} else {
html! { <><i></i><span id="result">{"success"}</span></> }
}
}
#[function_component]
fn Top() -> Html {
html! { <Nested /> }
}
#[function_component]
fn App() -> Html {
let show_bottom = use_state_eq(|| false);
{
let show_bottom = show_bottom.clone();
use_effect_with_deps(
move |_| {
show_bottom.set(true);
|| {}
},
(),
);
}
html! {
<>
<Top />
if *show_bottom {
<div>{"<div>Bottom</div>"}</div>
}
</>
}
}
yew::Renderer::<App>::with_root(gloo_utils::document().get_element_by_id("output").unwrap())
.render();
sleep(Duration::from_millis(100)).await;
let result = obtain_result();
assert_eq!(result.as_str(), "success");
}