Skip to content

sigmadeltasoftware/BallastCompanion

 
 

Repository files navigation

Ballast Companion Template Generator

Description

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!

Template generation

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:

Screen

@Composable
fun ExampleScreen(
    state: ExampleScreenContract.State,
    postInput: (ExampleScreenContract.Inputs) -> Unit
) {

}

Contract

object ExampleContract {

    @Immutable
    data class State()

    sealed interface Inputs {}

    sealed interface Events {}
}

InputHandler

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()
    }
}

EventHandler

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()
    }
}

ViewModel

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,
)

About

Avoid writing boilerplate code using the Ballast-MVI mental-model

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Kotlin 100.0%