Skip to content

Commit

Permalink
Upgrade to Kotlin 2.0 (#37)
Browse files Browse the repository at this point in the history
Upgrade to Kotlin 2.0 but not change other dependencies. 

Tested with iOS and Anroid clients.
  • Loading branch information
alsedi authored Oct 27, 2024
1 parent 6a36018 commit 09ef1af
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@ gnsp.disableApplyOnlyOnRootProjectEnforcement = true

libBaseGroup=com.umain
libAndroidNamespace=com.umain.revolver
libBaseVersion=1.4.3
libBaseVersion=1.5.3
iosDeploymentTarget=14.0
2 changes: 1 addition & 1 deletion revolver/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@file:Suppress("UnstableApiUsage")

plugins {
kotlin("multiplatform") version "1.9.23"
kotlin("multiplatform") version "2.0.20"
id("com.android.library")
id("maven-publish")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package com.umain.revolver.flow
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector

expect class CFlow<out T : Any>(flow: Flow<T>, coroutineScope: CoroutineScope) : Flow<T>
expect class CFlow<out T : Any>(flow: Flow<T>, coroutineScope: CoroutineScope) : Flow<T> {
override suspend fun collect(collector: FlowCollector<T>)
}

@Suppress("OPT_IN_USAGE")
fun <T : Any> Flow<T>.cFlow(coroutineScope: CoroutineScope = GlobalScope): CFlow<T> = CFlow(this, coroutineScope)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@ package com.umain.revolver.flow

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.SharedFlow

expect open class CSharedFlow<out T : Any>(flow: SharedFlow<T>, coroutineScope: CoroutineScope) : SharedFlow<T>
expect open class CSharedFlow<out T : Any>(flow: SharedFlow<T>, coroutineScope: CoroutineScope) : SharedFlow<T> {
override val replayCache: List<T>
override suspend fun collect(collector: FlowCollector<T>): Nothing
}

@Suppress("OPT_IN_USAGE")
fun <T : Any> SharedFlow<T>.cSharedFlow(coroutineScope: CoroutineScope = GlobalScope): CSharedFlow<T> = CSharedFlow(this, coroutineScope)
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,14 @@ package com.umain.revolver.flow

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.StateFlow

expect open class CStateFlow<out T : Any>(flow: StateFlow<T>, coroutineScope: CoroutineScope) : StateFlow<T>
expect open class CStateFlow<out T : Any>(flow: StateFlow<T>, coroutineScope: CoroutineScope) : StateFlow<T> {
override val value: T
override val replayCache: List<T>
override suspend fun collect(collector: FlowCollector<T>): Nothing
}

@Suppress("OPT_IN_USAGE")
fun <T : Any> StateFlow<T>.cStateFlow(coroutineScope: CoroutineScope = GlobalScope): CStateFlow<T> = CStateFlow(this,coroutineScope)
4 changes: 4 additions & 0 deletions revolver/src/iosMain/kotlin/com/umain/revolver/flow/CFlow.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
Expand All @@ -13,6 +14,9 @@ actual open class CFlow<out T : Any> actual constructor(
private val flow: Flow<T>,
private val coroutineScope: CoroutineScope,
) : Flow<T> by flow {
actual override suspend fun collect(collector: FlowCollector<T>) {
flow.collect(collector)
}

private fun watch(
coroutineScope: CoroutineScope,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@ actual open class CSharedFlow<out T : Any> actual constructor(
private val flow: SharedFlow<T>,
private val coroutineScope: CoroutineScope,
) : CFlow<T>(flow,coroutineScope), SharedFlow<T> {
override val replayCache: List<T> get() = flow.replayCache
actual override val replayCache: List<T>
get() = flow.replayCache

override suspend fun collect(collector: FlowCollector<T>): Nothing = flow.collect(collector)
actual override suspend fun collect(collector: FlowCollector<T>): Nothing {
flow.collect(collector)
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,19 @@
package com.umain.revolver.flow

import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.FlowCollector
import kotlinx.coroutines.flow.StateFlow

actual open class CStateFlow<out T : Any> actual constructor(
private val flow: StateFlow<T>,
private val coroutineScope: CoroutineScope,
) : CSharedFlow<T>(flow,coroutineScope), StateFlow<T> {
override val value: T get() = flow.value
actual override val value: T get() = flow.value

actual override val replayCache: List<T>
get() = super.replayCache

actual override suspend fun collect(collector: FlowCollector<T>): Nothing {
super.collect(collector)
}
}

0 comments on commit 09ef1af

Please sign in to comment.