Browse Source

fix: make miri pass

Jonathan Kelley 2 years ago
parent
commit
ea9245b0f7
2 changed files with 34 additions and 31 deletions
  1. 23 26
      packages/core/src/diff.rs
  2. 11 5
      packages/core/src/lazynodes.rs

+ 23 - 26
packages/core/src/diff.rs

@@ -155,21 +155,22 @@ impl<'b> VirtualDom {
 
 
         // Replace components that have different render fns
         // Replace components that have different render fns
         if left.render_fn != right.render_fn {
         if left.render_fn != right.render_fn {
-            todo!()
-            // let created = self.create_component_node(right_template, right, idx);
-            // let head = unsafe {
-            //     self.scopes[left.scope.get().unwrap().0]
-            //         .root_node()
-            //         .extend_lifetime_ref()
-            // };
-            // let last = match head {
-            //     RenderReturn::Sync(Ok(node)) => self.find_last_element(node),
-            //     _ => todo!(),
-            // };
-            // self.mutations
-            //     .push(Mutation::ReplaceWith { id, m: created });
-            // self.drop_scope(left.scope.get().unwrap());
-            // return;
+            let created = self.create_component_node(right_template, right, idx);
+            let head = unsafe {
+                self.scopes[left.scope.get().unwrap().0]
+                    .root_node()
+                    .extend_lifetime_ref()
+            };
+            let last = match head {
+                RenderReturn::Sync(Ok(node)) => self.find_last_element(node),
+                _ => todo!(),
+            };
+            self.mutations.push(Mutation::InsertAfter {
+                id: last,
+                m: created,
+            });
+            self.remove_component_node(left, true);
+            return;
         }
         }
 
 
         // Make sure the new vcomponent has the right scopeid associated to it
         // Make sure the new vcomponent has the right scopeid associated to it
@@ -240,14 +241,13 @@ impl<'b> VirtualDom {
     /// }
     /// }
     /// ```
     /// ```
     fn light_diff_templates(&mut self, left: &'b VNode<'b>, right: &'b VNode<'b>) {
     fn light_diff_templates(&mut self, left: &'b VNode<'b>, right: &'b VNode<'b>) {
-        self.replace(left, [right]);
-        // match matching_components(left, right) {
-        //     None => self.replace(left, [right]),
-        //     Some(components) => components
-        //         .into_iter()
-        //         .enumerate()
-        //         .for_each(|(idx, (l, r))| self.diff_vcomponent(l, r, right, idx)),
-        // }
+        match matching_components(left, right) {
+            None => self.replace(left, [right]),
+            Some(components) => components
+                .into_iter()
+                .enumerate()
+                .for_each(|(idx, (l, r))| self.diff_vcomponent(l, r, right, idx)),
+        }
     }
     }
 
 
     /// Diff the two text nodes
     /// Diff the two text nodes
@@ -815,9 +815,6 @@ impl<'b> VirtualDom {
             };
             };
 
 
             let props = self.scopes[scope.0].props.take();
             let props = self.scopes[scope.0].props.take();
-            // let props: Option<Box<dyn AnyProps>> = comp.props.take();
-
-            println!("taking props... {:?}", scope);
 
 
             self.dirty_scopes.remove(&DirtyScope {
             self.dirty_scopes.remove(&DirtyScope {
                 height: self.scopes[scope.0].height,
                 height: self.scopes[scope.0].height,

+ 11 - 5
packages/core/src/lazynodes.rs

@@ -25,8 +25,11 @@ use crate::{innerlude::VNode, ScopeState};
 /// LazyNodes::new(|f| f.element("div", [], [], [] None))
 /// LazyNodes::new(|f| f.element("div", [], [], [] None))
 /// ```
 /// ```
 pub struct LazyNodes<'a, 'b> {
 pub struct LazyNodes<'a, 'b> {
+    #[cfg(not(miri))]
+    inner: SmallBox<dyn FnMut(&'a ScopeState) -> VNode<'a> + 'b, S16>,
+
+    #[cfg(miri)]
     inner: Box<dyn FnMut(&'a ScopeState) -> VNode<'a> + 'b>,
     inner: Box<dyn FnMut(&'a ScopeState) -> VNode<'a> + 'b>,
-    // inner: SmallBox<dyn FnMut(&'a ScopeState) -> VNode<'a> + 'b, S16>,
 }
 }
 
 
 impl<'a, 'b> LazyNodes<'a, 'b> {
 impl<'a, 'b> LazyNodes<'a, 'b> {
@@ -40,14 +43,17 @@ impl<'a, 'b> LazyNodes<'a, 'b> {
         let mut slot = Some(val);
         let mut slot = Some(val);
 
 
         Self {
         Self {
+            #[cfg(miri)]
             inner: Box::new(move |f| {
             inner: Box::new(move |f| {
                 let val = slot.take().expect("cannot call LazyNodes twice");
                 let val = slot.take().expect("cannot call LazyNodes twice");
                 val(f)
                 val(f)
             }),
             }),
-            // inner: smallbox!(move |f| {
-            //     let val = slot.take().expect("cannot call LazyNodes twice");
-            //     val(f)
-            // }),
+
+            #[cfg(not(miri))]
+            inner: smallbox!(move |f| {
+                let val = slot.take().expect("cannot call LazyNodes twice");
+                val(f)
+            }),
         }
         }
     }
     }