diff --git a/leptos_reactive/src/signal_wrappers_read.rs b/leptos_reactive/src/signal_wrappers_read.rs index 0b7e17a494..bdab043794 100644 --- a/leptos_reactive/src/signal_wrappers_read.rs +++ b/leptos_reactive/src/signal_wrappers_read.rs @@ -1,7 +1,7 @@ use crate::{ create_isomorphic_effect, on_cleanup, runtime::untrack, store_value, Memo, - ReadSignal, RwSignal, SignalGet, SignalGetUntracked, SignalStream, - SignalWith, SignalWithUntracked, StoredValue, + ReadSignal, RwSignal, SignalDispose, SignalGet, SignalGetUntracked, + SignalStream, SignalWith, SignalWithUntracked, StoredValue, }; /// Helper trait for converting `Fn() -> T` closures into @@ -320,6 +320,16 @@ impl SignalGet for Signal { } } +impl SignalDispose for Signal { + fn dispose(self) { + match self.inner { + SignalTypes::ReadSignal(s) => s.dispose(), + SignalTypes::Memo(m) => m.dispose(), + SignalTypes::DerivedSignal(s) => s.dispose(), + } + } +} + impl SignalStream for Signal { fn to_stream(&self) -> std::pin::Pin>> { match self.inner { diff --git a/leptos_reactive/src/stored_value.rs b/leptos_reactive/src/stored_value.rs index edf97afe3e..67ed4f1bf2 100644 --- a/leptos_reactive/src/stored_value.rs +++ b/leptos_reactive/src/stored_value.rs @@ -203,6 +203,13 @@ impl StoredValue { .flatten() } + /// Disposes of the stored value + pub fn dispose(self) { + _ = with_runtime(|runtime| { + runtime.stored_values.borrow_mut().remove(self.id); + }); + } + /// Sets the stored value. /// /// # Examples