1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
//! This file handles the supporting infrastructure for the `Component` trait and `Properties` which makes it possible //! for components to be used within Nodes. //! /// The `Component` trait refers to any struct or funciton that can be used as a component /// We automatically implement Component for FC<T> // pub trait Component { // type Props: Properties<'static>; // fn builder(&'static self) -> Self::Props; // } // // Auto implement component for a FC // // Calling the FC is the same as "rendering" it // impl<P: Properties<'static>> Component for FC<P> { // type Props = P; // fn builder(&self) -> Self::Props { // todo!() // } // } /// The `Properties` trait defines any struct that can be constructed using a combination of default / optional fields. /// Components take a "properties" object // pub trait Properties<'a> // where // Self: Debug, // { // fn call(&self, ptr: *const ()) {} // } // // Auto implement for no-prop components // impl<'a> Properties<'a> for () { // fn call(&self, ptr: *const ()) {} // } #[cfg(test)] mod tests { use crate::prelude::bumpalo::Bump; use crate::prelude::*; fn test_static_fn<'a, P>(b: &'a Bump, r: FC<P>) -> VNode<'a> { todo!() } static TestComponent: FC<()> = |ctx, props| { // ctx.view(html! { <div> </div> }) }; static TestComponent2: FC<()> = |ctx, props| { // ctx.view(|bump: &Bump| VNode::text("blah")) }; #[test] fn ensure_types_work() { let bump = Bump::new(); // Happiness! The VNodes are now allocated onto the bump vdom let _ = test_static_fn(&bump, TestComponent); let _ = test_static_fn(&bump, TestComponent2); } }