mirror of
https://github.com/leptos-rs/leptos
synced 2024-11-10 06:44:17 +00:00
add set_pending
to <Transition/>
This commit is contained in:
parent
619dc59e1d
commit
8a8862be9e
1 changed files with 19 additions and 2 deletions
|
@ -6,9 +6,11 @@ use crate::{
|
|||
use leptos_macro::component;
|
||||
use reactive_graph::{
|
||||
computed::{suspense::SuspenseContext, ArcMemo},
|
||||
effect::Effect,
|
||||
owner::provide_context,
|
||||
signal::ArcRwSignal,
|
||||
traits::With,
|
||||
traits::{Get, With},
|
||||
wrappers::write::SignalSetter,
|
||||
};
|
||||
use slotmap::{DefaultKey, SlotMap};
|
||||
use tachys::reactive_graph::OwnedView;
|
||||
|
@ -16,7 +18,14 @@ use tachys::reactive_graph::OwnedView;
|
|||
/// TODO docs!
|
||||
#[component]
|
||||
pub fn Transition<Chil>(
|
||||
#[prop(optional, into)] fallback: ViewFnOnce,
|
||||
/// Will be displayed while resources are pending. By default this is the empty view.
|
||||
#[prop(optional, into)]
|
||||
fallback: ViewFnOnce,
|
||||
/// A function that will be called when the component transitions into or out of
|
||||
/// the `pending` state, with its argument indicating whether it is pending (`true`)
|
||||
/// or not pending (`false`).
|
||||
#[prop(optional, into)]
|
||||
set_pending: Option<SignalSetter<bool>>,
|
||||
children: TypedChildren<Chil>,
|
||||
) -> impl IntoView
|
||||
where
|
||||
|
@ -29,6 +38,14 @@ where
|
|||
tasks: tasks.clone(),
|
||||
});
|
||||
let none_pending = ArcMemo::new(move |_| tasks.with(SlotMap::is_empty));
|
||||
if let Some(set_pending) = set_pending {
|
||||
Effect::new_isomorphic({
|
||||
let none_pending = none_pending.clone();
|
||||
move |_| {
|
||||
set_pending.set(!none_pending.get());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
OwnedView::new(SuspenseBoundary::<true, _, _> {
|
||||
none_pending,
|
||||
|
|
Loading…
Reference in a new issue