dioxus/packages/core/tests/lifecycle.rs

44 lines
934 B
Rust
Raw Normal View History

2021-10-22 05:16:39 +00:00
#![allow(unused, non_upper_case_globals)]
2021-10-22 05:16:39 +00:00
//! Tests for the lifecycle of components.
use dioxus::prelude::*;
use dioxus_core as dioxus;
2021-09-25 01:46:23 +00:00
use dioxus_core_macro::*;
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
mod test_logging;
const IS_LOGGING_ENABLED: bool = true;
2021-10-01 06:07:12 +00:00
type Shared<T> = Arc<Mutex<T>>;
#[test]
fn manual_diffing() {
2021-09-13 05:14:09 +00:00
test_logging::set_up_logging(IS_LOGGING_ENABLED);
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();
cx.render(rsx! { div { "{val}" } })
};
2021-10-01 06:07:12 +00:00
let value = Arc::new(Mutex::new("Hello"));
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";
let edits = dom.diff();
log::debug!("edits: {:?}", edits);
}