mirror of
https://github.com/adoyle0/thaw.git
synced 2025-01-22 22:09:22 -05:00
fix: ToasterInjection supports Copy
This commit is contained in:
parent
c9c8e34143
commit
a242b307af
3 changed files with 18 additions and 18 deletions
|
@ -1,11 +1,10 @@
|
|||
# Menu
|
||||
|
||||
```rust demo
|
||||
|
||||
|
||||
let on_select = |key: String| {
|
||||
leptos::logging::warn!("{}", key);
|
||||
let toaster = ToasterInjection::expect_context();
|
||||
|
||||
let on_select = move |key: String| {
|
||||
leptos::logging::warn!("{}", key);
|
||||
toaster.dispatch_toast(view! {
|
||||
<Toast>
|
||||
<ToastBody>
|
||||
|
|
|
@ -30,9 +30,9 @@ view! {
|
|||
### Toast Positions
|
||||
|
||||
```rust demo
|
||||
fn dispatch_toast(position: ToastPosition) {
|
||||
let toaster = ToasterInjection::expect_context();
|
||||
|
||||
fn dispatch_toast(toaster: ToasterInjection, position: ToastPosition) {
|
||||
toaster.dispatch_toast(view! {
|
||||
<Toast>
|
||||
<ToastTitle>"Email sent"</ToastTitle>
|
||||
|
@ -53,12 +53,12 @@ fn dispatch_toast(position: ToastPosition) {
|
|||
|
||||
view! {
|
||||
<Space>
|
||||
<Button on_click=move |_| dispatch_toast(ToastPosition::Bottom)>"Bottom"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(ToastPosition::BottomStart)>"BottomStart"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(ToastPosition::BottomEnd)>"BottomEnd"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(ToastPosition::Top)>"Top"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(ToastPosition::TopStart)>"Topstart"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(ToastPosition::TopEnd)>"TopEnd"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::Bottom)>"Bottom"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::BottomStart)>"BottomStart"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::BottomEnd)>"BottomEnd"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::Top)>"Top"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::TopStart)>"Topstart"</Button>
|
||||
<Button on_click=move |_| dispatch_toast(toaster, ToastPosition::TopEnd)>"TopEnd"</Button>
|
||||
</Space>
|
||||
}
|
||||
```
|
||||
|
|
|
@ -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<Dom>, ToastOptions)>,
|
||||
trigger: ArcTrigger,
|
||||
sender: StoredValue<Sender<(AnyView<Dom>, ToastOptions)>>,
|
||||
trigger: StoredValue<ArcTrigger>,
|
||||
}
|
||||
|
||||
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<Dom>, 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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue