diff --git a/demo_markdown/docs/menu/mod.md b/demo_markdown/docs/menu/mod.md index 10617ac..c6dc31b 100644 --- a/demo_markdown/docs/menu/mod.md +++ b/demo_markdown/docs/menu/mod.md @@ -1,11 +1,10 @@ # Menu ```rust demo +let toaster = ToasterInjection::expect_context(); - -let on_select = |key: String| { +let on_select = move |key: String| { leptos::logging::warn!("{}", key); - let toaster = ToasterInjection::expect_context(); toaster.dispatch_toast(view! { diff --git a/demo_markdown/docs/toast/mod.md b/demo_markdown/docs/toast/mod.md index 11c4a78..e1e2fab 100644 --- a/demo_markdown/docs/toast/mod.md +++ b/demo_markdown/docs/toast/mod.md @@ -30,9 +30,9 @@ view! { ### Toast Positions ```rust demo -fn dispatch_toast(position: ToastPosition) { - let toaster = ToasterInjection::expect_context(); +let toaster = ToasterInjection::expect_context(); +fn dispatch_toast(toaster: ToasterInjection, position: ToastPosition) { toaster.dispatch_toast(view! { "Email sent" @@ -53,12 +53,12 @@ fn dispatch_toast(position: ToastPosition) { view! { - - - - - - + + + + + + } ``` diff --git a/thaw/src/toast/mod.rs b/thaw/src/toast/mod.rs index ffd399b..95d1f81 100644 --- a/thaw/src/toast/mod.rs +++ b/thaw/src/toast/mod.rs @@ -16,10 +16,10 @@ use std::sync::mpsc::{channel, Receiver, Sender, TryIter}; use tachys::view::any_view::AnyView; use wasm_bindgen::UnwrapThrowExt; -#[derive(Clone)] +#[derive(Clone, Copy)] pub struct ToasterInjection { - sender: Sender<(AnyView, ToastOptions)>, - trigger: ArcTrigger, + sender: StoredValue, ToastOptions)>>, + trigger: StoredValue, } impl ToasterInjection { @@ -33,16 +33,17 @@ impl ToasterInjection { ( Self { - sender, - trigger: trigger.clone(), + sender: StoredValue::new(sender), + trigger: StoredValue::new(trigger.clone()), }, ToasterReceiver::new(receiver, trigger), ) } pub fn dispatch_toast(&self, any_view: AnyView, options: ToastOptions) { - self.sender.send((any_view, options)).unwrap_throw(); - self.trigger.trigger(); + self.sender + .with_value(|sender| sender.send((any_view, options)).unwrap_throw()); + self.trigger.with_value(|trigger| trigger.trigger()); } }