mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-10-30 16:30:56 +08:00
bin: Improve update callback usage
This commit is contained in:
@@ -57,7 +57,7 @@ pub struct Window<B: Backend> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// All pages known
|
||||
pages: HashMap<Page, BoxedWidget<B>>,
|
||||
}
|
||||
@@ -84,7 +84,7 @@ where
|
||||
),
|
||||
]),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,8 +93,8 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -211,7 +211,7 @@ struct BrowsePage<'a, B> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Notifications widget
|
||||
notifications: BoxedWidget<B>,
|
||||
/// Search widget
|
||||
@@ -251,7 +251,7 @@ where
|
||||
)
|
||||
.content(Box::<Table<State, Action, NotificationItem>>::new(
|
||||
Table::new(state, action_tx.clone())
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<TableState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::Select {
|
||||
@@ -287,12 +287,12 @@ where
|
||||
search: Search::new(state, action_tx.clone()).to_boxed(),
|
||||
shortcuts: Shortcuts::new(state, action_tx.clone()).to_boxed(),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -302,8 +302,8 @@ where
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &State) {
|
||||
// TODO call mapper here instead?
|
||||
self.props = BrowsePageProps::from(state);
|
||||
self.props = BrowsePageProps::from_callback(self.on_update, state)
|
||||
.unwrap_or(BrowsePageProps::from(state));
|
||||
|
||||
self.notifications.update(state);
|
||||
self.search.update(state);
|
||||
@@ -504,7 +504,7 @@ pub struct Search<B: Backend> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Search input field
|
||||
input: BoxedWidget<B>,
|
||||
}
|
||||
@@ -515,7 +515,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
Self: Sized,
|
||||
{
|
||||
let input = TextField::new(state, action_tx.clone())
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<TextFieldState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::UpdateSearch {
|
||||
@@ -536,7 +536,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
action_tx,
|
||||
input,
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -545,8 +545,8 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -614,7 +614,7 @@ where
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Content widget
|
||||
content: BoxedWidget<B>,
|
||||
/// Shortcut widget
|
||||
@@ -656,7 +656,7 @@ where
|
||||
.focus(props.focus)
|
||||
.to_boxed()
|
||||
})
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<ParagraphState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::ScrollHelp {
|
||||
@@ -692,7 +692,7 @@ where
|
||||
.to_boxed(),
|
||||
shortcuts: Shortcuts::new(state, action_tx.clone()).to_boxed(),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,13 +701,14 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &State) {
|
||||
self.props = HelpPageProps::from(state);
|
||||
self.props = HelpPageProps::from_callback(self.on_update, state)
|
||||
.unwrap_or(HelpPageProps::from(state));
|
||||
|
||||
self.content.update(state);
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ pub struct Window<B: Backend> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// All pages known
|
||||
pages: HashMap<Page, BoxedWidget<B>>,
|
||||
}
|
||||
@@ -87,7 +87,7 @@ where
|
||||
),
|
||||
]),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,8 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -225,7 +225,7 @@ struct BrowsePage<'a, B> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Patches widget
|
||||
issues: BoxedWidget<B>,
|
||||
/// Search widget
|
||||
@@ -254,7 +254,7 @@ where
|
||||
)
|
||||
.content(Box::<Table<State, Action, IssueItem>>::new(
|
||||
Table::new(state, action_tx.clone())
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<TableState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::Select {
|
||||
@@ -290,7 +290,7 @@ where
|
||||
search: Search::new(state, action_tx.clone()).to_boxed(),
|
||||
shortcuts: Shortcuts::new(state, action_tx.clone()).to_boxed(),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -299,14 +299,14 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &State) {
|
||||
// TODO call mapper here instead?
|
||||
self.props = BrowsePageProps::from(state);
|
||||
self.props = BrowsePageProps::from_callback(self.on_update, state)
|
||||
.unwrap_or(BrowsePageProps::from(state));
|
||||
|
||||
self.issues.update(state);
|
||||
self.search.update(state);
|
||||
@@ -529,7 +529,7 @@ pub struct Search<B: Backend> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Search input field
|
||||
input: BoxedWidget<B>,
|
||||
}
|
||||
@@ -540,7 +540,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
Self: Sized,
|
||||
{
|
||||
let input = TextField::new(state, action_tx.clone())
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<TextFieldState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::UpdateSearch {
|
||||
@@ -561,7 +561,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
action_tx,
|
||||
input,
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -570,8 +570,8 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -639,7 +639,7 @@ where
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Content widget
|
||||
content: BoxedWidget<B>,
|
||||
/// Shortcut widget
|
||||
@@ -681,7 +681,7 @@ where
|
||||
.focus(props.focus)
|
||||
.to_boxed()
|
||||
})
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<ParagraphState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::ScrollHelp {
|
||||
@@ -717,7 +717,7 @@ where
|
||||
.to_boxed(),
|
||||
shortcuts: Shortcuts::new(state, action_tx.clone()).to_boxed(),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -726,13 +726,14 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &State) {
|
||||
self.props = HelpPageProps::from(state);
|
||||
self.props = HelpPageProps::from_callback(self.on_update, state)
|
||||
.unwrap_or(HelpPageProps::from(state));
|
||||
|
||||
self.content.update(state);
|
||||
}
|
||||
|
||||
@@ -62,7 +62,7 @@ pub struct Window<B: Backend> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// All pages known
|
||||
pages: HashMap<Page, BoxedWidget<B>>,
|
||||
}
|
||||
@@ -89,7 +89,7 @@ where
|
||||
),
|
||||
]),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,8 +98,8 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -226,7 +226,7 @@ struct BrowsePage<'a, B> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Patches widget
|
||||
patches: BoxedWidget<B>,
|
||||
/// Search widget
|
||||
@@ -255,7 +255,7 @@ where
|
||||
)
|
||||
.content(Box::<Table<State, Action, PatchItem>>::new(
|
||||
Table::new(state, action_tx.clone())
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<TableState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::Select {
|
||||
@@ -291,7 +291,7 @@ where
|
||||
search: Search::new(state, action_tx.clone()).to_boxed(),
|
||||
shortcuts: Shortcuts::new(state, action_tx.clone()).to_boxed(),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -300,14 +300,14 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &State) {
|
||||
// TODO call mapper here instead?
|
||||
self.props = BrowsePageProps::from(state);
|
||||
self.props = BrowsePageProps::from_callback(self.on_update, state)
|
||||
.unwrap_or(BrowsePageProps::from(state));
|
||||
|
||||
self.patches.update(state);
|
||||
self.search.update(state);
|
||||
@@ -561,7 +561,7 @@ pub struct Search<B: Backend> {
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Search input field
|
||||
input: BoxedWidget<B>,
|
||||
}
|
||||
@@ -572,7 +572,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
Self: Sized,
|
||||
{
|
||||
let input = TextField::new(state, action_tx.clone())
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<TextFieldState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::UpdateSearch {
|
||||
@@ -593,7 +593,7 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
action_tx,
|
||||
input,
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -602,8 +602,8 @@ impl<B: Backend> View<State, Action> for Search<B> {
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
@@ -671,7 +671,7 @@ where
|
||||
/// Custom update handler
|
||||
on_update: Option<UpdateCallback<State>>,
|
||||
/// Additional custom event handler
|
||||
on_change: Option<EventCallback<Action>>,
|
||||
on_event: Option<EventCallback<Action>>,
|
||||
/// Content widget
|
||||
content: BoxedWidget<B>,
|
||||
/// Shortcut widget
|
||||
@@ -713,7 +713,7 @@ where
|
||||
.focus(props.focus)
|
||||
.to_boxed()
|
||||
})
|
||||
.on_change(|state, action_tx| {
|
||||
.on_event(|state, action_tx| {
|
||||
state.downcast_ref::<ParagraphState>().and_then(|state| {
|
||||
action_tx
|
||||
.send(Action::ScrollHelp {
|
||||
@@ -749,7 +749,7 @@ where
|
||||
.to_boxed(),
|
||||
shortcuts: Shortcuts::new(state, action_tx.clone()).to_boxed(),
|
||||
on_update: None,
|
||||
on_change: None,
|
||||
on_event: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -758,13 +758,14 @@ where
|
||||
self
|
||||
}
|
||||
|
||||
fn on_change(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_change = Some(callback);
|
||||
fn on_event(mut self, callback: EventCallback<Action>) -> Self {
|
||||
self.on_event = Some(callback);
|
||||
self
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &State) {
|
||||
self.props = HelpPageProps::from(state);
|
||||
self.props = HelpPageProps::from_callback(self.on_update, state)
|
||||
.unwrap_or(HelpPageProps::from(state));
|
||||
|
||||
self.content.update(state);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user