All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.dev.programadorthi.routing.compose.ComposePopResult.kt Maven / Gradle / Ivy

There is a newer version: 2.0.0-alpha02
Show newest version
package dev.programadorthi.routing.compose

import dev.programadorthi.routing.core.Routing
import dev.programadorthi.routing.core.application.ApplicationCall
import io.ktor.util.AttributeKey

private val ComposeRoutingPopResultAttributeKey: AttributeKey =
    AttributeKey("ComposeRoutingPopResultAttributeKey")

private val ComposeRoutingPoppedApplicationCallAttributeKey: AttributeKey =
    AttributeKey("ComposeRoutingPoppedApplicationCallAttributeKey")

private val ComposeRoutingPoppedFlagCallAttributeKey: AttributeKey =
    AttributeKey("ComposeRoutingPoppedFlagCallAttributeKey")

@PublishedApi
internal var ApplicationCall.popResult: Any?
    get() = attributes.getOrNull(ComposeRoutingPopResultAttributeKey)
    set(value) {
        if (value != null) {
            attributes.put(ComposeRoutingPopResultAttributeKey, value)
        } else {
            attributes.remove(ComposeRoutingPopResultAttributeKey)
        }
    }

@PublishedApi
internal var Routing.poppedCall: ApplicationCall?
    get() = attributes.getOrNull(ComposeRoutingPoppedApplicationCallAttributeKey)
    set(value) {
        if (value != null) {
            attributes.put(ComposeRoutingPoppedApplicationCallAttributeKey, value)
        } else {
            attributes.remove(ComposeRoutingPoppedApplicationCallAttributeKey)
        }
    }

internal var Routing.popResult: Any?
    get() = attributes.getOrNull(ComposeRoutingPopResultAttributeKey)
    set(value) {
        if (value != null) {
            attributes.put(ComposeRoutingPopResultAttributeKey, value)
        } else {
            attributes.remove(ComposeRoutingPopResultAttributeKey)
        }
    }

public var ApplicationCall.popped: Boolean
    get() = attributes.getOrNull(ComposeRoutingPoppedFlagCallAttributeKey) ?: false
    internal set(value) {
        attributes.put(ComposeRoutingPoppedFlagCallAttributeKey, value)
    }

public inline fun  ApplicationCall.popResult(): T? =
    when (popResult) {
        is T -> popResult as T
        else -> null
    }

public inline fun  ApplicationCall.popResult(default: T): T = popResult() ?: default

public inline fun  ApplicationCall.popResult(default: () -> T): T = popResult() ?: default()

public fun Routing.poppedCall(): ApplicationCall? = poppedCall

public inline fun  Routing.popResult(): T? = poppedCall()?.popResult()

public inline fun  Routing.popResult(default: T): T = popResult() ?: default

public inline fun  Routing.popResult(default: () -> T): T = popResult() ?: default()




© 2015 - 2025 Weber Informatics LLC | Privacy Policy