mirror of
https://github.com/leptos-rs/leptos.git
synced 2025-12-27 09:54:41 -05:00
Clean up after work on transitions
This commit is contained in:
5
TODO.md
5
TODO.md
@@ -1,11 +1,10 @@
|
||||
- [ ] Async
|
||||
- [x] Resource
|
||||
- [x] Suspense
|
||||
- [ ] Transitions
|
||||
- [x] Transitions
|
||||
- [ ] Tests for Suspense/Transitions
|
||||
- [ ] Bugs in Suspense/Transitions
|
||||
- [ ] infinite loop if reading resource in effect
|
||||
- [ ] rendering bugs if `Suspense` doesn't have a parent
|
||||
- [ ] let render effects that _aren't_ under the transition continue running
|
||||
- [ ] Router
|
||||
- [ ] Docs (and clippy warning to insist on docs)
|
||||
- [ ] Read through + understand...
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn transition_tabs(cx: Scope) -> web_sys::Element {
|
||||
|
||||
view! {
|
||||
<div>
|
||||
<progress class:visible={move || transition.pending()} value={move || progress().to_string()} max="100"></progress>
|
||||
<progress class:visible={move || transition.pending()} value={move || progress().to_string()} max="40"></progress>
|
||||
<nav class="tabs" class:pending={move || transition.pending()}>
|
||||
<button class:selected={move || tab() == Tab::A} on:click=move |_| transition.start(move || set_tab(|n| *n = Tab::A))>
|
||||
"One"
|
||||
@@ -84,7 +84,7 @@ pub fn Child(cx: Scope, page: ReadSignal<Tab>) -> Element {
|
||||
|
||||
let (counter, set_counter) = cx.create_signal(0);
|
||||
|
||||
/* cx.create_effect(move |prev_handle: Option<IntervalHandle>| {
|
||||
cx.create_effect(move |prev_handle: Option<IntervalHandle>| {
|
||||
log::debug!("resetting counter for Child #{}", page());
|
||||
set_counter(|n| *n = 0);
|
||||
if let Some(handle) = prev_handle {
|
||||
@@ -93,16 +93,15 @@ pub fn Child(cx: Scope, page: ReadSignal<Tab>) -> Element {
|
||||
set_interval(
|
||||
move || {
|
||||
set_counter(|n| *n += 1);
|
||||
log::debug!("increment to {}", counter());
|
||||
},
|
||||
Duration::from_millis(10),
|
||||
Duration::from_millis(100),
|
||||
)
|
||||
.unwrap()
|
||||
}); */
|
||||
});
|
||||
|
||||
view! {
|
||||
<div class="tab-content">
|
||||
//<span>{move || counter().to_string()}</span>
|
||||
<span>{move || counter().to_string()}</span>
|
||||
<p>
|
||||
<Suspense fallback=view! { <div class="loader">"Lower suspense..."</div> }>
|
||||
{move || data.read().map(|data| view! {
|
||||
@@ -117,7 +116,7 @@ pub fn Child(cx: Scope, page: ReadSignal<Tab>) -> Element {
|
||||
}
|
||||
|
||||
async fn fake_data_load(page: Tab) -> String {
|
||||
delay(Duration::from_secs(1)).await;
|
||||
delay(Duration::from_millis(400)).await;
|
||||
let page_data = vec![
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Nec dui nunc mattis enim ut tellus elementum sagittis vitae. Quam elementum pulvinar etiam non. Sed faucibus turpis in eu mi. Convallis a cras semper auctor neque vitae tempus quam pellentesque. Duis tristique sollicitudin nibh sit amet. Elementum curabitur vitae nunc sed velit dignissim sodales. Nibh venenatis cras sed felis eget velit aliquet sagittis. In pellentesque massa placerat duis. Integer quis auctor elit sed vulputate mi sit amet mauris. Luctus accumsan tortor posuere ac ut consequat semper. Lorem ipsum dolor sit amet consectetur adipiscing elit. Sed faucibus turpis in eu mi bibendum neque egestas. Dictumst vestibulum rhoncus est pellentesque elit.",
|
||||
"Placerat orci nulla pellentesque dignissim. Non curabitur gravida arcu ac. Sed odio morbi quis commodo odio aenean sed. Quam elementum pulvinar etiam non quam lacus. Est lorem ipsum dolor sit. Turpis massa sed elementum tempus egestas sed sed. Quam nulla porttitor massa id neque aliquam vestibulum morbi blandit. Aenean pharetra magna ac placerat. Donec et odio pellentesque diam volutpat commodo sed. Eget duis at tellus at urna condimentum. Rhoncus dolor purus non enim praesent elementum facilisis leo vel. Velit laoreet id donec ultrices. Aliquet eget sit amet tellus cras adipiscing enim eu.",
|
||||
|
||||
@@ -220,11 +220,9 @@ where
|
||||
if let Some(transition) = self.runtime.running_transition() {
|
||||
let mut t_value = self.t_value.borrow_mut();
|
||||
if let Some(t_value) = &mut *t_value {
|
||||
log::debug!("setting forked value of memo");
|
||||
let v = { (self.f.borrow_mut())(Some(t_value)) };
|
||||
*t_value = v;
|
||||
} else {
|
||||
log::debug!("forking memo");
|
||||
// fork reality, using the old value as the basis for the transitional value
|
||||
let v = { (self.f.borrow_mut())(self.value.borrow().as_ref()) };
|
||||
*t_value = Some(v);
|
||||
@@ -261,10 +259,7 @@ where
|
||||
|
||||
fn end_transition(&self, runtime: &'static Runtime) {
|
||||
let t_value = self.t_value.borrow_mut().take();
|
||||
log::debug!(
|
||||
"committing value {t_value:?} on Memo<{}>",
|
||||
std::any::type_name::<T>()
|
||||
);
|
||||
|
||||
if let Some(value) = t_value {
|
||||
*self.value.borrow_mut() = Some(value);
|
||||
|
||||
|
||||
@@ -222,10 +222,6 @@ where
|
||||
let loaded_under_transition = self.scope.runtime.running_transition().is_some();
|
||||
|
||||
let fut = (self.fetcher)(&self.source.get());
|
||||
log::debug!(
|
||||
"loading resource — under transition? {}",
|
||||
loaded_under_transition
|
||||
);
|
||||
|
||||
// `scheduled` is true for the rest of this code only
|
||||
self.scheduled.set(true);
|
||||
@@ -249,10 +245,6 @@ where
|
||||
.resources
|
||||
.borrow_mut()
|
||||
.insert(suspense_context.pending_resources);
|
||||
log::debug!(
|
||||
"inserted resource to transition: now {} resources",
|
||||
transition.resources.borrow().len()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -165,10 +165,8 @@ where
|
||||
if let Some(transition) = self.runtime.running_transition() {
|
||||
let mut t_value = signal_state.t_value.borrow_mut();
|
||||
if let Some(t_value) = &mut *t_value {
|
||||
log::debug!("setting forked value of signal");
|
||||
(f)(t_value);
|
||||
} else {
|
||||
log::debug!("forking signal");
|
||||
// fork reality, using the old value as the basis for the transitional value
|
||||
let mut forked = (*signal_state.value.borrow()).clone();
|
||||
(f)(&mut forked);
|
||||
@@ -298,12 +296,8 @@ where
|
||||
}
|
||||
|
||||
fn end_transition(&self, runtime: &'static Runtime) {
|
||||
log::debug!("SignalState::end_transition");
|
||||
let t_value = self.t_value.borrow_mut().take();
|
||||
log::debug!(
|
||||
"committing value {t_value:?} on Signal<{}>",
|
||||
std::any::type_name::<T>()
|
||||
);
|
||||
|
||||
if let Some(value) = t_value {
|
||||
*self.value.borrow_mut() = value;
|
||||
|
||||
|
||||
@@ -34,9 +34,7 @@ impl Transition {
|
||||
if self.runtime.running_transition().is_some() {
|
||||
f();
|
||||
} else {
|
||||
log::debug!("[Transition] starting a transition");
|
||||
{
|
||||
log::debug!("[Transition] running => true");
|
||||
self.set_pending.update(|n| *n = true);
|
||||
*self.runtime.transition.borrow_mut() = Some(Rc::new(TransitionState {
|
||||
running: Cell::new(true),
|
||||
@@ -47,11 +45,9 @@ impl Transition {
|
||||
}));
|
||||
}
|
||||
|
||||
log::debug!("[Transition] running start_transition f()");
|
||||
f();
|
||||
|
||||
if let Some(running_transition) = self.runtime.running_transition() {
|
||||
log::debug!("[Transition] running => false");
|
||||
running_transition.running.set(false);
|
||||
|
||||
let runtime = self.runtime;
|
||||
@@ -65,10 +61,8 @@ impl Transition {
|
||||
queue_microtask(move || {
|
||||
scope.create_effect(move |_| {
|
||||
let pending = resources.borrow().iter().map(|p| p.get()).sum::<usize>();
|
||||
log::debug!("[Transition] pending: {pending}");
|
||||
|
||||
if pending == 0 {
|
||||
log::debug!("[Transition] Committing changes.");
|
||||
for signal in signals.borrow().iter() {
|
||||
runtime.any_signal(*signal, |signal| {
|
||||
signal.end_transition(runtime);
|
||||
@@ -80,7 +74,6 @@ impl Transition {
|
||||
});
|
||||
}
|
||||
for effect in effects.borrow().iter() {
|
||||
log::debug!("running deferred effect");
|
||||
runtime.any_effect(*effect, |any_effect| {
|
||||
any_effect.run(*effect);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user