2021-10-22 05:16:39 +00:00
|
|
|
#![allow(unused, non_upper_case_globals)]
|
2021-09-13 04:59:08 +00:00
|
|
|
|
2021-10-22 05:16:39 +00:00
|
|
|
//! Tests for the lifecycle of components.
|
2021-09-13 04:59:08 +00:00
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_core as dioxus;
|
2021-09-25 01:46:23 +00:00
|
|
|
use dioxus_core_macro::*;
|
2021-09-13 04:59:08 +00:00
|
|
|
use dioxus_html as dioxus_elements;
|
2021-10-01 06:07:12 +00:00
|
|
|
use std::sync::{Arc, Mutex};
|
2021-09-25 01:46:23 +00:00
|
|
|
|
2021-09-13 04:59:08 +00:00
|
|
|
mod test_logging;
|
|
|
|
|
|
|
|
const IS_LOGGING_ENABLED: bool = true;
|
2021-10-01 06:07:12 +00:00
|
|
|
type Shared<T> = Arc<Mutex<T>>;
|
2021-09-13 04:59:08 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn manual_diffing() {
|
2021-09-13 05:14:09 +00:00
|
|
|
test_logging::set_up_logging(IS_LOGGING_ENABLED);
|
|
|
|
|
2021-09-13 04:59:08 +00:00
|
|
|
struct AppProps {
|
|
|
|
value: Shared<&'static str>,
|
|
|
|
}
|
|
|
|
|
2021-10-16 21:37:28 +00:00
|
|
|
static App: FC<AppProps> = |(cx, props)| {
|
2021-10-01 06:07:12 +00:00
|
|
|
let val = props.value.lock().unwrap();
|
2021-09-13 04:59:08 +00:00
|
|
|
cx.render(rsx! { div { "{val}" } })
|
|
|
|
};
|
|
|
|
|
2021-10-01 06:07:12 +00:00
|
|
|
let value = Arc::new(Mutex::new("Hello"));
|
2021-09-13 04:59:08 +00:00
|
|
|
let mut dom = VirtualDom::new_with_props(
|
|
|
|
App,
|
|
|
|
AppProps {
|
|
|
|
value: value.clone(),
|
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
let _ = dom.rebuild();
|
|
|
|
|
2021-10-01 06:07:12 +00:00
|
|
|
*value.lock().unwrap() = "goodbye";
|
2021-09-13 04:59:08 +00:00
|
|
|
|
|
|
|
let edits = dom.diff();
|
|
|
|
|
|
|
|
log::debug!("edits: {:?}", edits);
|
|
|
|
}
|