Write docs for iced_web

This commit is contained in:
Héctor Ramón Jiménez 2019-11-22 22:14:04 +01:00
parent 048909b45d
commit fa227255b0
10 changed files with 225 additions and 17 deletions

View file

@ -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,