2021-02-07 22:38:17 +00:00
|
|
|
//! Debug virtual doms!
|
|
|
|
//! This renderer comes built in with dioxus core and shows how to implement a basic renderer.
|
|
|
|
//!
|
|
|
|
//! Renderers don't actually need to own the virtual dom (it's up to the implementer).
|
|
|
|
|
2021-06-22 21:20:54 +00:00
|
|
|
use crate::innerlude::RealDom;
|
2021-03-14 00:11:06 +00:00
|
|
|
use crate::{events::EventTrigger, virtual_dom::VirtualDom};
|
2021-03-12 21:58:30 +00:00
|
|
|
use crate::{innerlude::Result, prelude::*};
|
2021-02-07 22:38:17 +00:00
|
|
|
|
2021-02-13 08:19:35 +00:00
|
|
|
pub struct DebugRenderer {
|
2021-03-12 21:58:30 +00:00
|
|
|
internal_dom: VirtualDom,
|
2021-02-07 22:38:17 +00:00
|
|
|
}
|
|
|
|
|
2021-02-13 08:19:35 +00:00
|
|
|
impl DebugRenderer {
|
2021-03-12 21:58:30 +00:00
|
|
|
/// Create a new instance of the Dioxus Virtual Dom with no properties for the root component.
|
|
|
|
///
|
|
|
|
/// This means that the root component must either consumes its own context, or statics are used to generate the page.
|
|
|
|
/// The root component can access things like routing in its context.
|
2021-06-23 05:44:48 +00:00
|
|
|
pub fn new(root: FC<()>) -> Self {
|
2021-03-12 21:58:30 +00:00
|
|
|
Self::new_with_props(root, ())
|
2021-02-07 22:38:17 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 21:58:30 +00:00
|
|
|
/// Create a new text-renderer instance from a functional component root.
|
|
|
|
/// Automatically progresses the creation of the VNode tree to completion.
|
|
|
|
///
|
|
|
|
/// A VDom is automatically created. If you want more granular control of the VDom, use `from_vdom`
|
2021-06-23 05:44:48 +00:00
|
|
|
pub fn new_with_props<T: Properties + 'static>(root: FC<T>, root_props: T) -> Self {
|
2021-03-12 21:58:30 +00:00
|
|
|
Self::from_vdom(VirtualDom::new_with_props(root, root_props))
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Create a new text renderer from an existing Virtual DOM.
|
|
|
|
pub fn from_vdom(dom: VirtualDom) -> Self {
|
|
|
|
// todo: initialize the event registry properly
|
|
|
|
Self { internal_dom: dom }
|
2021-02-07 22:38:17 +00:00
|
|
|
}
|
|
|
|
|
2021-03-14 00:11:06 +00:00
|
|
|
pub fn handle_event(&mut self, trigger: EventTrigger) -> Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-06-22 21:20:54 +00:00
|
|
|
pub fn step<Dom: RealDom>(&mut self, machine: &mut DiffMachine<Dom>) -> Result<()> {
|
2021-03-12 21:58:30 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2021-03-26 19:50:28 +00:00
|
|
|
|
|
|
|
// this does a "holy" compare - if something is missing in the rhs, it doesn't complain.
|
|
|
|
// it only complains if something shows up that's not in the lhs, *or* if a value is different.
|
|
|
|
// This lets you exclude various fields if you just want to drill in to a specific prop
|
|
|
|
// It leverages the internal diffing mechanism.
|
|
|
|
// If you have a list or "nth" child, you do need to list those children, but you don't need to
|
|
|
|
// fill in their children/attrs/etc
|
|
|
|
// Does not handle children or lifecycles and will always fail the test if they show up in the rhs
|
|
|
|
pub fn compare<'a, F>(&self, other: LazyNodes<'a, F>) -> Result<()>
|
|
|
|
where
|
|
|
|
F: for<'b> FnOnce(&'b NodeCtx<'a>) -> VNode<'a> + 'a,
|
|
|
|
{
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do a full compare - everything must match
|
|
|
|
// Ignores listeners and children components
|
|
|
|
pub fn compare_full<'a, F>(&self, other: LazyNodes<'a, F>) -> Result<()>
|
|
|
|
where
|
|
|
|
F: for<'b> FnOnce(&'b NodeCtx<'a>) -> VNode<'a> + 'a,
|
|
|
|
{
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn trigger_listener(&mut self, id: usize) -> Result<()> {
|
|
|
|
Ok(())
|
|
|
|
}
|
2021-06-22 21:20:54 +00:00
|
|
|
|
|
|
|
pub fn render_nodes<'a, F>(&self, other: LazyNodes<'a, F>) -> Result<()>
|
|
|
|
where
|
|
|
|
F: for<'b> FnOnce(&'b NodeCtx<'a>) -> VNode<'a> + 'a,
|
|
|
|
{
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub struct DebugVNodeSource {
|
|
|
|
bump: Bump,
|
|
|
|
}
|
|
|
|
impl DebugVNodeSource {
|
|
|
|
fn new() -> Self {
|
|
|
|
Self { bump: Bump::new() }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn render_nodes(&self) -> VNode {
|
|
|
|
// let ctx = NodeCtx
|
|
|
|
todo!()
|
|
|
|
}
|
2021-02-07 22:38:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::*;
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn ensure_creation() -> Result<(), ()> {
|
2021-06-01 22:33:15 +00:00
|
|
|
// static Example: FC<()> = |ctx| {
|
2021-03-18 22:54:26 +00:00
|
|
|
// //
|
|
|
|
// ctx.render(html! { <div> "hello world" </div> })
|
|
|
|
// };
|
2021-03-12 21:58:30 +00:00
|
|
|
|
2021-03-18 22:54:26 +00:00
|
|
|
// let mut dom = VirtualDom::new(Example);
|
|
|
|
// let machine = DiffMachine::new();
|
2021-02-12 04:03:01 +00:00
|
|
|
|
2021-02-07 22:38:17 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
}
|