dioxus/examples/manual_edits.rs
2021-10-04 10:22:20 -04:00

40 lines
1.3 KiB
Rust

/*
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
CreateElement { tag: "div", id: 0 },
// create an element and push it onto the stack
CreateElement { tag: "h1", id: 2 },
// create a text node and push it onto the stack
CreateTextNode {
text: "hello world",
id: 3,
},
// 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 },
];
dioxus_desktop::run(APP, (), |c| c.with_edits(edits)).unwrap();
}
const APP: FC<()> = |cx, _props| {
rsx!(cx, div {
"some app"
})
};