2021-09-10 00:58:48 +00:00
|
|
|
//! Tests for the lifecycle of components.
|
2021-09-13 04:59:08 +00:00
|
|
|
|
|
|
|
use std::{cell::RefCell, rc::Rc};
|
|
|
|
|
|
|
|
use anyhow::{Context, Result};
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
use dioxus_core as dioxus;
|
|
|
|
use dioxus_html as dioxus_elements;
|
|
|
|
mod test_logging;
|
|
|
|
|
|
|
|
const IS_LOGGING_ENABLED: bool = true;
|
|
|
|
type Shared<T> = Rc<RefCell<T>>;
|
|
|
|
|
|
|
|
#[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
|
|
|
#[derive(PartialEq, Props)]
|
|
|
|
struct AppProps {
|
|
|
|
value: Shared<&'static str>,
|
|
|
|
}
|
|
|
|
|
2021-09-21 17:13:15 +00:00
|
|
|
static App: FC<AppProps> = |cx, props| {
|
|
|
|
let val = props.value.borrow();
|
2021-09-13 04:59:08 +00:00
|
|
|
cx.render(rsx! { div { "{val}" } })
|
|
|
|
};
|
|
|
|
|
2021-09-13 05:14:09 +00:00
|
|
|
let value = Rc::new(RefCell::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();
|
|
|
|
|
|
|
|
*value.borrow_mut() = "goodbye";
|
|
|
|
|
|
|
|
let edits = dom.diff();
|
|
|
|
|
|
|
|
log::debug!("edits: {:?}", edits);
|
|
|
|
}
|