Feat: ensure mutabality is okay when not double-using the components
This commit is contained in:
1 parent
b3c96a5996
commit
305ff919ef
13 files changed
+120
-114
No files matched your search
@@ -3,42 +3,54 @@
|
||||
//!
|
||||
//! Renderers don't actually need to own the virtual dom (it's up to the implementer).
|
||||
|
||||
use crate::prelude::VirtualDom;
|
||||
use crate::virtual_dom::VirtualDom;
|
||||
use crate::{innerlude::Result, prelude::*};
|
||||
|
||||
pub struct DebugRenderer {
|
||||
vdom: VirtualDom,
|
||||
internal_dom: VirtualDom,
|
||||
}
|
||||
|
||||
impl DebugRenderer {
|
||||
pub fn new(vdom: VirtualDom) -> Self {
|
||||
Self { vdom }
|
||||
/// 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.
|
||||
pub fn new(root: FC<()>) -> Self {
|
||||
Self::new_with_props(root, ())
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) -> Result<(), ()> {
|
||||
/// 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`
|
||||
pub fn new_with_props<T: Properties + 'static>(root: FC<T>, root_props: T) -> Self {
|
||||
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 }
|
||||
}
|
||||
|
||||
pub fn step(&mut self, machine: &mut DiffMachine) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn log_dom(&self) {}
|
||||
}
|
||||
|
||||
#[cfg(old)]
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::prelude::*;
|
||||
use crate::scope::Properties;
|
||||
|
||||
#[test]
|
||||
fn ensure_creation() -> Result<(), ()> {
|
||||
#[derive(PartialEq)]
|
||||
struct Creation {}
|
||||
impl FC for Creation {
|
||||
fn render(ctx: Context, props: &Self) -> DomTree {
|
||||
ctx.render(html! { <div>"hello world" </div> })
|
||||
}
|
||||
}
|
||||
static Example: FC<()> = |ctx, props| {
|
||||
//
|
||||
ctx.render(html! { <div> "hello world" </div> })
|
||||
};
|
||||
|
||||
let mut dom = VirtualDom::new_with_props(Creation {});
|
||||
let mut dom = VirtualDom::new(Example);
|
||||
let machine = DiffMachine::new();
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user