Struct perseus::template::CapsuleInner
source · pub struct CapsuleInner<G: Html, P: Clone + 'static> { /* private fields */ }
Expand description
The equivalent of TemplateInner
for capsules.
Implementation
Really, this is just a wrapper over TemplateInner
with the additional
methods capsules need. For example, templates have fallback views on their
own, they just don’t use them, and there’s no way to set them as an end
user. This means Perseus can treat templates and capsules in the same way
internally, since they both have the same representation. Types like this
are mere convenience wrappers.
Implementations§
source§impl<G: Html, P: Clone + 'static> CapsuleInner<G, P>
impl<G: Html, P: Clone + 'static> CapsuleInner<G, P>
sourcepub fn fallback(
self,
view: impl Fn(Scope<'_>, P) -> View<G> + Send + Sync + 'static
) -> Self
pub fn fallback( self, view: impl Fn(Scope<'_>, P) -> View<G> + Send + Sync + 'static ) -> Self
Declares the fallback view to render for this capsule. When Perseus renders a page of your app, it fetches the page itself, along with all the capsules it needs. If the page is ready before all the capsules, then it will be displayed immediately, with fallback views for the capsules that aren’t ready yet. Once they are ready, they will be updated.
This fallback view cannot access any of the state that the capsule generated, but it can access any properties provided to it by the page, along with a translator and the like. This view is fully reactive, it just doesn’t have the state yet.
Warning: if you do not set a fallback view for a capsule, your app will not compile!
sourcepub fn empty_fallback(self) -> Self
pub fn empty_fallback(self) -> Self
Sets the fallback for this capsule to be an empty view.
You should be careful using this function in production, since it is very often not what you actually want (especially since empty views have no size, which may compromise your layouts: be sure to test this).
sourcepub fn build(self) -> Capsule<G, P>
pub fn build(self) -> Capsule<G, P>
Builds a full Capsule
from this CapsuleInner
, consuming it in
the process. Once called, the capsule cannot be modified anymore,
and it will be placed into a smart pointer, allowing it to be cloned
freely with minimal costs.
You should call this just before you return your capsule.
sourcepub fn view_with_state<I, F>(self, val: F) -> Selfwhere
F: for<'app, 'child> Fn(BoundedScope<'app, 'child>, &'child I, P) -> View<G> + Clone + Send + Sync + 'static,
I: MakeUnrx + AnyFreeze + Clone,
I::Unrx: MakeRx<Rx = I> + Serialize + DeserializeOwned + Send + Sync + Clone + 'static,
pub fn view_with_state<I, F>(self, val: F) -> Selfwhere F: for<'app, 'child> Fn(BoundedScope<'app, 'child>, &'child I, P) -> View<G> + Clone + Send + Sync + 'static, I: MakeUnrx + AnyFreeze + Clone, I::Unrx: MakeRx<Rx = I> + Serialize + DeserializeOwned + Send + Sync + Clone + 'static,
Sets the rendering function to use for capsules that take reactive
state. Capsules that do not take state should use .view()
instead.
The closure wrapping this performs will automatically handle suspense state.
sourcepub fn view_with_unreactive_state<F, S>(self, val: F) -> Selfwhere
F: Fn(Scope<'_>, S, P) -> View<G> + Clone + Send + Sync + 'static,
S: MakeRx + Serialize + DeserializeOwned + UnreactiveState + 'static,
<S as MakeRx>::Rx: AnyFreeze + Clone + MakeUnrx<Unrx = S>,
pub fn view_with_unreactive_state<F, S>(self, val: F) -> Selfwhere F: Fn(Scope<'_>, S, P) -> View<G> + Clone + Send + Sync + 'static, S: MakeRx + Serialize + DeserializeOwned + UnreactiveState + 'static, <S as MakeRx>::Rx: AnyFreeze + Clone + MakeUnrx<Unrx = S>,
Sets the rendering function to use for capsules that take unreactive state.