Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.0.0-beta01 #19

Merged
merged 9 commits into from
Aug 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 24 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
[![CodeFactor](https://www.codefactor.io/repository/github/respawn-app/flowMVI/badge)](https://www.codefactor.io/repository/github/respawn-app/flowMVI)
[![AndroidWeekly #556](https://androidweekly.net/issues/issue-556/badge)](https://androidweekly.net/issues/issue-556/)

### This is Readme for FlowMVI 2.0, which is in alpha right now. Please go to the [V1 Docs](https://opensource.respawn.pro/FlowMVI/#/v1/) if you need to see the older version

FlowMVI is a Kotlin Multiplatform MVI library based on coroutines that has a few main goals:

1. Being simple to understand and use while staying powerful and flexible.
Expand All @@ -34,13 +32,15 @@ flowmvi-core = { module = "pro.respawn.flowmvi:core", version.ref = "flowmvi" }
flowmvi-android = { module = "pro.respawn.flowmvi:android", version.ref = "flowmvi" } # common android
flowmvi-view = { module = "pro.respawn.flowmvi:android-view", version.ref = "flowmvi" } # view-based android
flowmvi-compose = { module = "pro.respawn.flowmvi:android-compose", version.ref = "flowmvi" } # compose

flowmvi-test = { module = "pro.respawn.flowmvi:test", version.ref = "flowmvi" } # test utils
```

Supported platforms:

* JVM: [ `Android`, `JRE 11+` ],
* Linux [ `X64`, `mingw64` ],
* iOS: [ `X64`, `Arm64`, `macOS` ],
* Linux [ `x64`, `mingw64` ],
* Apple: [ `iosX64`, `macOSx64`, 'watchOSx64', 'tvOSx64' ],
* js: [ `nodejs`, `browser` ]

### A quick overview:
Expand Down Expand Up @@ -217,6 +217,26 @@ class ScreenFragment : Fragment(), MVIView<CounterState, CounterIntent, CounterA
}
```

### Testing DSL

```kotlin
// using Turbine + Kotest
testStore().subscribeAndTest {

ClickedCounter resultsIn {

states.test {
awaitItem() shouldBe DisplayingCounter(counter = 1, timer = 0)
}
actions.test {
awaitItem().shouldBeTypeOf<ShowMessage>()
}

}

}
```

Ready to try? Start with reading the [Quickstart Guide](https://opensource.respawn.pro/FlowMVI/#/quickstart).

## License
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public interface ConsumerScope<in I : MVIIntent, out A : MVIAction> {
* Should only be called once per screen.
*/
@Composable
public fun consume(onAction: suspend CoroutineScope.(action: A) -> Unit): Unit
public fun consume(onAction: suspend CoroutineScope.(action: A) -> Unit)
}

@Composable
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ dependencies {
api(project(":core"))
api(libs.lifecycle.runtime)
api(libs.lifecycle.viewmodel)
api(libs.kotlinx.coroutines.android)
api(libs.kotlin.coroutines.android)
implementation(libs.lifecycle.savedstate)
}
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,9 @@ public abstract class MVIViewModel<S : MVIState, I : MVIIntent, A : MVIAction>(
override suspend fun <R> withState(block: suspend S.() -> R): R = store.withState(block)

/**
* @see MVIStore.launchRecovering
* @see launchRecovering
*/
@Deprecated("launchRecovering is no longer needed. As you migrate to Stores, use launch()")
protected fun launchRecovering(
context: CoroutineContext = EmptyCoroutineContext,
start: CoroutineStart = CoroutineStart.DEFAULT,
Expand Down Expand Up @@ -170,7 +171,10 @@ public abstract class MVIViewModel<S : MVIState, I : MVIIntent, A : MVIAction>(

override fun start(scope: CoroutineScope): Job = error("Store is already started by the ViewModel")

@Deprecated("Directly using actions/states is deprecated. Use the subscribeDsl", ReplaceWith("subscribe()"))
override val actions: Flow<A> get() = store.actions

@Deprecated("Directly using actions/states is deprecated. Use the subscribeDsl", ReplaceWith("subscribe()"))
override val states: StateFlow<S> get() = store.states

public override fun CoroutineScope.subscribe(
Expand Down
8 changes: 6 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ android {
minSdk = Config.appMinSdk
targetSdk = Config.targetSdk
versionCode = 1
versionName = "1.0"
versionName = Config.versionName
}

buildFeatures {
buildConfig = true
compose = true
viewBinding = true
}
kotlinOptions {
freeCompilerArgs += Config.jvmCompilerArgs
jvmTarget = Config.jvmTarget.target
languageVersion = Config.kotlinVersion.version
}
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import pro.respawn.flowmvi.android.plugins.androidLoggingPlugin
import pro.respawn.flowmvi.api.Container
import pro.respawn.flowmvi.api.PipelineContext
import pro.respawn.flowmvi.dsl.store
import pro.respawn.flowmvi.dsl.updateState
import pro.respawn.flowmvi.plugins.platformLoggingPlugin
import pro.respawn.flowmvi.plugins.recover
import pro.respawn.flowmvi.plugins.reduce
import pro.respawn.flowmvi.plugins.whileSubscribed
Expand All @@ -30,7 +30,7 @@ class CounterContainer(

override val store = store(CounterState.Loading) {
name = "Counter"
install(androidLoggingPlugin())
install(platformLoggingPlugin())
whileSubscribed {
repo.getTimer()
.onEach { produceState(it) } // set mapped states
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.flow.onEach
import pro.respawn.flowmvi.android.plugins.androidLoggingPlugin
import pro.respawn.flowmvi.android.plugins.parcelizeState
import pro.respawn.flowmvi.api.Container
import pro.respawn.flowmvi.api.PipelineContext
import pro.respawn.flowmvi.dsl.lazyStore
import pro.respawn.flowmvi.dsl.reduceLambdas
import pro.respawn.flowmvi.dsl.send
import pro.respawn.flowmvi.dsl.updateState
import pro.respawn.flowmvi.plugins.platformLoggingPlugin
import pro.respawn.flowmvi.plugins.whileSubscribed
import pro.respawn.flowmvi.sample.BuildConfig
import pro.respawn.flowmvi.sample.CounterAction
Expand All @@ -37,7 +37,7 @@ class LambdaViewModel(
) {
name = "Counter"
debuggable = BuildConfig.DEBUG
install(androidLoggingPlugin())
install(platformLoggingPlugin())
parcelizeState(savedStateHandle)
whileSubscribed {
repo.getTimer()
Expand Down
8 changes: 8 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ allprojects {
jvmTarget.set(Config.jvmTarget)
languageVersion.set(Config.kotlinVersion)
freeCompilerArgs.addAll(Config.compilerArgs)
optIn.addAll(Config.optIns.map { "-opt-in=$it" })
}
}
}
Expand Down Expand Up @@ -120,6 +121,13 @@ tasks {
}
}

withType<Test>().configureEach {
useJUnitPlatform()
filter {
isFailOnNoMatchingTests = false
}
}

register<io.gitlab.arturbosch.detekt.Detekt>("detektFormat") {
description = "Formats whole project."
autoCorrect = true
Expand Down
2 changes: 1 addition & 1 deletion buildSrc/src/main/kotlin/Config.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object Config {
const val majorRelease = 2
const val minorRelease = 0
const val patch = 0
const val postfix = "alpha02"
const val postfix = "beta01"
const val versionName = "$majorRelease.$minorRelease.$patch-$postfix"

// kotlin
Expand Down
33 changes: 13 additions & 20 deletions buildSrc/src/main/kotlin/ConfigureAndroid.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fun Project.configureAndroid(
commonExtension: CommonExtension<*, *, *, *, *>,
) = commonExtension.apply {
compileSdk = Config.compileSdk
val libs by versionCatalog

defaultConfig {
minSdk = Config.minSdk
Expand All @@ -33,12 +34,6 @@ fun Project.configureAndroid(
targetCompatibility = Config.javaVersion
}

kotlinOptions {
freeCompilerArgs += Config.jvmCompilerArgs
jvmTarget = Config.jvmTarget.target
languageVersion = Config.kotlinVersion.version
}

buildFeatures {
aidl = false
buildConfig = false
Expand All @@ -50,17 +45,11 @@ fun Project.configureAndroid(
compose = false
}

val libs by versionCatalog
composeOptions {
kotlinCompilerExtensionVersion = libs.requireVersion("compose-compiler")
}

packaging {
resources {
excludes += setOf(
"DebugProbesKt.bin",
"/META-INF/{AL2.0,LGPL2.1}",
"/META-INF/versions/9/previous-compilation-data.bin"
)
}
}
Expand All @@ -71,21 +60,29 @@ fun Project.configureAndroid(
isReturnDefaultValues = true
all {
it.apply {
useJUnitPlatform()
maxHeapSize = "1G"
setForkEvery(100)
forkEvery = 100
jvmArgs = listOf("-Xmx1g", "-Xms512m")
}
}
}
}

composeOptions {
kotlinCompilerExtensionVersion = libs.findVersion("compose-compiler").get().toString()
useLiveLiterals = true
}
}

fun Project.configureAndroidLibrary(variant: LibraryExtension) = variant.apply {
configureAndroid(this)

kotlinOptions {
freeCompilerArgs += "-Xexplicit-api=strict"
testFixtures {
enable = true
}

defaultConfig {
consumerProguardFiles(file(Config.consumerProguardFile))
}

buildTypes {
Expand All @@ -97,10 +94,6 @@ fun Project.configureAndroidLibrary(variant: LibraryExtension) = variant.apply {
}
}

defaultConfig {
consumerProguardFiles(file(Config.consumerProguardFile))
}

libraryVariants.all {
sourceSets {
getByName(name) {
Expand Down
Loading