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() }
}
)
Content copied to clipboard
For receiver builder
QueryReceiver {
customClient = newCustomClient()
}
Content copied to clipboard
For receiver executor
class GetPostKey(private val postId: Int) : QueryKey<Post> by buildCustomQueryKey(
id = ..,
fetch = { // CustomClient.() -> Post
doSomething()
}
)
Content copied to clipboard
Inheritors
Types
Link copied to clipboard
Default implementation for QueryReceiver.