wip: add test_dom
This commit is contained in:
1 parent
44b4384961
commit
a652090dc5
12 files changed
+192
-97
No files matched your search
@@ -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,
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user