Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux refactor #3

Merged
merged 20 commits into from
Jan 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 5 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "tezedge-tui"
description = "A terminal user interface for Tezedge"
version = "0.1.0"
authors = ["Adrian Nagy <adrian.nagy@viablesystems.io>"]
edition = "2018"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

Expand All @@ -29,3 +29,7 @@ slog-term = "2.8"
strum = "0.23"
strum_macros = "0.23"
num = "0.4"
redux-rs = { git = "https://github.com/tezedge/redux-rs.git", tag = "tezedge-v1.11.0", features = ["serde"] }
async-trait = "0.1"
enum-kinds = "0.5.1"
derive_more = "0.99.16"
99 changes: 99 additions & 0 deletions src/automaton/action.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
use derive_more::From;
use enum_kinds::EnumKind;
pub use redux_rs::{ActionId, EnablingCondition};

use crate::{
endorsements::{
CurrentHeadHeaderGetAction, CurrentHeadHeaderRecievedAction, EndorsementsRightsGetAction,
EndorsementsRightsReceivedAction, EndorsementsStatusesGetAction,
EndorsementsStatusesReceivedAction,
},
operations::{OperationsStatisticsGetAction, OperationsStatisticsReceivedAction},
rpc::{RpcRequestAction, RpcResponseAction, RpcResponseReadAction},
terminal_ui::{
ChangeScreenAction, DrawScreenAction, DrawScreenFailiureAction, DrawScreenSuccessAction,
TuiDeltaToggleKeyPushedAction, TuiDownKeyPushedAction, TuiLeftKeyPushedAction,
TuiRightKeyPushedAction, TuiSortKeyPushedAction, TuiUpKeyPushedAction,
TuiWidgetSelectionKeyPushedAction,
},
websocket::{WebsocketMessageReceivedAction, WebsocketReadAction},
};

use super::State;

pub type ActionWithMeta = redux_rs::ActionWithMeta<Action>;

#[derive(Debug, Clone)]
pub struct InitAction {}

impl EnablingCondition<State> for InitAction {
fn is_enabled(&self, _: &State) -> bool {
false
}
}
#[derive(Debug, Clone)]
pub struct ShutdownAction {}

impl EnablingCondition<State> for ShutdownAction {
fn is_enabled(&self, _: &State) -> bool {
false
}
}

#[derive(EnumKind, strum_macros::AsRefStr, strum_macros::IntoStaticStr, From, Debug, Clone)]
#[enum_kind(
ActionKind,
derive(strum_macros::EnumIter, strum_macros::Display, Hash)
)]
pub enum Action {
Init(InitAction),
Shutdown(ShutdownAction),

RpcRequest(RpcRequestAction),
RpcResponse(RpcResponseAction),
RpcResponseRead(RpcResponseReadAction),

WebsocketRead(WebsocketReadAction),
WebsocketMessageReceived(WebsocketMessageReceivedAction),

EndorsementsRightsGet(EndorsementsRightsGetAction),
EndorsementsRightsReceived(EndorsementsRightsReceivedAction),
EndorsementsStatusesGet(EndorsementsStatusesGetAction),
EndorsementsStatusesReceived(EndorsementsStatusesReceivedAction),
CurrentHeadHeaderGet(CurrentHeadHeaderGetAction),
CurrentHeadHeaderReceived(CurrentHeadHeaderRecievedAction),

OperationsStatisticsGet(OperationsStatisticsGetAction),
OperationsStatisticsReceived(OperationsStatisticsReceivedAction),

ChangeScreen(ChangeScreenAction),
DrawScreen(DrawScreenAction),
DrawScreenSuccess(DrawScreenSuccessAction),
DrawScreenFailiure(DrawScreenFailiureAction),
TuiRightKeyPushed(TuiRightKeyPushedAction),
TuiLeftKeyPushed(TuiLeftKeyPushedAction),
TuiUpKeyPushedAction(TuiUpKeyPushedAction),
TuiDownKeyPushedAction(TuiDownKeyPushedAction),
TuiSortKeyPushed(TuiSortKeyPushedAction),
TuiDeltaToggleKeyPushed(TuiDeltaToggleKeyPushedAction),
TuiWidgetSelectionKeyPushed(TuiWidgetSelectionKeyPushedAction),
}

impl Action {
#[inline(always)]
pub fn kind(&self) -> ActionKind {
ActionKind::from(self)
}
}

impl<'a> From<&'a ActionWithMeta> for ActionKind {
fn from(action: &'a ActionWithMeta) -> ActionKind {
action.action.kind()
}
}

impl From<ActionWithMeta> for ActionKind {
fn from(action: ActionWithMeta) -> ActionKind {
action.action.kind()
}
}
Loading