2021-09-24 06:37:51 +00:00
|
|
|
/*
|
|
|
|
Example: Manual Edits
|
|
|
|
|
|
|
|
It's possible to manually provide a stream of DomEdits to a Dioxus Renderer. All renderers are designed to accept a stream
|
|
|
|
of DomEdits that abstract over a stack machine. This allows the VirtualDOM to exist entirely separately from the RealDOM,
|
|
|
|
though features like NodeRefs and NativeEvents might not work properly everywhere.
|
|
|
|
*/
|
|
|
|
|
|
|
|
use dioxus::core::*;
|
|
|
|
use dioxus::prelude::*;
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
use DomEdit::*;
|
|
|
|
|
|
|
|
let edits = vec![
|
|
|
|
// create a container and push it onto the stack
|
2021-10-05 07:37:15 +00:00
|
|
|
CreateElement {
|
|
|
|
tag: "div",
|
|
|
|
root: 0,
|
|
|
|
},
|
2021-09-24 06:37:51 +00:00
|
|
|
// create an element and push it onto the stack
|
2021-10-05 07:37:15 +00:00
|
|
|
CreateElement { tag: "h1", root: 2 },
|
2021-09-24 06:37:51 +00:00
|
|
|
// create a text node and push it onto the stack
|
|
|
|
CreateTextNode {
|
|
|
|
text: "hello world",
|
2021-10-05 07:37:15 +00:00
|
|
|
root: 3,
|
2021-09-24 06:37:51 +00:00
|
|
|
},
|
|
|
|
// append the text node to the h1 element
|
|
|
|
AppendChildren { many: 1 },
|
|
|
|
// append the h1 element to the container
|
|
|
|
AppendChildren { many: 1 },
|
|
|
|
// append the container to the default render element ("dioxusroot" if used with default config)
|
|
|
|
AppendChildren { many: 1 },
|
|
|
|
];
|
|
|
|
|
2021-12-29 04:48:25 +00:00
|
|
|
let app: Component = |cx| rsx!(cx, div { "some app" });
|
2021-09-24 06:37:51 +00:00
|
|
|
|
2021-12-25 22:18:05 +00:00
|
|
|
dioxus_desktop::run(app, (), |c| c.with_edits(edits));
|
|
|
|
}
|