bin: Use associated types in views

This commit is contained in:
Erik Kundt
2024-04-24 13:26:27 +02:00
parent 166add7780
commit 0c628a2a44
6 changed files with 56 additions and 23 deletions
+3 -1
View File
@@ -210,7 +210,9 @@ pub enum Action {
ScrollHelp { progress: usize },
}
impl store::State<Action, Selection> for State {
impl store::State<Selection> for State {
type Action = Action;
fn tick(&self) {}
fn handle_action(&mut self, action: Action) -> Option<Exit<Selection>> {
+15 -6
View File
@@ -119,10 +119,13 @@ pub struct BrowsePage<'a, B> {
shortcuts: BoxedWidget<B>,
}
impl<'a: 'static, B> View<State, Action> for BrowsePage<'a, B>
impl<'a: 'static, B> View for BrowsePage<'a, B>
where
B: Backend + 'a,
{
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self {
let props = BrowsePageProps::from(state);
let name = match state.mode.repository() {
@@ -327,7 +330,7 @@ impl<'a, B: Backend> BrowsePage<'a, B> {
}
}
impl<'a: 'static, B> Widget<B, State, Action> for BrowsePage<'a, B>
impl<'a: 'static, B> Widget<B> for BrowsePage<'a, B>
where
B: Backend + 'a,
{
@@ -396,7 +399,10 @@ pub struct Search<B: Backend> {
input: BoxedWidget<B>,
}
impl<B: Backend> View<State, Action> for Search<B> {
impl<B: Backend> View for Search<B> {
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self
where
Self: Sized,
@@ -453,7 +459,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
}
}
impl<B> Widget<B, State, Action> for Search<B>
impl<B> Widget<B> for Search<B>
where
B: Backend,
{
@@ -501,10 +507,13 @@ where
shortcuts: BoxedWidget<B>,
}
impl<'a: 'static, B> View<State, Action> for HelpPage<'a, B>
impl<'a: 'static, B> View for HelpPage<'a, B>
where
B: Backend + 'a,
{
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self
where
Self: Sized,
@@ -604,7 +613,7 @@ where
}
}
impl<'a: 'static, B> Widget<B, State, Action> for HelpPage<'a, B>
impl<'a: 'static, B> Widget<B> for HelpPage<'a, B>
where
B: Backend + 'a,
{
+4 -2
View File
@@ -129,8 +129,8 @@ pub enum Action {
ScrollHelp { progress: usize },
}
impl store::State<Action, Selection> for State {
fn tick(&self) {}
impl store::State<Selection> for State {
type Action = Action;
fn handle_action(&mut self, action: Action) -> Option<Exit<Selection>> {
match action {
@@ -185,6 +185,8 @@ impl store::State<Action, Selection> for State {
}
}
}
fn tick(&self) {}
}
impl App {
+15 -6
View File
@@ -133,10 +133,13 @@ pub struct BrowsePage<'a, B> {
shortcuts: BoxedWidget<B>,
}
impl<'a: 'static, B> View<State, Action> for BrowsePage<'a, B>
impl<'a: 'static, B> View for BrowsePage<'a, B>
where
B: Backend + 'a,
{
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self {
let props = BrowsePageProps::from(state);
@@ -346,7 +349,7 @@ impl<'a, B: Backend> BrowsePage<'a, B> {
}
}
impl<'a: 'static, B> Widget<B, State, Action> for BrowsePage<'a, B>
impl<'a: 'static, B> Widget<B> for BrowsePage<'a, B>
where
B: Backend + 'a,
{
@@ -415,7 +418,10 @@ pub struct Search<B: Backend> {
input: BoxedWidget<B>,
}
impl<B: Backend> View<State, Action> for Search<B> {
impl<B: Backend> View for Search<B> {
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self
where
Self: Sized,
@@ -472,7 +478,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
}
}
impl<B> Widget<B, State, Action> for Search<B>
impl<B> Widget<B> for Search<B>
where
B: Backend,
{
@@ -520,10 +526,13 @@ where
shortcuts: BoxedWidget<B>,
}
impl<'a: 'static, B> View<State, Action> for HelpPage<'a, B>
impl<'a: 'static, B> View for HelpPage<'a, B>
where
B: Backend + 'a,
{
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self
where
Self: Sized,
@@ -623,7 +632,7 @@ where
}
}
impl<'a: 'static, B> Widget<B, State, Action> for HelpPage<'a, B>
impl<'a: 'static, B> Widget<B> for HelpPage<'a, B>
where
B: Backend + 'a,
{
+4 -2
View File
@@ -134,8 +134,8 @@ pub enum Action {
ScrollHelp { progress: usize },
}
impl store::State<Action, Selection> for State {
fn tick(&self) {}
impl store::State<Selection> for State {
type Action = Action;
fn handle_action(&mut self, action: Action) -> Option<Exit<Selection>> {
match action {
@@ -190,6 +190,8 @@ impl store::State<Action, Selection> for State {
}
}
}
fn tick(&self) {}
}
impl App {
+15 -6
View File
@@ -134,10 +134,13 @@ pub struct BrowsePage<'a, B> {
shortcuts: BoxedWidget<B>,
}
impl<'a: 'static, B> View<State, Action> for BrowsePage<'a, B>
impl<'a: 'static, B> View for BrowsePage<'a, B>
where
B: Backend + 'a,
{
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self {
let props = BrowsePageProps::from(state);
@@ -374,7 +377,7 @@ impl<'a, B: Backend> BrowsePage<'a, B> {
}
}
impl<'a: 'static, B> Widget<B, State, Action> for BrowsePage<'a, B>
impl<'a: 'static, B> Widget<B> for BrowsePage<'a, B>
where
B: Backend + 'a,
{
@@ -443,7 +446,10 @@ pub struct Search<B: Backend> {
input: BoxedWidget<B>,
}
impl<B: Backend> View<State, Action> for Search<B> {
impl<B: Backend> View for Search<B> {
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self
where
Self: Sized,
@@ -500,7 +506,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
}
}
impl<B> Widget<B, State, Action> for Search<B>
impl<B> Widget<B> for Search<B>
where
B: Backend,
{
@@ -548,10 +554,13 @@ where
shortcuts: BoxedWidget<B>,
}
impl<'a: 'static, B> View<State, Action> for HelpPage<'a, B>
impl<'a: 'static, B> View for HelpPage<'a, B>
where
B: Backend + 'a,
{
type Action = Action;
type State = State;
fn new(state: &State, action_tx: UnboundedSender<Action>) -> Self
where
Self: Sized,
@@ -651,7 +660,7 @@ where
}
}
impl<'a: 'static, B> Widget<B, State, Action> for HelpPage<'a, B>
impl<'a: 'static, B> Widget<B> for HelpPage<'a, B>
where
B: Backend + 'a,
{