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

Add renderTrue and renderFalse convenience functions #857

Merged
merged 2 commits into from Mar 21, 2024

Conversation

haukesomm
Copy link
Collaborator

@haukesomm haukesomm commented Mar 15, 2024

Motivation

With fritz1.0-RC8 we added a bunch of convenience-render-functions to reduce boilerplate-code within the ui-sections, such as renderIf({/*some boolean expression */}) { ... }. In many cases however, we have to work with boolean Flows which lead to code like this:

someBooleanFlow.renderIf({ it }) { 
    /* render UI */ 
}

This looks not as clean as it could.

Solution

This PR adds two convenience functions Flow<Boolean>.renderIfTrue(...) and Flow<Boolean>.renderIfFalse(...) that render a given content if a boolean Flow's value is true or false respectively.

Examples:

val store = storeOf(true)

store.data.renderIfTrue {
    // content is rendered if the Store's value is true.
    // If the Store's value is false, nothing is rendered.
}
val store = storeOf(false)

store.data.renderIfFalse {
    // content is rendered if the Store's value is false.
    // If the Store's value is true, nothing is rendered.
}

@haukesomm haukesomm added the enhancement New feature or request label Mar 15, 2024
@haukesomm haukesomm added this to the 1.0-RC17 milestone Mar 15, 2024
@haukesomm haukesomm requested a review from Lysander March 15, 2024 14:49
@haukesomm haukesomm closed this Mar 15, 2024
@haukesomm haukesomm reopened this Mar 15, 2024
@haukesomm haukesomm marked this pull request as draft March 15, 2024 16:06
Both provide a shortcut to render content if a given
boolean flow's value is `true` or `false` respectively.
@haukesomm haukesomm marked this pull request as ready for review March 20, 2024 09:34
@haukesomm haukesomm changed the title Add renderIfTrue and renderIfFalse convenience functions Add renderTrue and renderFalse convenience functions Mar 21, 2024
@Lysander Lysander self-requested a review March 21, 2024 10:00
@Lysander Lysander merged commit e7d2424 into master Mar 21, 2024
2 checks passed
@Lysander Lysander deleted the haukesomm/render-if branch March 21, 2024 10:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants