Skip to content

Commit

Permalink
More progress towards diagnostic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
galex committed May 22, 2024
1 parent 372f307 commit caa0276
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 18 deletions.
72 changes: 67 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,79 @@
[![codecov](https://codecov.io/github/galex/yamvil/branch/main/graph/badge.svg?token=ML8EN8PYP0)](https://codecov.io/github/galex/yamvil)
[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

> Do we really need Yet Another MVI Library? Yes, we do!
> ⚠️ **This is a work in progress**: Yamvil is still in early development and is not ready for production use. The API is subject to change and Android Studio is not ready to run the compiler plugin, **yet**.
Yamvil is a library and a compiler plugin to help write MVI Screens ensuring a proper Unidirectional Data Flow way for Android and Compose Multiplatform.

> ⚠️ **This is a work in progress**: Yamvil is still in early development and is not ready for production use. The API is subject to change and Android Studio is not ready to run the compiler plugin, **yet**.
## Documentation

The full documentation of Yamvil [is available right here](https://docs.galex.dev/yamvil/).
The full documentation of Yamvil [is available here](https://docs.galex.dev/yamvil/).

## To the Point

Write MVI ViewModels like this:
```kotlin
class DashboardViewModel: MVIViewModel<DashboardUiState, DashboardUiEvent>() {

override fun initializeUiState(): DashboardUiState {
return DashboardUiState(state = DashboardUiState.ContentState.Loading)
}
override fun handleEvent(event: DashboardUiEvent) {
when (event) {
is DashboardUiEvent.ClickOnNext -> onClickOnNext()
}
}

private fun onClickOnNext() {
update { copy(action = Consumable(DashboardUiAction.NavigateToNext)) }
}
}
```
Then use your MVI ViewModel in a Composable like this:
```kotlin
@Composable
fun DashboardScreen(
uiState: DashboardUiState,
handleEvent: (DashboardUiEvent) -> Unit,
modifier: Modifier = Modifier
) {
when (uiState.state) {
is DashboardUiState.ContentState.Loading -> DashboardLoadingContent()
is DashboardUiState.ContentState.Error -> DashboardErrorContent()
is DashboardUiState.ContentState.Content -> DashboardContent(uiState.state)
}

LaunchedActionEffect(uiState) { action: DashboardUiAction ->
when (action) {
DashboardUiAction.NavigateToNext -> {}
}
}
}
// (...)
```
Or if you're using Fragments, like this:
```kotlin
class DashboardFragment: MVIFragment<DashboardUiState, DashboardUiEvent>() {

override val viewModel: DashboardViewModel by viewModels()
override fun observeUiState(uiState: DashboardUiState) {
when (uiState.state) {
DashboardUiState.ContentState.Loading -> onLoading()
is DashboardUiState.ContentState.Content -> onContent(uiState.state)
DashboardUiState.ContentState.Error -> onError()
}

uiState.onAction { action ->
when (action) {
DashboardUiAction.NavigateToNext -> navigateToNext()
}
}
}
// (...)
}
```

## Quick Start
## Installation

In your libs.version.toml, add the following:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import java.io.File;
import java.util.regex.Pattern;

import dev.galex.yamvil.runners.AbstractDiagnosticTest;

/** This class is generated by {@link dev.galex.yamvil.GenerateTestsKt}. DO NOT MODIFY MANUALLY */
@SuppressWarnings("all")
@TestMetadata("src/test-data/diagnostics")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package dev.galex.yamvil

import dev.conguard.compiler.runners.AbstractDiagnosticTest
import dev.galex.yamvil.runners.AbstractDiagnosticTest
import org.jetbrains.kotlin.generators.generateTestGroupSuiteWithJUnit5

fun main() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.conguard.compiler.runners
package dev.galex.yamvil.runners

import org.jetbrains.kotlin.test.FirParser
import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.conguard.compiler.runners
package dev.galex.yamvil.runners

import dev.conguard.compiler.services.ExtensionRegistrarConfigurator
import dev.conguard.compiler.services.PluginDslProvider
Expand Down
6 changes: 3 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[versions]
agp = "8.3.0"
agp = "8.3.2"
junitJupiterApi = "5.10.1"
junitJupiterEngine = "5.10.1"
kotlin = "2.0.0-RC3"
kotlin = "2.0.0"
compose = "1.6.7"
compose-material3 = "1.2.1"
androidx-activityCompose = "1.9.0"
Expand All @@ -11,7 +11,7 @@ lifecycle-viewmodel-compose = "2.8.0-beta02"
junit = "4.13.2"
junit-bom = "5.10.1"
autoservice = "1.0.1"
kotlin-compile-testing = "1.4.9"
kotlin-compile-testing = "1.5.0"
gson = "2.10.1"
robolectric = "4.12"
truth = "1.4.2"
Expand Down
9 changes: 9 additions & 0 deletions samples/sample-android/app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import dev.galex.yamvil.dsl.YamvilLevel

plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
Expand Down Expand Up @@ -75,4 +77,11 @@ dependencies {
androidTestImplementation(libs.androidx.ui.test.junit4)
debugImplementation(libs.androidx.ui.tooling)
debugImplementation(libs.androidx.ui.test.manifest)
}

yamvil {
level = YamvilLevel.Warning
screenSuffix = "MVIScreen" // Default value is "Screen"
uiStateParameterName = "state" // Default value is "uiState"
uiEventFunctionParameterMame = "onEvent" // Default value is "handleEvent"
}
14 changes: 7 additions & 7 deletions samples/sample-android/gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
[versions]
agp = "8.4.0"
kotlin = "2.0.0-RC3"
coreKtx = "1.10.1"
agp = "8.4.1"
kotlin = "2.0.0"
coreKtx = "1.13.1"
junit = "4.13.2"
junitVersion = "1.1.5"
espressoCore = "3.5.1"
lifecycleRuntimeKtx = "2.6.1"
lifecycleRuntimeKtx = "2.8.0"
activityCompose = "1.9.0"
composeBom = "2023.08.00"
yamvil = "0.0.1"
lifecycleViewmodelCompose = "2.7.0"
composeBom = "2024.05.00"
yamvil = "0.0.2"
lifecycleViewmodelCompose = "2.8.0"

[libraries]
androidx-core-ktx = { group = "androidx.core", name = "core-ktx", version.ref = "coreKtx" }
Expand Down

0 comments on commit caa0276

Please sign in to comment.