QueryReceiver

Extension receiver for referencing external instances needed when executing query.

Usage:

For receiver provider

internal val customClientKey = ContextPropertyKey<CustomClient>()

val ContextReceiver.customClient: CustomClient?
get() = get(customClientKey)

var ContextReceiverBuilder.customClient: CustomClient
get() = error("You cannot retrieve a builder property directly.")
set(value) = set(customClientKey, value)

inline fun <T> buildCustomQueryKey(
id: QueryId<T>,
crossinline fetch: suspend CustomClient.() -> T
): QueryKey<T> = buildQueryKey(
id = id,
fetch = {
val client = checkNotNull(customClient) { "customClient isn't available. Did you forget to set it up?" }
with(client) { fetch() }
}
)

For receiver builder

QueryReceiver {
customClient = newCustomClient()
}

For receiver executor

class GetPostKey(private val postId: Int) : QueryKey<Post> by buildCustomQueryKey(
id = ..,
fetch = { // CustomClient.() -> Post
doSomething()
}
)

Inheritors

Types

Link copied to clipboard

Default implementation for QueryReceiver.

Functions

Link copied to clipboard
abstract operator fun <T : Any> get(key: ContextPropertyKey<T>): T?