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

New utility render-functions for RenderContext #788

Merged
merged 2 commits into from
Aug 21, 2023
Merged

Conversation

jamowei
Copy link
Collaborator

@jamowei jamowei commented Aug 21, 2023

This PR and PR #783 added new utility render-functions inside RenderContext.

The renderIf(predicate: (V) -> Boolean) function only renders the given content, when the given predicate returns true for the value inside the Flow<V>.

val store = storeOf<String>("foo")
render {
    store.data.renderIf(String::isNotBlank) {
        p { +it }
    }
}

The renderNotNull() function only renders the given content, when the value inside the Flow<V?> is not null.

val store = storeOf<String?>(null)
render {
    store.data.renderNotNull {
        p { +it }
    }
}

The renderIs(klass: KClass<W>) function only renders the given content, when the value inside the Flow<V> is a type of klass.

interface I
class A: I
class B: I

val store = storeOf<I>(A())
render {
    store.data.renderIs(A::class) {
        p { +"A" }
    }
}

Extends the PR #783 from @serras. Thanks for your work!

@jamowei jamowei added this to the 1.0-RC8 milestone Aug 21, 2023
@jamowei jamowei requested a review from Lysander August 21, 2023 12:12
@jamowei jamowei self-assigned this Aug 21, 2023
@Lysander Lysander merged commit 88697f7 into master Aug 21, 2023
@Lysander Lysander deleted the jamowei/more-render branch August 21, 2023 15:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants