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.rs15
1 files changed, 14 insertions, 1 deletions
diff --git a/web/src/bus.rs b/web/src/bus.rs
index b4fd67c7..09908679 100644
--- a/web/src/bus.rs
+++ b/web/src/bus.rs
@@ -2,6 +2,12 @@ use crate::Instance;
use std::rc::Rc;
+/// A publisher of messages.
+///
+/// It can be used to route messages back to the [`Application`].
+///
+/// [`Application`]: trait.Application.html
+#[allow(missing_debug_implementations)]
#[derive(Clone)]
pub struct Bus<Message> {
publish: Rc<Box<dyn Fn(Message, &mut dyn dodrio::RootRender)>>,
@@ -11,7 +17,7 @@ impl<Message> Bus<Message>
where
Message: 'static,
{
- pub fn new() -> Self {
+ pub(crate) fn new() -> Self {
Self {
publish: Rc::new(Box::new(|message, root| {
let app = root.unwrap_mut::<Instance<Message>>();
@@ -21,10 +27,17 @@ 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);
}
+ /// Creates a new [`Bus`] that applies the given function to the messages
+ /// before publishing.
+ ///
+ /// [`Bus`]: struct.Bus.html
pub fn map<B>(&self, mapper: Rc<Box<dyn Fn(B) -> Message>>) -> Bus<B>
where
B: 'static,