use crate::Instance; use std::rc::Rc; #[derive(Clone)] pub struct Bus { publish: Rc>, } impl Bus where Message: 'static, { pub fn new() -> Self { Self { publish: Rc::new(Box::new(|message, root| { let app = root.unwrap_mut::>(); app.update(message) })), } } pub fn publish(&self, message: Message, root: &mut dyn dodrio::RootRender) { (self.publish)(message, root); } pub fn map(&self, mapper: Rc Message>>) -> Bus where B: 'static, { let publish = self.publish.clone(); Bus { publish: Rc::new(Box::new(move |message, root| { publish(mapper(message), root) })), } } }