subIntent

suspend fun <STATE : Any, SIDE_EFFECT : Any> ContainerHost<STATE, SIDE_EFFECT>.subIntent(transformer: suspend SimpleSyntax<STATE, SIDE_EFFECT>.() -> Unit)

Used for parallel decomposition or subdivision of a larger intent into smaller parts.

Should only be used from within an intent or subIntent block.

An example use case for sub-intents is to launch multiple from a single intent using coroutineScope. For example, when listening to multiple flows from the Container onCreate lambda.

override val container = scope.container<TestState, String>(initialState) {
coroutineScope {
launch {
sendSideEffect1()
}
launch {
sendSideEffect2()
}
}
}

@OptIn(OrbitExperimental::class)
private suspend fun sendSideEffect1() = subIntent {
flow1.collect {
postSideEffect(it)
}
}

@OptIn(OrbitExperimental::class)
private suspend fun sendSideEffect1() = subIntent {
flow2.collect {
postSideEffect(it)
}
}

Parameters

transformer

lambda representing the transformer