wip: add test_dom

This commit is contained in:
Jonathan Kelley committed 2021-09-01 23:57:34 -04:00
1 parent 44b4384961
commit a652090dc5
12 files changed
+192 -97

No files matched your search

+1 -1
View File
@@ -136,7 +136,7 @@ impl<'a> SavedDiffWork<'a> {
}
impl<'bump> DiffMachine<'bump> {
pub(crate) fn new(edits: Mutations<'bump>, shared: &'bump mut ResourcePool) -> Self {
pub(crate) fn new(edits: Mutations<'bump>, shared: &'bump ResourcePool) -> Self {
Self {
stack: DiffStack::new(),
mutations: edits,
+8 -1
View File
@@ -13,7 +13,10 @@ pub struct UiEvent {
/// The optional real node associated with the trigger
pub mounted_dom_id: Option<ElementId>,
pub listener_type: &'static str,
/// The event type IE "onclick" or "onmouseover"
///
/// The name that the renderer will use to mount the listener.
pub name: &'static str,
/// The type of event
pub event: SyntheticEvent,
@@ -406,6 +409,10 @@ pub mod on {
///
ontoggle
];
GenericEventInner(GenericEvent): [
];
}
pub trait GenericEventInner {
+1
View File
@@ -26,6 +26,7 @@ pub mod mutations;
pub mod nodes;
pub mod scheduler;
pub mod scope;
pub mod test_dom;
pub mod util;
pub mod virtual_dom;
+82
View File
@@ -0,0 +1,82 @@
//! A DOM for testing - both internal and external code.
use bumpalo::Bump;
use crate::innerlude::*;
use crate::nodes::IntoVNode;
pub struct TestDom {
bump: Bump,
scheduler: Scheduler,
}
impl TestDom {
pub fn new() -> TestDom {
let bump = Bump::new();
let scheduler = Scheduler::new();
TestDom { bump, scheduler }
}
pub fn new_factory<'a>(&'a self) -> NodeFactory<'a> {
NodeFactory::new(&self.bump)
}
pub fn render<'a, F>(&'a self, lazy_nodes: LazyNodes<'a, F>) -> VNode<'a>
where
F: FnOnce(NodeFactory<'a>) -> VNode<'a>,
{
lazy_nodes.into_vnode(NodeFactory::new(&self.bump))
}
pub fn diff<'a>(&'a self, old: &'a VNode<'a>, new: &'a VNode<'a>) -> Mutations<'a> {
let mutations = Mutations::new();
let mut machine = DiffMachine::new(mutations, &self.scheduler.pool);
machine.stack.push(DiffInstruction::DiffNode { new, old });
machine.mutations
}
pub fn create<'a, F1>(&'a self, left: LazyNodes<'a, F1>) -> Mutations<'a>
where
F1: FnOnce(NodeFactory<'a>) -> VNode<'a>,
{
let old = self.bump.alloc(self.render(left));
let mut machine = DiffMachine::new(Mutations::new(), &self.scheduler.pool);
machine.stack.create_node(old, MountType::Append);
machine.work(&mut || false);
machine.mutations
}
pub fn lazy_diff<'a, F1, F2>(
&'a self,
left: LazyNodes<'a, F1>,
right: LazyNodes<'a, F2>,
) -> (Mutations<'a>, Mutations<'a>)
where
F1: FnOnce(NodeFactory<'a>) -> VNode<'a>,
F2: FnOnce(NodeFactory<'a>) -> VNode<'a>,
{
let old = self.bump.alloc(self.render(left));
let new = self.bump.alloc(self.render(right));
let mut machine = DiffMachine::new(Mutations::new(), &self.scheduler.pool);
machine.stack.create_node(old, MountType::Append);
machine.work(&mut || false);
let create_edits = machine.mutations;
let mut machine = DiffMachine::new(Mutations::new(), &self.scheduler.pool);
machine.stack.push(DiffInstruction::DiffNode { old, new });
machine.work(&mut || false);
let edits = machine.mutations;
(create_edits, edits)
}
}
+1 -1
View File
@@ -1,7 +1,7 @@
//! tests to prove that the iterative implementation works
use anyhow::{Context, Result};
use dioxus::{diff::DiffMachine, prelude::*, scheduler::Scheduler, DomEdit, Mutations};
use dioxus::{prelude::*, DomEdit, Mutations};
mod test_logging;
use dioxus_core as dioxus;
use dioxus_html as dioxus_elements;
+1 -1
View File
@@ -43,6 +43,6 @@ async fn test_iterative_create_components() {
let mutations = dom.rebuild_async().await;
dbg!(mutations);
let mutations = dom.diff_async().await;
let mutations = dom.diff();
dbg!(mutations);
}
-84
View File
@@ -15,90 +15,6 @@ use DomEdit::*;
// feel free to enable while debugging
const IS_LOGGING_ENABLED: bool = false;
struct TestDom {
bump: Bump,
resources: Scheduler,
}
impl TestDom {
fn new() -> TestDom {
test_logging::set_up_logging(IS_LOGGING_ENABLED);
let bump = Bump::new();
let resources = Scheduler::new();
TestDom { bump, resources }
}
fn new_factory<'a>(&'a self) -> NodeFactory<'a> {
NodeFactory::new(&self.bump)
}
fn render<'a, F>(&'a self, lazy_nodes: LazyNodes<'a, F>) -> VNode<'a>
where
F: FnOnce(NodeFactory<'a>) -> VNode<'a>,
{
use dioxus_core::nodes::{IntoVNode, IntoVNodeList};
lazy_nodes.into_vnode(NodeFactory::new(&self.bump))
}
fn diff<'a>(&'a self, old: &'a VNode<'a>, new: &'a VNode<'a>) -> Mutations<'a> {
// let mut edits = Vec::new();
let mut machine = DiffMachine::new_headless(&self.resources);
machine.stack.push(DiffInstruction::DiffNode { new, old });
machine.mutations
}
fn create<'a, F1>(&'a self, left: LazyNodes<'a, F1>) -> Mutations<'a>
where
F1: FnOnce(NodeFactory<'a>) -> VNode<'a>,
{
let old = self.bump.alloc(self.render(left));
let mut machine = DiffMachine::new_headless(&self.resources);
machine.stack.create_node(old, MountType::Append);
work_sync(&mut machine);
machine.mutations
}
fn lazy_diff<'a, F1, F2>(
&'a self,
left: LazyNodes<'a, F1>,
right: LazyNodes<'a, F2>,
) -> (Mutations<'a>, Mutations<'a>)
where
F1: FnOnce(NodeFactory<'a>) -> VNode<'a>,
F2: FnOnce(NodeFactory<'a>) -> VNode<'a>,
{
let old = self.bump.alloc(self.render(left));
let new = self.bump.alloc(self.render(right));
let mut machine = DiffMachine::new_headless(&self.resources);
machine.stack.create_node(old, MountType::Append);
work_sync(&mut machine);
let create_edits = machine.mutations;
let mut machine = DiffMachine::new_headless(&self.resources);
machine.stack.push(DiffInstruction::DiffNode { old, new });
work_sync(&mut machine);
let edits = machine.mutations;
(create_edits, edits)
}
}
fn work_sync(machine: &mut DiffMachine) {
let mut fut = machine.work().boxed_local();
while let None = (&mut fut).now_or_never() {
//
}
}
#[test]
fn diffing_works() {}
+1 -1
View File
@@ -1,7 +1,7 @@
use bumpalo::Bump;
use anyhow::{Context, Result};
use dioxus::{diff::DiffMachine, prelude::*, scheduler::Scheduler, DomEdit};
use dioxus::{prelude::*, DomEdit};
use dioxus_core as dioxus;
use dioxus_html as dioxus_elements;
+1 -1
View File
@@ -1,5 +1,5 @@
use anyhow::{Context, Result};
use dioxus::{diff::DiffMachine, prelude::*, scheduler::Scheduler, DomEdit};
use dioxus::prelude::*;
use dioxus_core as dioxus;
use dioxus_html as dioxus_elements;
+1 -1
View File
@@ -3,7 +3,7 @@
//! This means you can actually call it synchronously if you want.
use anyhow::{Context, Result};
use dioxus::{diff::DiffMachine, prelude::*, scheduler::Scheduler, scope::Scope};
use dioxus::{prelude::*, scope::Scope};
use dioxus_core as dioxus;
use dioxus_html as dioxus_elements;
use futures_util::FutureExt;