From 2ed8a58894f1c75108833ab8266369869f4d5234 Mon Sep 17 00:00:00 2001 From: Greg Johnston Date: Sat, 15 Oct 2022 07:59:37 -0400 Subject: [PATCH] Remove transitions; maybe work this back in in the future --- leptos_reactive/Cargo.toml | 3 +- leptos_reactive/src/effect.rs | 10 ---- leptos_reactive/src/runtime.rs | 20 ------- leptos_reactive/src/scope.rs | 5 -- leptos_reactive/src/signal.rs | 88 ---------------------------- leptos_reactive/src/transition.rs | 96 ------------------------------- 6 files changed, 1 insertion(+), 221 deletions(-) delete mode 100644 leptos_reactive/src/transition.rs diff --git a/leptos_reactive/Cargo.toml b/leptos_reactive/Cargo.toml index f9001cd96..5f68259d4 100644 --- a/leptos_reactive/Cargo.toml +++ b/leptos_reactive/Cargo.toml @@ -30,5 +30,4 @@ tokio-test = "0.4" [features] csr = ["dep:wasm-bindgen", "dep:wasm-bindgen-futures", "dep:web-sys"] hydrate = ["dep:base64", "dep:js-sys", "dep:serde-wasm-bindgen", "dep:serde_json", "dep:wasm-bindgen", "dep:wasm-bindgen-futures", "dep:web-sys"] -ssr = ["dep:base64", "dep:serde_json", "dep:tokio"] -transition = [] \ No newline at end of file +ssr = ["dep:base64", "dep:serde_json", "dep:tokio"] \ No newline at end of file diff --git a/leptos_reactive/src/effect.rs b/leptos_reactive/src/effect.rs index 3609a1718..82210b73e 100644 --- a/leptos_reactive/src/effect.rs +++ b/leptos_reactive/src/effect.rs @@ -234,16 +234,6 @@ where self.runtime.push_stack(Subscriber(id)); // actually run the effect - #[cfg(feature = "transition")] - if let Some(transition) = self.runtime.running_transition() && self.render_effect { - transition.effects.borrow_mut().push(id); - } else { - let curr = { self.value.borrow_mut().take() }; - let v = { (self.f.borrow_mut())(curr) }; - *self.value.borrow_mut() = Some(v); - } - - #[cfg(not(feature = "transition"))] { let curr = { self.value.borrow_mut().take() }; let v = { (self.f.borrow_mut())(curr) }; diff --git a/leptos_reactive/src/runtime.rs b/leptos_reactive/src/runtime.rs index db3dfbd29..79ad5d943 100644 --- a/leptos_reactive/src/runtime.rs +++ b/leptos_reactive/src/runtime.rs @@ -1,5 +1,3 @@ -#[cfg(feature = "transition")] -use crate::TransitionState; use crate::{ debug_warn, AnyEffect, AnySignal, EffectId, ResourceId, ResourceState, Scope, ScopeDisposer, ScopeId, ScopeState, SignalId, SignalState, StreamingResourceId, Subscriber, @@ -18,8 +16,6 @@ pub(crate) struct Runtime { pub(crate) shared_context: RefCell>, pub(crate) stack: RefCell>, pub(crate) scopes: RefCell>>, - #[cfg(feature = "transition")] - pub(crate) transition: RefCell>>, } #[derive(Error, Debug)] @@ -142,22 +138,6 @@ impl Runtime { self.stack.borrow().last().cloned() } - #[cfg(feature = "transition")] - pub fn running_transition(&self) -> Option> { - self.transition.borrow().as_ref().and_then(|t| { - if t.running.get() { - Some(Rc::clone(t)) - } else { - None - } - }) - } - - #[cfg(feature = "transition")] - pub fn transition(&self) -> Option> { - self.transition.borrow().as_ref().map(Rc::clone) - } - pub fn create_scope( &'static self, f: impl FnOnce(Scope), diff --git a/leptos_reactive/src/scope.rs b/leptos_reactive/src/scope.rs index 1c494412c..ce57ed65d 100644 --- a/leptos_reactive/src/scope.rs +++ b/leptos_reactive/src/scope.rs @@ -73,11 +73,6 @@ impl Scope { self.runtime.create_scope(f, Some(self)) } - #[cfg(feature = "transition")] - pub fn transition_pending(&self) -> bool { - self.runtime.transition().is_some() - } - pub fn untrack(&self, f: impl FnOnce() -> T) -> T { self.runtime.untrack(f) } diff --git a/leptos_reactive/src/signal.rs b/leptos_reactive/src/signal.rs index e11530c66..c36ce998e 100644 --- a/leptos_reactive/src/signal.rs +++ b/leptos_reactive/src/signal.rs @@ -172,31 +172,6 @@ where }); } - // If transition is running, or contains this as a source, take from t_value - #[cfg(feature = "transition")] - if let Some(transition) = self.runtime.transition() { - self.runtime - .signal((self.scope, self.id), |signal_state: &SignalState| { - if transition.running.get() - && transition.signals.borrow().contains(&(self.scope, self.id)) - { - f(signal_state - .t_value - .borrow() - .as_ref() - .expect("read ReadSignal under transition, without any t_value")) - } else { - f(&signal_state.value.borrow()) - } - }) - } else { - self.runtime - .signal((self.scope, self.id), |signal_state: &SignalState| { - (f)(&signal_state.value.borrow()) - }) - } - - #[cfg(not(feature = "transition"))] self.runtime .signal((self.scope, self.id), |signal_state: &SignalState| { (f)(&signal_state.value.borrow()) @@ -325,29 +300,6 @@ where self.runtime .signal((self.scope, self.id), |signal_state: &SignalState| { // update value - - #[cfg(feature = "transition")] - 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 { - (f)(t_value); - } else { - // fork reality, using the old value as the basis for the transitional value - let mut forked = (*signal_state.value.borrow()).clone(); - (f)(&mut forked); - *t_value = Some(forked); - - // track this signal - transition - .signals - .borrow_mut() - .insert((self.scope, self.id)); - } - } else { - (f)(&mut *signal_state.value.borrow_mut()); - } - - #[cfg(not(feature = "transition"))] (f)(&mut *signal_state.value.borrow_mut()); // notify subscribers @@ -417,8 +369,6 @@ pub(crate) struct SignalId(pub(crate) usize); //#[derive(Debug)] pub(crate) struct SignalState { value: RefCell, - #[cfg(feature = "transition")] - t_value: RefCell>, subscribers: RefCell>, } @@ -426,16 +376,6 @@ impl Debug for SignalState where T: Debug, { - #[cfg(feature = "transition")] - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - f.debug_struct("SignalState") - .field("value", &*self.value.borrow()) - .field("t_value", &*self.t_value.borrow()) - .field("subscribers", &*self.subscribers.borrow()) - .finish() - } - - #[cfg(not(feature = "transition"))] fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { f.debug_struct("SignalState") .field("value", &*self.value.borrow()) @@ -451,8 +391,6 @@ where pub fn new(value: T) -> Self { Self { value: RefCell::new(value), - #[cfg(feature = "transition")] - t_value: Default::default(), subscribers: Default::default(), } } @@ -462,9 +400,6 @@ pub(crate) trait AnySignal: Debug { fn unsubscribe(&self, subscriber: Subscriber); fn as_any(&self) -> &dyn Any; - - #[cfg(feature = "transition")] - fn end_transition(&self, runtime: &'static Runtime); } impl AnySignal for SignalState @@ -478,27 +413,4 @@ where fn as_any(&self) -> &dyn Any { self } - - #[cfg(feature = "transition")] - fn end_transition(&self, runtime: &'static Runtime) { - let t_value = self.t_value.borrow_mut().take(); - - if let Some(value) = t_value { - *self.value.borrow_mut() = value; - - let subs = { self.subscribers.borrow().clone() }; - - // run all its subscribers; if any of them are from scopes that have - // been disposed, unsubscribe them - let mut dropped_subs = Vec::new(); - for subscriber in subs.iter() { - if subscriber.try_run(runtime).is_err() { - dropped_subs.push(subscriber); - } - } - for sub in dropped_subs { - self.subscribers.borrow_mut().remove(sub); - } - } - } } diff --git a/leptos_reactive/src/transition.rs b/leptos_reactive/src/transition.rs deleted file mode 100644 index 0669cea33..000000000 --- a/leptos_reactive/src/transition.rs +++ /dev/null @@ -1,96 +0,0 @@ -use std::{ - cell::{Cell, RefCell}, - collections::HashSet, - rc::Rc, -}; - -use crate::{ - create_effect, create_signal, runtime::Runtime, spawn::queue_microtask, EffectId, ReadSignal, - Scope, ScopeId, SignalId, WriteSignal, -}; - -pub fn use_transition(cx: Scope) -> Transition { - let (pending, set_pending) = create_signal(cx, false); - Transition { - runtime: cx.runtime, - scope: cx, - pending, - set_pending, - } -} - -#[derive(Copy, Clone)] -pub struct Transition { - runtime: &'static Runtime, - scope: Scope, - pending: ReadSignal, - set_pending: WriteSignal, -} - -impl Transition { - pub fn start(&self, f: impl FnOnce()) { - if self.runtime.running_transition().is_some() { - f(); - } else { - { - self.set_pending.update(|n| *n = true); - *self.runtime.transition.borrow_mut() = Some(Rc::new(TransitionState { - running: Cell::new(true), - resources: Default::default(), - signals: Default::default(), - effects: Default::default(), - })); - } - - f(); - - if let Some(running_transition) = self.runtime.running_transition() { - running_transition.running.set(false); - - let runtime = self.runtime; - let scope = self.scope; - let resources = running_transition.resources.clone(); - let signals = running_transition.signals.clone(); - let effects = running_transition.effects.clone(); - let set_pending = self.set_pending; - - // place this at end of task queue so it doesn't start at 0 - queue_microtask(move || { - create_effect(scope, move |_| { - let pending = resources.borrow().iter().map(|p| p.get()).sum::(); - - if pending == 0 { - log::debug!("[Transition] transition complete"); - for signal in signals.borrow().iter() { - log::debug!("[Transition] deferred signal"); - runtime.any_signal(*signal, |signal| { - signal.end_transition(runtime); - }); - } - for effect in effects.borrow().iter() { - log::debug!("[Transition] running deferred effect"); - runtime.any_effect(*effect, |any_effect| { - any_effect.run(*effect); - }); - } - log::debug!("[Transition] setting pending to false"); - set_pending.update(|n| *n = false); - } - }); - }); - } - } - } - - pub fn pending(&self) -> bool { - self.pending.get() - } -} - -#[derive(Debug)] -pub(crate) struct TransitionState { - pub running: Cell, - pub resources: Rc>>>, - pub signals: Rc>>, - pub effects: Rc>>, -}