mirror of
https://github.com/DioxusLabs/dioxus
synced 2024-11-15 00:47:09 +00:00
43 lines
934 B
Rust
43 lines
934 B
Rust
#![allow(unused, non_upper_case_globals)]
|
|
|
|
//! Tests for the lifecycle of components.
|
|
use dioxus::prelude::*;
|
|
use dioxus_core as dioxus;
|
|
use dioxus_core_macro::*;
|
|
use dioxus_html as dioxus_elements;
|
|
use std::sync::{Arc, Mutex};
|
|
|
|
mod test_logging;
|
|
|
|
const IS_LOGGING_ENABLED: bool = true;
|
|
type Shared<T> = Arc<Mutex<T>>;
|
|
|
|
#[test]
|
|
fn manual_diffing() {
|
|
test_logging::set_up_logging(IS_LOGGING_ENABLED);
|
|
|
|
struct AppProps {
|
|
value: Shared<&'static str>,
|
|
}
|
|
|
|
static App: FC<AppProps> = |(cx, props)| {
|
|
let val = props.value.lock().unwrap();
|
|
cx.render(rsx! { div { "{val}" } })
|
|
};
|
|
|
|
let value = Arc::new(Mutex::new("Hello"));
|
|
let mut dom = VirtualDom::new_with_props(
|
|
App,
|
|
AppProps {
|
|
value: value.clone(),
|
|
},
|
|
);
|
|
|
|
let _ = dom.rebuild();
|
|
|
|
*value.lock().unwrap() = "goodbye";
|
|
|
|
let edits = dom.diff();
|
|
|
|
log::debug!("edits: {:?}", edits);
|
|
}
|