Jonathan Kelley 4 سال پیش
والد
کامیت
c809095124
3فایلهای تغییر یافته به همراه47 افزوده شده و 27 حذف شده
  1. 5 19
      packages/core/src/scope.rs
  2. 17 0
      packages/core/src/virtual_dom.rs
  3. 25 8
      packages/web/examples/todomvc_simple.rs

+ 5 - 19
packages/core/src/scope.rs

@@ -84,25 +84,14 @@ impl Scope {
     ///
     /// Props is ?Sized because we borrow the props and don't need to know the size. P (sized) is used as a marker (unsized)
     pub fn run_scope<'b>(&'b mut self) -> Result<()> {
-        // pub fn run_scope<'bump>(&'bump mut self) -> Result<()> {
-        // let frame = {
-        {
-            let frame = self.frames.next();
-            frame.bump.reset();
-        }
-        //     frame
-        // };
-        // self.new_frame()
+        // cycle to the next frame and then reset it
+        // this breaks any latent references
+        self.frames.next().bump.reset();
 
         let ctx = Context {
-            // arena: &self.hook_arena,
-            // hooks: &self.hooks,
-            // bump: &frame.bump,
             idx: 0.into(),
             _p: PhantomData {},
             scope: self,
-            // scope: self.myidx,
-            // listeners: &self.listeners,
         };
 
         let caller = self.caller.upgrade().expect("Failed to get caller");
@@ -118,14 +107,11 @@ impl Scope {
         - The VNode has a private API and can only be used from accessors.
         - Public API cannot drop or destructure VNode
         */
-
         let new_head = unsafe {
-            // frame.head_node = unsafe {
-            //     // use the same type, just manipulate the lifetime
+            // use the same type, just manipulate the lifetime
             type ComComp<'c> = Rc<OpaqueComponent<'c>>;
             let caller = std::mem::transmute::<ComComp<'static>, ComComp<'b>>(caller);
-            let r: DomTree = (caller.as_ref())(ctx);
-            r
+            (caller.as_ref())(ctx)
         };
 
         self.frames.cur_frame_mut().head_node = new_head.root;

+ 17 - 0
packages/core/src/virtual_dom.rs

@@ -229,3 +229,20 @@ impl UpdateFunnel {
         }
     }
 }
+
+macro_rules! UpdateFunnel {
+    (root: $root:expr) => {
+        VirtualDom::new($root)
+    };
+}
+
+// #[test]
+// fn test_new_vdom() {
+//     let dom = UpdateFunnel! {
+//         root: |ctx, props| {
+//             ctx.render(rsx!{
+
+//             })
+//         }
+//     };
+// }

+ 25 - 8
packages/web/examples/todomvc_simple.rs

@@ -79,10 +79,12 @@ pub fn TodoList(ctx: Context, props: &()) -> DomTree {
                     FilterState::Completed => item.checked,
                 })
                 .map(|(id, item)| {
-                    rsx!(TodoEntry {
-                        key: "{order}",
-                        item: item.clone()
-                    })
+                    TodoEntry!();
+                    todo!()
+                    // rsx!(TodoEntry {
+                    //     key: "{order}",
+                    //     item: item.clone()
+                    // })
                 })
             }
 
@@ -99,9 +101,24 @@ pub struct TodoEntryProps {
     item: Rc<TodoItem>,
 }
 
-pub fn TodoEntry(ctx: Context, props: &TodoEntryProps) -> DomTree {
+mod mac {
+    #[macro_export]
+    macro_rules! TodoEntry {
+        () => {};
+    }
+}
+
+// pub fn TodoEntry(ctx: Context, props: &TodoEntryProps) -> DomTree {
+// #[inline_props]
+pub fn TodoEntry(
+    ctx: Context,
+    baller: &impl Fn() -> (),
+    caller: &impl Fn() -> (),
+    todo: &Rc<TodoItem>,
+) -> DomTree {
+    // pub fn TodoEntry(ctx: Context, todo: &Rc<TodoItem>) -> DomTree {
     let (is_editing, set_is_editing) = use_state(&ctx, || false);
-    let todo = &props.item;
+    // let todo = &props.item;
 
     ctx.render(rsx! (
         li {
@@ -111,11 +128,11 @@ pub fn TodoEntry(ctx: Context, props: &TodoEntryProps) -> DomTree {
                 type: "checkbox"
                 "{todo.checked}"
             }
-            {is_editing.then(|| rsx!(
+           {is_editing.then(|| rsx!{
                 input {
                     value: "{contents}"
                 }
-            ))}
+            })}
         }
     ))
 }