manual_edits.rs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*
  2. Example: Manual Edits
  3. It's possible to manually provide a stream of DomEdits to a Dioxus Renderer. All renderers are designed to accept a stream
  4. of DomEdits that abstract over a stack machine. This allows the VirtualDOM to exist entirely separately from the RealDOM,
  5. though features like NodeRefs and NativeEvents might not work properly everywhere.
  6. */
  7. use dioxus::core::*;
  8. use dioxus::prelude::*;
  9. fn main() {
  10. use DomEdit::*;
  11. let edits = vec![
  12. // create a container and push it onto the stack
  13. CreateElement { tag: "div", id: 0 },
  14. // create an element and push it onto the stack
  15. CreateElement { tag: "h1", id: 2 },
  16. // create a text node and push it onto the stack
  17. CreateTextNode {
  18. text: "hello world",
  19. id: 3,
  20. },
  21. // append the text node to the h1 element
  22. AppendChildren { many: 1 },
  23. // append the h1 element to the container
  24. AppendChildren { many: 1 },
  25. // append the container to the default render element ("dioxusroot" if used with default config)
  26. AppendChildren { many: 1 },
  27. ];
  28. dioxus_desktop::WebviewRenderer::run_with_edits(APP, (), |c| c, Some(edits)).expect("failed");
  29. }
  30. const APP: FC<()> = |cx, _props| {
  31. rsx!(cx, div {
  32. "some app"
  33. })
  34. };