Updated on 2026-08-14

This commit is contained in:
Tangem 2024-07-03 14:33:31 +03:00
parent 8737ebd291
commit 5c51d8c3f1
6 changed files with 30 additions and 30 deletions

View file

@ -4,10 +4,10 @@ package com.tangem.pagination
* Represents a batch of data with a key.
* Used in [BatchListState].
*
* @param K type of the key.
* @param T type of the data.
* @param TKey type of the key.
* @param TData type of the data.
*/
data class Batch<K, T>(
val key: K,
val data: T,
data class Batch<TKey, TData>(
val key: TKey,
val data: TData,
)

View file

@ -3,11 +3,11 @@ package com.tangem.pagination
/**
* Action that can be dispatched to [BatchListSource].
*
* @param R type of the request to load batches.
* @param K type of the key of the batch.
* @param U type of the update request.
* @param TRequest type of the request to load batches.
* @param TKey type of the key of the batch.
* @param TUpdate type of the update request.
*/
sealed class BatchAction<R, K, U> {
sealed class BatchAction<TRequest, TKey, TUpdate> {
/**
* Action to load the first batch.

View file

@ -4,10 +4,10 @@ package com.tangem.pagination
* Represents a result of a batch fetch request.
* Used in [BatchListState].
*
* @param T type of the data.
* @param E type of the error.
* @param TData type of the data.
* @param TError type of the error.
*/
sealed class BatchFetchResult<out T, out E> {
sealed class BatchFetchResult<out TData, out TError> {
/**
* Represents a successful result of a batch fetch request.
@ -15,17 +15,17 @@ sealed class BatchFetchResult<out T, out E> {
* @param data fetched data.
* @param last indicates if this is the last batch for the request.
*/
data class Success<T>(
val data: T,
data class Success<TData>(
val data: TData,
val last: Boolean = false,
) : BatchFetchResult<T, Nothing>()
) : BatchFetchResult<TData, Nothing>()
/**
* Represents an error result of a batch fetch request.
*
* @param error error that occurred during the request.
*/
data class Error<E>(val error: E) : BatchFetchResult<Nothing, E>()
data class Error<TError>(val error: TError) : BatchFetchResult<Nothing, TError>()
/**
* Represents an unknown error result of a batch fetch request.

View file

@ -3,16 +3,16 @@ package com.tangem.pagination
/**
* State that is used for listening the current state of a pagination.
*
* @param K type of the key of the batch.
* @param T type of the data.
* @param E type of the error.
* @param TKey type of the key of the batch.
* @param TData type of the data.
* @param TError type of the error.
*
* @property data list of loaded batches.
* @property status current status of the pagination.
*
* @see BatchListSource
*/
data class BatchListState<K, T, E>(
val data: List<Batch<K, T>>,
val status: PaginationStatus<T, E>,
data class BatchListState<TKey, TData, TError>(
val data: List<Batch<TKey, TData>>,
val status: PaginationStatus<TData, TError>,
)

View file

@ -3,7 +3,7 @@ package com.tangem.pagination
/**
* Request to fetch a batch of data.
*
* @param R type of the request.
* @param TRequest type of the request.
*
* @property offset offset for the request.
* @property limit limit for the request.
@ -11,8 +11,8 @@ package com.tangem.pagination
*
* @see BatchFetcher
*/
data class BatchRequest<R>(
data class BatchRequest<TRequest>(
val offset: Int,
val limit: Int,
val data: R,
val data: TRequest,
)

View file

@ -6,9 +6,9 @@ import kotlinx.coroutines.flow.Flow
/**
* Context for working with [BatchListSource].
*
* @param R type of the request.
* @param K type of the key.
* @param U type of the update request.
* @param TRequest type of the request.
* @param TKey type of the key.
* @param TUpdate type of the update request.
*
* @property actionsFlow flow of [BatchAction]s that would be dispatched to [BatchListSource].
* @property coroutineScope scope for the [BatchListSource] to launch coroutines. When it is cancelled,
@ -16,7 +16,7 @@ import kotlinx.coroutines.flow.Flow
*
* @see BatchListSource
*/
class BatchingContext<R, K, U>(
val actionsFlow: Flow<BatchAction<R, K, U>>,
class BatchingContext<TRequest, TKey, TUpdate>(
val actionsFlow: Flow<BatchAction<TRequest, TKey, TUpdate>>,
val coroutineScope: CoroutineScope,
)