use tokio::sync::mpsc;
#[derive(Clone)]
pub struct Navigator<ID> {
pub(crate) channel: mpsc::UnboundedSender<Action<ID>>,
}
impl<ID> Navigator<ID> {
pub(crate) fn new(channel: mpsc::UnboundedSender<Action<ID>>) -> Self {
Navigator { channel }
}
pub fn push(&self, id: ID) {
self.channel
.send(Action::Push(id))
.expect("The Navigator actions channel was dropped! This is a ratapp bug.");
}
pub fn replace(&self, id: ID) {
self.channel
.send(Action::Replace(id))
.expect("The Navigator actions channel was dropped! This is a ratapp bug.");
}
pub fn back(&self) {
self.channel
.send(Action::Back)
.expect("The Navigator actions channel was dropped! This is a ratapp bug.");
}
pub fn clear(&self) {
self.channel
.send(Action::Clear)
.expect("The Navigator actions channel was dropped! This is a ratapp bug.");
}
pub fn restart(&self) {
self.channel
.send(Action::Restart)
.expect("The Navigator actions channel was dropped! This is a ratapp bug.");
}
pub fn exit(&self) {
self.channel
.send(Action::Exit)
.expect("The Navigator actions channel was dropped! This is a ratapp bug.");
}
pub fn rerender(&self) {
self.channel
.send(Action::Rerender)
.expect("The Navigator actions channel was dropped! This is a ratapp bug.");
}
}
pub(crate) enum Action<ID> {
Push(ID),
Replace(ID),
Back,
Clear,
Restart,
Exit,
Rerender,
}