-
-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
40 additions
and
92 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,47 @@ | ||
#![allow(non_snake_case)] | ||
use dioxus::prelude::dioxus_core::NoOpMutations; | ||
use freya::prelude::*; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
fn app() -> Element { | ||
rsx! { | ||
Spammer {} | ||
Spammer {} | ||
Spammer {} | ||
Spammer {} | ||
} | ||
} | ||
#![cfg_attr( | ||
all(not(debug_assertions), target_os = "windows"), | ||
windows_subsystem = "windows" | ||
)] | ||
|
||
fn Spammer() -> Element { | ||
let mut count = use_signal(|| 0); | ||
use freya::prelude::*; | ||
|
||
use_hook(|| { | ||
spawn(async move { | ||
loop { | ||
tokio::time::sleep(std::time::Duration::from_nanos(1)).await; | ||
let val = *count.peek_unchecked(); | ||
if val == 70 { | ||
count.set(0); | ||
} else { | ||
count.set(val + 1); | ||
} | ||
} | ||
}) | ||
}); | ||
fn main() { | ||
launch_with_props(app, "Counter", (400.0, 350.0)); | ||
} | ||
|
||
rsx! { | ||
for el in 0..*count.read() { | ||
// To avoid the leak simply replace this by `div {` | ||
Comp { | ||
key: "{el}", | ||
} | ||
fn app() -> Element { | ||
let mut count = use_signal(|| 0); | ||
|
||
rsx!( | ||
rect { | ||
height: "50%", | ||
width: "100%", | ||
main_align: "center", | ||
cross_align: "center", | ||
background: "rgb(0, 119, 182)", | ||
color: "white", | ||
shadow: "0 4 20 5 rgb(0, 0, 0, 80)", | ||
label { | ||
font_size: "75", | ||
font_weight: "bold", | ||
"{count}" | ||
} | ||
} | ||
} | ||
|
||
#[component] | ||
fn Comp() -> Element { | ||
rsx!(rect {}) | ||
} | ||
|
||
// create the vdom, the real_dom, and the binding layer between them | ||
let mut vdom = VirtualDom::new(app); | ||
|
||
vdom.rebuild(&mut NoOpMutations); | ||
|
||
// we need to run the vdom in a async runtime | ||
tokio::runtime::Builder::new_current_thread() | ||
.enable_all() | ||
.build()? | ||
.block_on(async { | ||
loop { | ||
// wait for the vdom to update | ||
vdom.wait_for_work().await; | ||
|
||
// get the mutations from the vdom | ||
vdom.render_immediate(&mut NoOpMutations); | ||
rect { | ||
height: "50%", | ||
width: "100%", | ||
main_align: "center", | ||
cross_align: "center", | ||
direction: "horizontal", | ||
spacing: "8", | ||
Button { | ||
onpress: move |_| count += 1, | ||
label { "Increase" } | ||
} | ||
Button { | ||
onpress: move |_| count -= 1, | ||
label { "Decrease" } | ||
} | ||
}) | ||
} | ||
) | ||
} |