#![doc = include_str!("../README.md")]
#![deny(missing_docs)]
pub(crate) use std::cell::RefCell;
pub(crate) use std::sync::Arc;
pub(crate) use std::any::TypeId;
pub(crate) use log::{info, warn, debug};
pub(crate) use downcast_rs::{Downcast, DowncastSync};
pub mod prelude {
pub use futures::channel::oneshot::channel as oneshot_channel;
pub use futures::channel::oneshot::Sender as OneshotSender;
pub use std::cell::RefCell;
pub use std::sync::Arc;
pub use crate::comp::{NodeComponent, NodeComponentSync};
pub use crate::event::{Event, EventWrapper, EventPhase};
pub use crate::node::{NodeHandler, NodeHandlerRequestRes, NodeHandlerRequest, cstore::CStoreEventHandler};
pub use crate::ctx::{OuterNodeContext, NodeContext};
pub use crate::Backbone;
}
pub use log;
pub use futures;
pub use downcast_rs;
pub mod comp;
pub mod event;
pub mod node;
pub mod thunk;
pub mod ctx;
pub(crate) use comp::*;
pub(crate) use event::*;
pub(crate) use node::*;
pub(crate) use thunk::*;
pub(crate) use ctx::*;
pub struct Backbone {
nodes: Nodes,
thunks: Thunks,
}
impl Backbone {
pub fn from_obj<N: NodeHandler + 'static>(root_handler: N) -> Self {
let root_handler = Box::new(root_handler);
Self::from_box(root_handler)
}
pub fn from_box(root_handler: NodeHandlerBox) -> Self {
Self {
nodes: vec![NamedNodeHandlerBox {
name: "/".into(),
node: root_handler
}],
thunks: Thunks::default(),
}
}
pub fn cascade<N: NodeHandler + 'static>(self, handler: N) -> Self {
let Self { mut nodes, .. } = self;
if nodes.len() != 1 {panic!("can only cascade when the root is the sole node")}
let node = nodes.remove(0);
let handler = Box::new(handler);
Self {
nodes: vec![NamedNodeHandlerBox {
name: "/".into(),
node: Box::new(cascade::CascadingEventHandler {
outer: NamedNodeHandlerBox {
name: "/".into(),
node: handler
},
inner: node
})
}],
thunks: Thunks::default(),
}
}
}
impl<N: NodeHandler + 'static> From<N> for Backbone {
fn from(node: N) -> Self {
Self::from_obj(node)
}
}
#[allow(clippy::derivable_impls)]
impl Default for Backbone {
fn default() -> Self {
Self::from_obj(node::empty::EmptyEventHandler)
}
}
impl Backbone {
pub fn update(&mut self) -> Result<(), Box<dyn std::error::Error>> {
self.process_thunks()
}
}