summaryrefslogtreecommitdiffstats
path: root/web/src/bus.rs
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/bus.rs')
-rw-r--r--web/src/bus.rs32
1 files changed, 17 insertions, 15 deletions
diff --git a/web/src/bus.rs b/web/src/bus.rs
index 1b650b28..c66e9659 100644
--- a/web/src/bus.rs
+++ b/web/src/bus.rs
@@ -1,5 +1,4 @@
-use crate::Instance;
-
+use iced_futures::futures::channel::mpsc;
use std::rc::Rc;
/// A publisher of messages.
@@ -8,21 +7,26 @@ use std::rc::Rc;
///
/// [`Application`]: trait.Application.html
#[allow(missing_debug_implementations)]
-#[derive(Clone)]
pub struct Bus<Message> {
- publish: Rc<Box<dyn Fn(Message, &mut dyn dodrio::RootRender)>>,
+ publish: Rc<Box<dyn Fn(Message) -> ()>>,
+}
+
+impl<Message> Clone for Bus<Message> {
+ fn clone(&self) -> Self {
+ Bus {
+ publish: self.publish.clone(),
+ }
+ }
}
impl<Message> Bus<Message>
where
- Message: 'static + Clone,
+ Message: 'static,
{
- pub(crate) fn new() -> Self {
+ pub(crate) fn new(publish: mpsc::UnboundedSender<Message>) -> Self {
Self {
- publish: Rc::new(Box::new(|message, root| {
- let app = root.unwrap_mut::<Instance<Message>>();
-
- app.update(message)
+ publish: Rc::new(Box::new(move |message| {
+ publish.unbounded_send(message).expect("Send message");
})),
}
}
@@ -30,8 +34,8 @@ where
/// Publishes a new message for the [`Application`].
///
/// [`Application`]: trait.Application.html
- pub fn publish(&self, message: Message, root: &mut dyn dodrio::RootRender) {
- (self.publish)(message, root);
+ pub fn publish(&self, message: Message) {
+ (self.publish)(message)
}
/// Creates a new [`Bus`] that applies the given function to the messages
@@ -45,9 +49,7 @@ where
let publish = self.publish.clone();
Bus {
- publish: Rc::new(Box::new(move |message, root| {
- publish(mapper(message), root)
- })),
+ publish: Rc::new(Box::new(move |message| publish(mapper(message)))),
}
}
}