Skip to content

Commit

Permalink
2.5.0-alpha02 (#41)
Browse files Browse the repository at this point in the history
  • Loading branch information
Nek-12 authored Mar 9, 2024
2 parents d8a7be0 + f3830d8 commit fc3daee
Show file tree
Hide file tree
Showing 83 changed files with 1,342 additions and 578 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,6 @@ jobs:
- name: Copy CI gradle.properties
run: mkdir -p ~/.gradle ; cp .github/ci-gradle.properties ~/.gradle/gradle.properties

- name: Create local properties
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > local.properties && cat local.properties

- name: set up JDK
uses: actions/setup-java@v3
with:
Expand All @@ -40,11 +35,16 @@ jobs:
with:
xcode-version: latest

- name: Create local properties
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > local.properties

- name: Run detekt
run: ./gradlew detektAll

- name: Build
run: ./gradlew assembleRelease --stacktrace
run: ./gradlew assemble --stacktrace

- name: Unit tests
run: ./gradlew allTests --stacktrace
4 changes: 1 addition & 3 deletions .github/workflows/debugger-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: debugger-linux
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: "publish-linux"
Expand All @@ -13,7 +11,7 @@ concurrency:
jobs:
publish-windows:
runs-on: ubuntu-latest

environment: publishing
steps:
- uses: actions/checkout@v3

Expand Down
4 changes: 1 addition & 3 deletions .github/workflows/debugger-macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: debugger-macos
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: "publish-macos"
Expand All @@ -13,7 +11,7 @@ concurrency:
jobs:
publish-windows:
runs-on: macos-latest

environment: publishing
steps:
- uses: actions/checkout@v3

Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/debugger-win.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ name: debugger-windows
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

concurrency:
group: "publish-win"
Expand All @@ -13,7 +11,7 @@ concurrency:
jobs:
publish-windows:
runs-on: windows-latest

environment: publishing
steps:
- uses: actions/checkout@v3

Expand All @@ -36,7 +34,7 @@ jobs:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > local.properties

- name: Create macOS debugger distributable
- name: Create platform debugger distributable
run: ./gradlew debugger:app:packageDistributionForCurrentOS

- name: Upload a Build Artifact
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ jobs:
uses: gradle/wrapper-validation-action@v1

- name: Create local properties
with:
properties: ${{ secrets.LOCAL_PROPERTIES }}
env:
LOCAL_PROPERTIES: ${{ secrets.LOCAL_PROPERTIES }}
run: echo "$LOCAL_PROPERTIES" > local.properties
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ concurrency:
jobs:
publish:
runs-on: macos-latest
environment: publishing

steps:
- uses: actions/checkout@v3
Expand Down
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,10 +124,12 @@ class CounterContainer(
) {
val store = store<CounterState, CounterIntent, CounterAction>(initial = Loading) {

// makes the store fully async and parallel
actionShareBehavior = ActionShareBehavior.Distribute()

// makes the store fully async, parallel and thread-safe
parallelIntents = true
coroutineContext = Dispatchers.Default
actionShareBehavior = ActionShareBehavior.Distribute()
atomicStateUpdates = true

// enables debugging features such as logging and remote connection
debuggable = true
Expand Down Expand Up @@ -201,6 +203,7 @@ Powerful DSL allows to hook into store events and amend any store's logic with r

```kotlin
val counterPlugin = plugin<CounterState, CounterIntent, CounterAction> {

onStart { }

onStop { }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class CounterContainer(
private val cacheDir = context.cacheDir.resolve("state").path

override val store = store(CounterState.Loading) {
name = "CounterContainer"
name = "ComposeCounter"
debuggable = BuildConfig.DEBUG
if (debuggable) {
enableRemoteDebugging()
Expand Down
3 changes: 2 additions & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ allprojects {
}

subprojects {
if (name in setOf("app", "debugger")) return@subprojects
// TODO: Migrate to applying dokka plugin per-project in conventions
if (name in setOf("app", "debugger", "server")) return@subprojects
apply(plugin = rootProject.libs.plugins.dokka.id)

dependencies {
Expand Down
28 changes: 18 additions & 10 deletions buildSrc/src/main/kotlin/ConfigureMultiplatform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import org.gradle.api.Project
import org.gradle.kotlin.dsl.getValue
import org.gradle.kotlin.dsl.getting
import org.jetbrains.kotlin.gradle.dsl.KotlinMultiplatformExtension
import org.jetbrains.kotlin.gradle.targets.js.dsl.ExperimentalWasmDsl

@OptIn(ExperimentalWasmDsl::class)
fun Project.configureMultiplatform(
ext: KotlinMultiplatformExtension,
jvm: Boolean = true,
Expand All @@ -15,25 +17,37 @@ fun Project.configureMultiplatform(
tvOs: Boolean = true,
macOs: Boolean = true,
watchOs: Boolean = true,
explicitApi: Boolean = true,
windows: Boolean = true,
wasmJs: Boolean = true,
wasmWasi: Boolean = false, // TODO: Coroutines do not support wasmWasi yet
) = ext.apply {
val libs by versionCatalog
if (explicitApi) explicitApi()
explicitApi()
applyDefaultHierarchyTemplate()
withSourcesJar(true)

if (linux) {
linuxX64()
linuxArm64()
mingwX64()
}

if (windows) mingwX64()

if (js) js(IR) {
browser()
nodejs()
binaries.library()
}

if (wasmJs) wasmJs {
moduleName = this@configureMultiplatform.name
nodejs()
browser()
binaries.library()
}

if (wasmWasi) wasmWasi()

if (android) androidTarget {
publishLibraryVariants("release")
}
Expand Down Expand Up @@ -61,13 +75,7 @@ fun Project.configureMultiplatform(
yield(watchosDeviceArm64())
yield(watchosSimulatorArm64())
}
}.forEach {
it.binaries.framework {
binaryOption("bundleId", Config.artifactId)
binaryOption("bundleVersion", Config.versionName)
baseName = Config.artifactId
}
}
}.toList() // for now, do nothing, but iterate the lazy sequence

sourceSets.apply {
if (jvm) {
Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/ConfigurePublication.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import org.gradle.plugins.signing.Sign
* Configures Maven publishing to sonatype for this project
*/
fun Project.publishMultiplatform() {
val properties by rootProject.localProperties
val properties = localProperties()
val isReleaseBuild = requireNotNull(properties["release"]).toString().toBooleanStrict()

val javadocTask = tasks.named("emptyJavadocJar") // TODO: dokka does not support kmp javadocs yet
Expand All @@ -43,7 +43,7 @@ fun Project.publishMultiplatform() {
* Publish the android artifact
*/
fun Project.publishAndroid(ext: LibraryExtension) = with(ext) {
val properties by rootProject.localProperties
val properties = localProperties()
publishing {
singleVariant(Config.publishingVariant) {
withSourcesJar()
Expand Down
13 changes: 5 additions & 8 deletions buildSrc/src/main/kotlin/Util.kt
Original file line number Diff line number Diff line change
Expand Up @@ -49,14 +49,11 @@ fun List<String>.toJavaArrayString() = buildString {

fun String.toBase64() = Base64.getEncoder().encodeToString(toByteArray())

val Project.localProperties
get() = lazy {
Properties().apply {
val file = File(rootProject.rootDir.absolutePath, "local.properties")
require(file.exists()) { "Please create root local.properties file" }
load(FileInputStream(file))
}
}
fun Project.localProperties() = Properties().apply {
val file = File(rootProject.rootDir.absolutePath, "local.properties")
require(file.exists()) { "Please create root local.properties file" }
load(FileInputStream(file))
}

fun stabilityLevel(version: String): Int {
Config.stabilityLevels.forEachIndexed { index, postfix ->
Expand Down
19 changes: 9 additions & 10 deletions compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ plugins {

android {
configureAndroidLibrary(this)
namespace = "${Config.namespace}.compose"

buildFeatures {
compose = true
}
}

kotlin {
Expand All @@ -20,13 +25,14 @@ kotlin {
watchOs = false,
tvOs = false,
linux = false,
js = false,
js = true,
wasmJs = true,
windows = false,
)
sourceSets {
androidMain.dependencies {
implementation(libs.compose.foundation)
implementation(libs.compose.preview)
implementation(libs.compose.lifecycle.viewmodel)
implementation(libs.compose.lifecycle.runtime)
api(projects.android)
}
Expand All @@ -37,18 +43,11 @@ kotlin {
}
jvmMain.dependencies {
implementation(compose.desktop.common)
implementation(libs.compose.lifecycle.runtime)
}
}
}

android {
namespace = "${Config.namespace}.compose"

buildFeatures {
compose = true
}
}

dependencies {
debugImplementation(libs.compose.tooling)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package pro.respawn.flowmvi.compose.android

import androidx.compose.runtime.Stable
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.LifecycleOwner
import androidx.lifecycle.repeatOnLifecycle
import pro.respawn.flowmvi.compose.api.SubscriberLifecycle
import pro.respawn.flowmvi.compose.api.SubscriptionMode

/**
* Converts this Android [LifecycleOwner] to a [SubscriberLifecycle].
*/
@Stable
public fun Lifecycle.asSubscriberOwner(): SubscriberLifecycle = SubscriberLifecycle { mode, block ->
repeatOnLifecycle(mode.asLifecycleState, block)
}

/**
* Converts this [SubscriptionMode] to a [Lifecycle.State]
*/
@Stable
public val SubscriptionMode.asLifecycleState: Lifecycle.State
get() = when (this) {
SubscriptionMode.Immediate -> Lifecycle.State.CREATED
SubscriptionMode.Started -> Lifecycle.State.STARTED
SubscriptionMode.Visible -> Lifecycle.State.RESUMED
}

/**
* Converts the [Lifecycle.State] to a [SubscriptionMode]
*
* [Lifecycle.State.DESTROYED] and [Lifecycle.State.INITIALIZED] **cannot** be used as valid subscription modes as
* it is not supported by Android
*/
@Stable
public val Lifecycle.State.asSubscriptionMode: SubscriptionMode
get() = when (this) {
Lifecycle.State.CREATED -> SubscriptionMode.Immediate
Lifecycle.State.STARTED -> SubscriptionMode.Started
Lifecycle.State.RESUMED -> SubscriptionMode.Visible
Lifecycle.State.DESTROYED,
Lifecycle.State.INITIALIZED -> error("Android lifecycle does not support $this as subscription mode")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package pro.respawn.flowmvi.compose.dsl

import androidx.compose.runtime.Composable
import androidx.compose.runtime.ReadOnlyComposable
import androidx.compose.ui.platform.LocalLifecycleOwner
import pro.respawn.flowmvi.compose.android.asSubscriberOwner
import pro.respawn.flowmvi.compose.api.SubscriberLifecycle

internal actual val PlatformLifecycle: SubscriberLifecycle?
@Composable @ReadOnlyComposable get() = LocalLifecycleOwner.current.lifecycle.asSubscriberOwner()
Loading

0 comments on commit fc3daee

Please sign in to comment.