Prefer .map for conditionals with else conditions (#15118)

This PR updates instances where we were using `.when_else` and
`.when_else_some` to use `.map` with a conditional inside.

This allows us to avoid reinventing Rust's syntax for conditionals and
(IMO) makes the code easier to read.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers 2024-07-24 17:09:07 -04:00 committed by GitHub
parent 596ee58be8
commit 298ca5ff1b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 55 additions and 93 deletions

View file

@ -119,9 +119,15 @@ impl Render for Toolbar {
.when(has_right_items, |this| {
this.child(
h_flex()
// We're using `flex_none` here to prevent some flickering that can occur when the
// size of the left items container changes.
.when_else(has_left_items, Div::flex_none, Div::flex_auto)
.map(|el| {
if has_left_items {
// We're using `flex_none` here to prevent some flickering that can occur when the
// size of the left items container changes.
el.flex_none()
} else {
el.flex_auto()
}
})
.justify_end()
.children(self.right_items().map(|item| item.to_any())),
)