PendingActions

data class PendingActions<T : Any>(actions: List<T> = emptyList())

An immutable action holder data class to be used in UiStates and to be consumed in Compose to indicate pending loading async states.

Example usage:

// Screen actions
interface Action {
data object LongOperation : Action
}

// Screen ui state
data class UiState(
val title: String,
val pendingActions: PendingActions<Action> = PendingActions()
)

val uiState = MutableStateFlow(UiState(title = "PendingActions"))

// Adding pending action before executing a blocking operation and removing afterwards
fun onAction(action: Action) {
when (action) {
is Action.LongOperation -> {
uiState.update { it.copy(pendingActions = it.pendingActions + action) }
// perform blocking operation
uiState.update { it.copy(pendingActions = it.pendingActions - action) }
}
}
}

// Using isLoading inside compose
@Composable
fun PendingActions(uiState: UiState) {
val isLoading = uiState.pendingActions.isLoading(action = Action.LongOperation)
// rest of the screen
}

Constructors

Link copied to clipboard
constructor(actions: List<T> = emptyList())

Functions

Link copied to clipboard
Link copied to clipboard
operator fun minus(action: T): PendingActions<T>

Returns a new PendingActions instance by removing all actions of the same type as action

Link copied to clipboard
operator fun plus(action: T): PendingActions<T>

Returns a new PendingActions instance by appending action