Package me.aartikov.replica.keyed

Types

Link copied to clipboard
interface ClearOrder<out K : Any, out T : Any>

Configures in which order KeyedPhysicalReplica clears children when child count exceeds KeyedReplicaSettings.maxCount.

Link copied to clipboard
data class ClearPolicy<K : Any, T : Any>(val clearOrder: ClearOrder<K, T> = ClearOrder.ByObservingTime, val isPrivilegedReplica: (Pair<K, ReplicaState<T>>) -> Boolean? = null)

Configures how KeyedPhysicalReplica clears children when child count exceeds KeyedReplicaSettings.maxCount.

Link copied to clipboard
fun interface KeyedFetcher<K : Any, T : Any>

Fetches data from a server. Throws exception on error.

Link copied to clipboard
interface KeyedPhysicalReplica<K : Any, T : Any> : KeyedReplica<K, T>

Keyed replica replicates multiple chunks of data - different chunks for different keys. Internally it uses PhysicalReplica for individual data chunks.

Link copied to clipboard
interface KeyedReplica<K : Any, out T : Any>

Keyed replica replicates multiple chunks of data - different chunks for different keys.

Link copied to clipboard
interface KeyedReplicaEvent<K : Any, T : Any>

Notifies that something happened in KeyedPhysicalReplica.

Link copied to clipboard
data class KeyedReplicaSettings<K : Any, T : Any>(val maxCount: Int = Int.MAX_VALUE, val clearPolicy: ClearPolicy<K, T> = ClearPolicy())

Configures behaviour of a keyed replica.

Link copied to clipboard
data class KeyedReplicaState(    val replicaCount: Int,     val replicaWithObserversCount: Int,     val replicaWithActiveObserversCount: Int)
Link copied to clipboard
interface KeyedStorage<K : Any, T : Any>

Allows KeyedPhysicalReplica to save data on a persistent storage.

Functions

Link copied to clipboard
suspend fun <K : Any, T : Any> KeyedPhysicalReplica<T, K>.cancelAll()

Cancels network requests in all child replicas.

Link copied to clipboard
suspend fun <K : Any, T : Any> KeyedPhysicalReplica<T, K>.cancelByTags(predicate: (Set<ReplicaTag>) -> Boolean)

Cancels network requests in child replicas with the matching tags.

Link copied to clipboard
suspend fun <K : Any, T : Any> KeyedPhysicalReplica<T, K>.clearByTags(predicate: (Set<ReplicaTag>) -> Boolean)

Cancels network requests and clears data in child replicas with the matching tags.

Link copied to clipboard
suspend fun <K : Any, T : Any> KeyedPhysicalReplica<T, K>.invalidateAll(mode: InvalidationMode = InvalidationMode.RefreshIfHasObservers)

Makes all child replicas stale.

Link copied to clipboard
suspend fun <K : Any, T : Any> KeyedPhysicalReplica<T, K>.invalidateByTags(mode: InvalidationMode = InvalidationMode.RefreshIfHasObservers, predicate: (Set<ReplicaTag>) -> Boolean)

Makes child replicas with the matching tags stale.

Link copied to clipboard
fun <K : Any, T : Any> KeyedReplica<K, T>.keepPreviousData(): KeyedReplica<K, T>

Modifies KeyedReplica so its observer keeps a data from a previous key until a data for a new key will not be loaded. It allows to dramatically improve UX when KeyedReplica is observed by changing keys.

Link copied to clipboard
inline suspend fun <K : Any, T : Any, R> withOptimisticUpdate(    update: OptimisticUpdate<T>,     replica: KeyedPhysicalReplica<K, T>,     key: K,     noinline onSuccess: suspend () -> Unit? = null,     noinline onError: suspend (Exception) -> Unit? = null,     noinline onCanceled: suspend () -> Unit? = null,     noinline onFinished: suspend () -> Unit? = null,     block: () -> R): R

Executes an optimistic update on a keyed replica for a given key. update is applied immediately on observed replica state. Then block is executed. If block succeed an update is committed, otherwise an update is rolled back.

Properties

Link copied to clipboard
val <K : Any, T : Any> KeyedPhysicalReplica<K, T>.currentState: KeyedReplicaState

Returns current KeyedReplicaState.