Package-level declarations

Utilities for using hurok with Compose Multiplatform

This package contains the LoopView which can be used to attach a Loop to a @Composable function.

For example:

@Composable
fun ScoreScreenView() {
LoopView(ScoreScreenLoop) {
Column {
Text(text = playerName)

Text(text = score)

Button(onClick = { emit(OnUpdateScoreClick) }) {
Text(text = "Update score")
}
}
}
}

In the above example ScoreScreenLoop is a LoopBuilder. A LoopBuilder(com.ekezet.hurok.LoopBuilder) is used to create a Loop by passing optional arguments and is needed to re-create the given Loop when the function leaves the composition (e.g. a configuration change).

class ScoreScreenLoop(
model: ScoreScreenModel,
renderer: Renderer<ScoreScreenModel, ScoreScreenDependency, ScoreScreenState>,
dependency: ScoreScreenDependency? = null,
effectContext: CoroutineContext = DispatcherProvider.IO,
) : Loop<ScoreScreenState, ScoreScreenModel, ScoreScreenArgs, ScoreScreenDependency, ScoreScreenAction>(
model = model,
renderer = renderer,
argsApplyer = { TODO() },
dependency = dependency,
effectContext = effectContext,
) {
companion object Builder :
LoopBuilder<ScoreScreenState, ScorescreenModel, ScoreScreenArgs, ScoreScreenDependency, ScoreScreenAction> {
override fun build(args: ScoreScreenArgs?) =
ScoreScreenLoop(
model = ScoreScreenModel(),
renderer = ScoreScreenRenderer(),
args = args,
)
}
}

By creating a builder, the Loop can be re-created by the UI with the given input arguments whenever necessary.

Utilities for using hurok with Compose Multiplatform

This package contains the LoopView which can be used to attach a Loop to a @Composable function.

For example:

@Composable
fun ScoreScreenView() {
LoopView(ScoreScreenLoop) {
Column {
Text(text = playerName)

Text(text = score)

Button(onClick = { emit(OnUpdateScoreClick) }) {
Text(text = "Update score")
}
}
}
}

In the above example ScoreScreenLoop is a LoopBuilder. A LoopBuilder(com.ekezet.hurok.LoopBuilder) is used to create a Loop by passing optional arguments and is needed to re-create the given Loop when the function leaves the composition (e.g. a configuration change).

class ScoreScreenLoop(
model: ScoreScreenModel,
renderer: Renderer<ScoreScreenModel, ScoreScreenDependency, ScoreScreenState>,
dependency: ScoreScreenDependency? = null,
effectContext: CoroutineContext = DispatcherProvider.IO,
) : Loop<ScoreScreenState, ScoreScreenModel, ScoreScreenArgs, ScoreScreenDependency, ScoreScreenAction>(
model = model,
renderer = renderer,
argsApplyer = { TODO() },
dependency = dependency,
effectContext = effectContext,
) {
companion object Builder :
LoopBuilder<ScoreScreenState, ScorescreenModel, ScoreScreenArgs, ScoreScreenDependency, ScoreScreenAction> {
override fun build(args: ScoreScreenArgs?) =
ScoreScreenLoop(
model = ScoreScreenModel(),
renderer = ScoreScreenRenderer(),
args = args,
)
}
}

By creating a builder, the Loop can be re-created by the UI with the given input arguments whenever necessary.

Types

Link copied to clipboard

Properties

Link copied to clipboard

Locally scoped com.ekezet.hurok.ActionEmitter in the composition.

Functions

Link copied to clipboard
fun <TState : Any, TModel : Any, TArgs : TModel, TDependency, TAction : Action<TModel, TDependency>> Loop<TState, TModel, TArgs, TDependency, TAction>.collectAsState(scope: CoroutineScope = rememberCoroutineScope()): State<TState>

Collects state values from this Loop as a State.

Link copied to clipboard

Collects state values from this Loop as a State in a lifecycle aware manner.

Link copied to clipboard
inline fun <TState : Any, TModel : Any, TArgs, TDependency, TAction : Action<TModel, TDependency>> LoopView(builder: @DisallowComposableCalls LoopBuilder<TState, TModel, TArgs, TDependency, TAction>, args: TArgs? = null, childOf: Set<AnyActionEmitter> = emptySet(), scope: CoroutineScope = rememberCoroutineScope(), key: String? = TModel::class.simpleName, loopStateCollector: LoopStateCollector<TState, TModel, TArgs, TDependency, TAction> = LoopStateCollectors.Standard(), crossinline content: @Composable TState.(emit: (action: TAction) -> Unit) -> Unit)

Attach a com.ekezet.hurok.Loop to a @Composable block as a state receiver.