hydrate.rs 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. use dioxus_core::prelude::*;
  2. use dioxus_core_macro::*;
  3. use dioxus_html as dioxus_elements;
  4. use wasm_bindgen_test::wasm_bindgen_test;
  5. use web_sys::window;
  6. wasm_bindgen_test::wasm_bindgen_test_configure!(run_in_browser);
  7. #[test]
  8. fn makes_tree() {
  9. fn app(cx: Scope) -> Element {
  10. cx.render(rsx! {
  11. div {
  12. div {
  13. h1 {}
  14. }
  15. div {
  16. h2 {}
  17. }
  18. }
  19. })
  20. }
  21. let mut dom = VirtualDom::new(app);
  22. let muts = dom.rebuild();
  23. dbg!(muts.edits);
  24. }
  25. #[wasm_bindgen_test]
  26. fn rehydrates() {
  27. fn app(cx: Scope) -> Element {
  28. cx.render(rsx! {
  29. div {
  30. div {
  31. h1 { "h1" }
  32. }
  33. div {
  34. h2 { "h2" }
  35. }
  36. button {
  37. onclick: move |_| {
  38. println!("clicked");
  39. },
  40. "listener test"
  41. }
  42. false.then(|| rsx!{ "hello" })
  43. }
  44. })
  45. }
  46. let mut dom = VirtualDom::new(app);
  47. let _ = dom.rebuild();
  48. let out = dioxus_ssr::render_vdom_cfg(&dom, |c| c.pre_render(true));
  49. window()
  50. .unwrap()
  51. .document()
  52. .unwrap()
  53. .body()
  54. .unwrap()
  55. .set_inner_html(&format!("<div id='main'>{}</div>", out));
  56. dioxus_web::launch_cfg(app, |c| c.hydrate(true));
  57. }