2021-01-15 01:56:28 +00:00
|
|
|
use std::future::Future;
|
|
|
|
|
2021-01-29 16:57:52 +00:00
|
|
|
use dioxus_core::{prelude::*, virtual_dom::Properties};
|
2021-01-16 04:25:29 +00:00
|
|
|
// use virtual_dom_rs::Closure;
|
2021-01-15 01:56:28 +00:00
|
|
|
|
2021-01-15 07:52:47 +00:00
|
|
|
// Stop-gap while developing
|
|
|
|
// Need to update the macro
|
|
|
|
type VirtualNode = VNode;
|
|
|
|
|
2021-01-15 01:56:28 +00:00
|
|
|
pub fn main() {
|
2021-01-19 13:47:08 +00:00
|
|
|
let dom = VirtualDom::new_with_props(root);
|
2021-01-16 06:30:48 +00:00
|
|
|
// let mut renderer = TextRenderer::new(dom);
|
|
|
|
// let output = renderer.render();
|
2021-01-15 01:56:28 +00:00
|
|
|
}
|
|
|
|
|
2021-01-29 16:57:52 +00:00
|
|
|
#[derive(PartialEq)]
|
2021-01-19 13:47:08 +00:00
|
|
|
struct Props {
|
|
|
|
name: String,
|
|
|
|
}
|
2021-01-29 16:57:52 +00:00
|
|
|
impl Properties for Props {}
|
2021-01-19 13:47:08 +00:00
|
|
|
|
|
|
|
fn root(ctx: &mut Context<Props>) -> VNode {
|
2021-01-15 01:56:28 +00:00
|
|
|
// the regular html syntax
|
|
|
|
|
|
|
|
// html! {
|
|
|
|
// <html>
|
|
|
|
// <Head />
|
|
|
|
// <Body />
|
|
|
|
// <Footer />
|
|
|
|
// </html>
|
|
|
|
// }
|
|
|
|
|
|
|
|
// or a manually crated vnode
|
|
|
|
{
|
2021-01-15 07:52:47 +00:00
|
|
|
let mut node_0 = VNode::element("div");
|
2021-01-16 04:25:29 +00:00
|
|
|
{
|
|
|
|
if let Some(ref mut element_node) = node_0.as_velement_mut() {
|
|
|
|
// element_node.attrs.insert("blah", "blah");
|
|
|
|
// element_node.children.extend(node_0.into_iter());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-15 01:56:28 +00:00
|
|
|
let mut node_1: IterableNodes = ("Hello world!").into();
|
2021-01-29 16:57:52 +00:00
|
|
|
|
2021-01-15 01:56:28 +00:00
|
|
|
node_1.first().insert_space_before_text();
|
2021-01-15 07:52:47 +00:00
|
|
|
let mut node_2 = VNode::element("button");
|
2021-01-16 04:25:29 +00:00
|
|
|
|
2021-01-29 16:57:52 +00:00
|
|
|
let node_3 = VNode::Component(VComponent::from_fn(
|
|
|
|
Head,
|
|
|
|
Props {
|
|
|
|
name: "".to_string(),
|
|
|
|
},
|
|
|
|
));
|
|
|
|
|
2021-01-15 01:56:28 +00:00
|
|
|
{
|
|
|
|
// let closure = Closure::wrap(Box::new(|_| {}) as Box<FnMut(_)>);
|
|
|
|
// let closure_rc = std::rc::Rc::new(closure);
|
|
|
|
// node_2
|
|
|
|
// .as_velement_mut()
|
|
|
|
// .expect("Not an element")
|
|
|
|
// .events
|
|
|
|
// .0
|
|
|
|
// .insert("onclick".to_string(), closure_rc);
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(ref mut element_node) = node_0.as_velement_mut() {
|
|
|
|
element_node.children.extend(node_1.into_iter());
|
|
|
|
}
|
|
|
|
if let Some(ref mut element_node) = node_0.as_velement_mut() {
|
|
|
|
element_node.children.extend(node_2.into_iter());
|
|
|
|
}
|
|
|
|
|
|
|
|
node_0
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-19 13:47:08 +00:00
|
|
|
fn Head(ctx: &mut Context<Props>) -> VNode {
|
2021-01-15 01:56:28 +00:00
|
|
|
html! {
|
2021-01-29 16:57:52 +00:00
|
|
|
<head> "Head Section" </head>
|
2021-01-15 01:56:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-19 13:47:08 +00:00
|
|
|
fn Body(ctx: &mut Context<Props>) -> VNode {
|
2021-01-15 01:56:28 +00:00
|
|
|
html! {
|
2021-01-29 16:57:52 +00:00
|
|
|
<body> {"Footer Section"}</body>
|
2021-01-15 01:56:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-19 13:47:08 +00:00
|
|
|
fn Footer(ctx: &mut Context<Props>) -> VNode {
|
|
|
|
let mut v = 10_i32;
|
|
|
|
format!("Is this the real life, or is this fantasy, caught in a landslide");
|
|
|
|
|
2021-01-15 01:56:28 +00:00
|
|
|
html! {
|
|
|
|
<div>
|
2021-01-19 13:47:08 +00:00
|
|
|
"Footer Section"
|
|
|
|
"Footer Section"
|
|
|
|
"Footer Section"
|
|
|
|
"Footer Section"
|
|
|
|
"Footer Section"
|
|
|
|
"Footer Section"
|
2021-01-15 01:56:28 +00:00
|
|
|
</div>
|
|
|
|
}
|
|
|
|
}
|