diff --git a/packages/core/src/any_props.rs b/packages/core/src/any_props.rs index 9c3c34cfe..edf115de5 100644 --- a/packages/core/src/any_props.rs +++ b/packages/core/src/any_props.rs @@ -1,5 +1,5 @@ use crate::{nodes::RenderReturn, properties::ComponentFunction}; -use std::{any::Any, ops::Deref, panic::AssertUnwindSafe, rc::Rc}; +use std::{any::Any, marker::PhantomData, ops::Deref, panic::AssertUnwindSafe}; /// A boxed version of AnyProps that can be cloned pub(crate) struct BoxedAnyProps { @@ -38,30 +38,34 @@ pub(crate) trait AnyProps { fn duplicate(&self) -> Box; } -pub(crate) struct VProps { - pub render_fn: Rc>, +pub(crate) struct VProps, Phantom: 'static> { + pub render_fn: F, pub memo: fn(&P, &P) -> bool, pub props: P, pub name: &'static str, + phantom: PhantomData, } -impl VProps { +impl, Phantom: 'static> VProps { pub(crate) fn new( - render_fn: impl ComponentFunction + 'static, + render_fn: F, memo: fn(&P, &P) -> bool, props: P, name: &'static str, ) -> Self { Self { - render_fn: Rc::new(render_fn), + render_fn, memo, props, name, + phantom: PhantomData, } } } -impl AnyProps for VProps { +impl, Phantom> AnyProps + for VProps +{ fn memoize(&self, other: &dyn Any) -> bool { match other.downcast_ref::

() { Some(other) => (self.memo)(&self.props, other), @@ -96,6 +100,7 @@ impl AnyProps for VProps { memo: self.memo, props: self.props.clone(), name: self.name, + phantom: PhantomData, }) } } diff --git a/packages/core/src/nodes.rs b/packages/core/src/nodes.rs index c159c5d92..9cdfd525a 100644 --- a/packages/core/src/nodes.rs +++ b/packages/core/src/nodes.rs @@ -503,7 +503,6 @@ impl Default for DynamicNode { } } -#[derive(Clone)] /// An instance of a child component pub struct VComponent { /// The name of this component diff --git a/packages/core/src/properties.rs b/packages/core/src/properties.rs index 530d32bf3..1be8e957f 100644 --- a/packages/core/src/properties.rs +++ b/packages/core/src/properties.rs @@ -112,7 +112,7 @@ where /// ``` /// /// > Note: If you get an error about the `ComponentFunction` trait not being implemented: make sure your props implements the `Properties` trait or if you would like to declare your props inline, make sure you use the #[component] macro on your function. -pub trait ComponentFunction

{ +pub trait ComponentFunction

: Clone + 'static { /// The props type for this component. type Props: 'static; @@ -120,7 +120,7 @@ pub trait ComponentFunction

{ fn call(&self, props: Self::Props) -> Element; } -impl Element> ComponentFunction<(T,)> for F { +impl Element + Clone + 'static> ComponentFunction<(T,)> for F { type Props = T; fn call(&self, props: T) -> Element { @@ -130,7 +130,7 @@ impl Element> ComponentFunction<(T,)> for F { #[doc(hidden)] pub struct ZeroElementMarker; -impl Element> ComponentFunction for F { +impl Element + Clone + 'static> ComponentFunction for F { type Props = (); fn call(&self, _: ()) -> Element { diff --git a/packages/core/src/virtual_dom.rs b/packages/core/src/virtual_dom.rs index 21dffbefa..39a7d1aa6 100644 --- a/packages/core/src/virtual_dom.rs +++ b/packages/core/src/virtual_dom.rs @@ -13,7 +13,7 @@ use crate::{ nodes::{Template, TemplateId}, runtime::{Runtime, RuntimeGuard}, scopes::ScopeId, - AttributeValue, Element, Event, Mutations, + AttributeValue, BoxedContext, Element, Event, Mutations, }; use futures_util::{pin_mut, StreamExt}; use rustc_hash::{FxHashMap, FxHashSet}; @@ -328,8 +328,10 @@ impl VirtualDom { /// Build the virtualdom with a global context inserted into the base scope /// /// This method is useful for when you want to provide a context in your app without knowing its type - pub fn with_boxed_root_context(self, context: Box) -> Self { - self.base_scope().context().provide_any_context(context); + pub fn with_boxed_root_context(self, context: BoxedContext) -> Self { + self.base_scope() + .context() + .provide_any_context(context.into_inner()); self }