1
0

manual_edits.rs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 {
  14. tag: "div",
  15. root: 0,
  16. },
  17. // create an element and push it onto the stack
  18. CreateElement { tag: "h1", root: 2 },
  19. // create a text node and push it onto the stack
  20. CreateTextNode {
  21. text: "hello world",
  22. root: 3,
  23. },
  24. // append the text node to the h1 element
  25. AppendChildren { many: 1 },
  26. // append the h1 element to the container
  27. AppendChildren { many: 1 },
  28. // append the container to the default render element ("dioxusroot" if used with default config)
  29. AppendChildren { many: 1 },
  30. ];
  31. let app: Component = |cx| cx.render(rsx!(div { "some app" }));
  32. dioxus_desktop::launch_with_props(app, (), |c| c.with_edits(edits));
  33. }