mod direct;
mod dispatch;
mod dispatchable;
mod open;
mod routed;
mod stateful;
mod stateless;
use direct::Direct;
use dispatch::Dispatch;
use routed::Routed;
pub use open::*;
pub use stateful::*;
pub use stateless::*;
use crate::{ActionContext, Handler};
#[derive(Clone)]
pub enum System<Status, State> {
Direct(Direct<Status, State>),
Dispatch(Dispatch<Status, State>),
Routed(Routed<Status, State>),
}
impl<Status, State> System<Status, State>
where
State: Clone + Send + Sync + 'static,
{
pub fn on_frame<ActionHandler, Args>(self, action: ActionHandler) -> Self
where
ActionHandler: Handler<Args, State> + Clone + Send + Sync + 'static,
Args: Clone + Send + Sync + 'static,
{
match self {
Self::Direct(system) => Self::Direct(system.on_frame(action)),
_ => self,
}
}
pub fn on<ActionHandler, Args>(self, pattern: impl AsRef<str>, action: ActionHandler) -> Self
where
ActionHandler: Handler<Args, State> + Clone + Send + Sync + 'static,
Args: Clone + Send + Sync + 'static,
{
match self {
Self::Dispatch(system) => Self::Dispatch(system.on(pattern, action)),
Self::Routed(system) => Self::Routed(system.on(pattern, action)),
_ => self,
}
}
pub fn routes(&self) -> Option<Vec<String>> {
match self {
Self::Routed(system) => Some(system.routes()),
_ => None,
}
}
pub fn action_context(&self) -> ActionContext<State> {
match self {
Self::Direct(system) => system.action_context(),
Self::Dispatch(system) => system.action_context(),
Self::Routed(system) => system.action_context(),
}
}
}