Feat: WIP

This commit is contained in:
Jonathan Kelley committed 2021-01-14 20:56:28 -05:00
1 parent cd20d3c168
commit ce34d0dfcd
13 files changed
+275 -18

No files matched your search

+5
View File
@@ -9,3 +9,8 @@ edition = "2018"
[dependencies]
generational-arena = "0.2.8"
typed-arena = "2.0.1"
virtual-dom-rs = { path = "../virtual-dom-rs" }
virtual-node = { path = "../virtual-node" }
html-macro = { path = "../html-macro" }
# web-sys = "0.3.46"
# js-sys = "0.3.46"
+75
View File
@@ -0,0 +1,75 @@
use std::future::Future;
use dioxus_core::{component::AnyContext, prelude::*};
use virtual_dom_rs::Closure;
pub fn main() {
let dom = VirtualDom::new(root);
let mut renderer = TextRenderer::new(dom);
let output = renderer.render();
}
fn root(ctx: &mut AnyContext) -> VirtualNode {
// the regular html syntax
// html! {
// <html>
// <Head />
// <Body />
// <Footer />
// </html>
// }
// or a manually crated vnode
{
let mut node_0 = VirtualNode::element("div");
let mut node_1: IterableNodes = ("Hello world!").into();
node_1.first().insert_space_before_text();
let mut node_2 = VirtualNode::element("button");
{
// 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());
}
VirtualNode
node_0
}
}
fn Head(ctx: &mut AnyContext) -> VirtualNode {
html! {
<head>
{"Head Section"}
</head>
}
}
fn Body(ctx: &mut AnyContext) -> VirtualNode {
html! {
<body>
{"Footer Section"}
</body>
}
}
fn Footer(ctx: &mut AnyContext) -> VirtualNode {
html! {
<div>
{"Footer Section"}
</div>
}
}
+91
View File
@@ -1 +1,92 @@
use html_macro::html;
use virtual_node::{IterableNodes, VElement, VirtualNode};
/// A re-export of everything to get macros working smoothly
pub mod prelude {
pub use crate::component::Context;
pub use crate::renderer::TextRenderer;
pub use crate::types::FC;
pub use crate::virtual_dom::VirtualDom;
pub use html_macro::html;
pub use virtual_node::{IterableNodes, VirtualNode};
}
pub mod virtual_dom {
use super::*;
pub struct VirtualDom {}
impl VirtualDom {
pub fn new(root: types::FC) -> Self {
Self {}
}
}
}
/// Virtual Node Support
pub mod nodes {
pub type VNode = virtual_node::VirtualNode;
// pub enum VNode {
// VText,
// VElement,
// VComponent,
// }
}
/// Example on how to craft a renderer that interacts with the VirtualDom
pub mod renderer {
use crate::virtual_dom::VirtualDom;
use super::*;
/// Renders a full Dioxus app to a String
///
pub struct TextRenderer {}
impl TextRenderer {
/// Create a new Text Renderer which renders the VirtualDom to a string
pub fn new(dom: VirtualDom) -> Self {
Self {}
}
pub fn render(&mut self) -> String {
todo!()
}
}
}
pub mod component {
/// A wrapper around component contexts that hides component property types
pub struct AnyContext {}
pub struct Context<T> {
_props: std::marker::PhantomData<T>,
}
pub trait Properties {}
impl Properties for () {}
fn test() {}
}
/// Utility types that wrap internals
pub mod types {
use super::*;
use component::{AnyContext, Context};
use nodes::VNode;
pub type FC = fn(&mut AnyContext) -> VNode;
}
// #[cg(test)]
mod integration_tests {
use crate::prelude::*;
/// Test a basic usage of a virtual dom + text renderer combo
#[test]
fn simple_integration() {
let dom = VirtualDom::new(|_| html! { <div>Hello World!</div> });
let mut renderer = TextRenderer::new(dom);
let output = renderer.render();
}
}