mirror of
https://seed.radicle.dev/rad:z39mP9rQAaGmERfUMPULfPUi473tY.git
synced 2026-11-12 14:40:42 +08:00
lib: Improve update callback
This commit is contained in:
+16
-10
@@ -153,11 +153,14 @@ impl<S, A> View<S, A> for Shortcuts<S, A> {
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &S) {
|
||||
if let Some(on_update) = self.on_update {
|
||||
if let Some(props) = (on_update)(state).downcast_ref::<ShortcutsProps>() {
|
||||
self.props.shortcuts = props.shortcuts.clone();
|
||||
}
|
||||
}
|
||||
self.props = self
|
||||
.on_update
|
||||
.and_then(|on_update| {
|
||||
(on_update)(state)
|
||||
.downcast_ref::<ShortcutsProps>()
|
||||
.map(|props| props.clone())
|
||||
})
|
||||
.unwrap_or(self.props.clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -407,11 +410,14 @@ where
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &S) {
|
||||
if let Some(on_update) = self.on_update {
|
||||
if let Some(props) = (on_update)(state).downcast_ref::<TableProps<'_, R>>() {
|
||||
self.props = props.clone();
|
||||
}
|
||||
}
|
||||
self.props = self
|
||||
.on_update
|
||||
.and_then(|on_update| {
|
||||
(on_update)(state)
|
||||
.downcast_ref::<TableProps<'_, R>>()
|
||||
.map(|props| props.clone())
|
||||
})
|
||||
.unwrap_or(self.props.clone());
|
||||
|
||||
// TODO: Move to state reducer
|
||||
if let Some(selected) = self.state.selected() {
|
||||
|
||||
+16
-10
@@ -102,11 +102,14 @@ impl<'a: 'static, S, A> View<S, A> for Header<'a, S, A> {
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &S) {
|
||||
if let Some(on_update) = self.on_update {
|
||||
if let Some(props) = (on_update)(state).downcast_ref::<HeaderProps>() {
|
||||
self.props = props.clone();
|
||||
}
|
||||
}
|
||||
self.props = self
|
||||
.on_update
|
||||
.and_then(|on_update| {
|
||||
(on_update)(state)
|
||||
.downcast_ref::<HeaderProps>()
|
||||
.map(|props| props.clone())
|
||||
})
|
||||
.unwrap_or(self.props.clone());
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, _key: Key) {
|
||||
@@ -267,11 +270,14 @@ impl<'a: 'static, S, A> View<S, A> for Footer<'a, S, A> {
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &S) {
|
||||
if let Some(on_update) = self.on_update {
|
||||
if let Some(props) = (on_update)(state).downcast_ref::<FooterProps>() {
|
||||
self.props = props.clone();
|
||||
}
|
||||
}
|
||||
self.props = self
|
||||
.on_update
|
||||
.and_then(|on_update| {
|
||||
(on_update)(state)
|
||||
.downcast_ref::<FooterProps>()
|
||||
.map(|props| props.clone())
|
||||
})
|
||||
.unwrap_or(self.props.clone());
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, _key: Key) {
|
||||
|
||||
@@ -151,11 +151,14 @@ impl<S, A> View<S, A> for TextField<S, A> {
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &S) {
|
||||
if let Some(on_update) = self.on_update {
|
||||
if let Some(props) = (on_update)(state).downcast_ref::<TextFieldProps>() {
|
||||
self.props = props.clone();
|
||||
}
|
||||
}
|
||||
self.props = self
|
||||
.on_update
|
||||
.and_then(|on_update| {
|
||||
(on_update)(state)
|
||||
.downcast_ref::<TextFieldProps>()
|
||||
.map(|props| props.clone())
|
||||
})
|
||||
.unwrap_or(self.props.clone());
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, key: Key) {
|
||||
|
||||
@@ -168,11 +168,14 @@ impl<'a: 'static, S, A> View<S, A> for Paragraph<'a, S, A> {
|
||||
}
|
||||
|
||||
fn update(&mut self, state: &S) {
|
||||
if let Some(on_update) = self.on_update {
|
||||
if let Some(props) = (on_update)(state).downcast_ref::<ParagraphProps>() {
|
||||
self.props = props.clone();
|
||||
}
|
||||
}
|
||||
self.props = self
|
||||
.on_update
|
||||
.and_then(|on_update| {
|
||||
(on_update)(state)
|
||||
.downcast_ref::<ParagraphProps>()
|
||||
.map(|props| props.clone())
|
||||
})
|
||||
.unwrap_or(self.props.clone());
|
||||
}
|
||||
|
||||
fn handle_key_event(&mut self, key: Key) {
|
||||
|
||||
Reference in New Issue
Block a user