dead-code.rs
2 KB
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
async fn logic( mut rx_logic: broadcast::Receiver<AppLogic>
, tx_view: broadcast::Sender<AppView>
, mut rx_dom: broadcast::Receiver<Dom> ) {
let mut clicks = 0u32;
let dom = rx_dom.next().await.unwrap();
while let Some(msg) = rx_logic.next().await {
if let Either::Left(dom_js) = dom.inner_read() {
/*
* Here we can get the whole dom element with all sub elements and
* text data.
* Needed to get the contenteditable dom element content.
*/
let text = dom_js
. to_owned()
. dyn_into::<Node>().unwrap()
. first_child().unwrap()
. first_child().unwrap();
console::log_1(text.as_ref());
}
match msg {
AppLogic::Click => {
clicks += 1;
tx_view.broadcast(AppView::Clicked(clicks)).await.unwrap();
},
_ => ()
}
}
}
fn view( tx_logic: broadcast::Sender<AppLogic>
, rx_view: broadcast::Receiver<AppView>
, tx_dom: broadcast::Sender<Dom>
) -> ViewBuilder<Dom> {
builder! {
<div style:float="left"
style:padding="1em"
style:border_radius=".5em"
style:border="1px solid #ddd"
style:background="#f7f7f7"
style:cursor="pointer"
on:click=tx_logic.sink().contra_map(|_| AppLogic::Click)
capture:view=tx_dom.sink()>
<p>
{(
"Hello from mogwai!",
rx_view.to_owned().map(|msg| {
match msg {
AppView::Clicked(1) =>
format!("Caught 1 click, click again 😀"),
AppView::Clicked(n) =>
format!("Caught {} clicks", n),
}
})
)}
</p>
</div>
}
}