Draft widget nodes and wire interaction
This commit is contained in:
parent
27ac85a9d9
commit
8834772fa7
10 changed files with 223 additions and 22 deletions
40
web/src/bus.rs
Normal file
40
web/src/bus.rs
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
use crate::Application;
|
||||
|
||||
use std::rc::Rc;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Bus<Message> {
|
||||
publish: Rc<Box<dyn Fn(Message, &mut dyn dodrio::RootRender)>>,
|
||||
}
|
||||
|
||||
impl<Message> Bus<Message>
|
||||
where
|
||||
Message: 'static,
|
||||
{
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
publish: Rc::new(Box::new(|message, root| {
|
||||
let app = root.unwrap_mut::<Application<Message>>();
|
||||
|
||||
app.update(message)
|
||||
})),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn publish(&self, message: Message, root: &mut dyn dodrio::RootRender) {
|
||||
(self.publish)(message, root);
|
||||
}
|
||||
|
||||
pub fn map<B>(&self, mapper: Rc<Box<dyn Fn(B) -> Message>>) -> Bus<B>
|
||||
where
|
||||
B: 'static,
|
||||
{
|
||||
let publish = self.publish.clone();
|
||||
|
||||
Bus {
|
||||
publish: Rc::new(Box::new(move |message, root| {
|
||||
publish(mapper(message), root)
|
||||
})),
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue