This plugin is designed to use in conjunction with the Ballast MVI Kotlin Multiplatform library by copper-leaf.
Available through the Jetbrains Marketplace (IDE > Plugins > Marketplace) or downloadable here!
The plugin will generate the 4 core files necessary for the Ballast mental-model, including a file containing the Composable screen.
Given the Example
prefix/feature, the following will be generated:
@Composable
fun ExampleScreen(
state: ExampleScreenContract.State,
postInput: (ExampleScreenContract.Inputs) -> Unit
) {
}
object ExampleContract {
@Immutable
data class State()
sealed interface Inputs {}
sealed interface Events {}
}
typealias ExampleContractInputHandler = InputHandler<ExampleContract.Inputs, ExampleContract.Events, ExampleContract.State>
typealias ExampleContractInputHandlerScope = InputHandlerScope<ExampleContract.Inputs, ExampleContract.Events, ExampleContract.State>
class ExampleInputHandler : ExampleContractInputHandler {
override suspend fun ExampleContractInputHandlerScope.handleInput(input: ExampleContract.Inputs) = try {
when (input) {
}
Unit
} catch (e: Exception) {
e.printStackTrace()
}
}
typealias ExampleContractEventHandler = EventHandler<ExampleContract.Inputs, ExampleContract.Events, ExampleContract.State>
typealias ExampleContractEventHandlerScope = EventHandlerScope<ExampleContract.Inputs, ExampleContract.Events, ExampleContract.State>
class ExampleEventHandler : ExampleContractEventHandler {
override suspend fun ExampleContractEventHandlerScope.handleEvent(event: ExampleContract.Events) = try {
when (event) {
}
Unit
} catch(e: Exception) {
e.printStackTrace()
}
}
class ExampleViewModel(
viewModelCoroutineScope: CoroutineScope,
) : BasicViewModel<
ExampleContract.Inputs,
ExampleContract.Events,
ExampleContract.State
>(
config = BallastViewModelConfiguration.Builder()
.withViewModel(
initialState = ExampleContract.State(),
inputHandler = ExampleInputHandler(),
)
.dispatchers(
inputsDispatcher = Dispatchers.Main.immediate,
eventsDispatcher = Dispatchers.Main.immediate,
sideJobsDispatcher = Dispatchers.Default,
interceptorDispatcher = Dispatchers.Default
)
.build(),
eventHandler = ExampleEventHandler(),
coroutineScope = viewModelCoroutineScope,
)