-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
53 changed files
with
145 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,56 @@ | ||
import org.jlleitschuh.gradle.ktlint.KtlintExtension | ||
|
||
plugins { | ||
kotlin("jvm") version libs.versions.kotlin.get() | ||
alias(libs.plugins.kotlinMultiplatform) | ||
alias(libs.plugins.ktlint) | ||
alias(libs.plugins.mavenPublish) | ||
alias(libs.plugins.kotest) | ||
alias(libs.plugins.atomicfu) | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
} | ||
|
||
val compileTestKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks | ||
compileTestKotlin.kotlinOptions { | ||
freeCompilerArgs += "-Xuse-experimental=kotlinx.coroutines.ExperimentalCoroutinesApi" | ||
jvm { | ||
withJava() | ||
} | ||
iosX64() | ||
iosArm64() | ||
iosSimulatorArm64() | ||
macosX64() | ||
macosArm64() | ||
watchosArm32() | ||
watchosArm64() | ||
watchosDeviceArm64() | ||
watchosSimulatorArm64() | ||
watchosX64() | ||
tvosArm64() | ||
tvosSimulatorArm64() | ||
tvosX64() | ||
|
||
sourceSets { | ||
commonMain.dependencies { | ||
implementation(libs.coroutinesCore) | ||
} | ||
|
||
commonTest.dependencies { | ||
implementation(libs.kotest.framework.engine) | ||
implementation(libs.kotest.assertions) | ||
implementation(libs.coroutinesTest) | ||
} | ||
|
||
jvmTest.dependencies { | ||
implementation(libs.kotestRunner) | ||
} | ||
} | ||
} | ||
|
||
configure<KtlintExtension> { | ||
version.set(libs.versions.ktlint.lib.get()) | ||
} | ||
|
||
tasks.getByName<Test>("test") { | ||
useJUnitPlatform() | ||
} | ||
|
||
dependencies { | ||
implementation(libs.coroutinesCore) | ||
|
||
testImplementation(libs.kotestRunner) | ||
testImplementation(libs.coroutinesTest) | ||
tasks { | ||
withType<Test> { | ||
useJUnitPlatform() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
29 changes: 17 additions & 12 deletions
29
...com/adidas/mvi/sideeffects/SideEffects.kt → ...com/adidas/mvi/sideeffects/SideEffects.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
package com.adidas.mvi.sideeffects | ||
|
||
import java.util.LinkedList | ||
import java.util.Queue | ||
import kotlinx.atomicfu.AtomicRef | ||
import kotlinx.atomicfu.atomic | ||
|
||
/** | ||
* A thread-safe side effect container | ||
* It only returns each SideEffect once, if you use it as an [Iterable] it will emit each SideEffect and remove them so it's a perfect case for one shot SideEffects. | ||
* It locks itself, so you can't add and read at the same time, also it's not possible to read it at the same time from different threads, being completely thread-safe. | ||
*/ | ||
|
||
public class SideEffects<T>() : Iterable<T> { | ||
private val sideEffects: Queue<T> = LinkedList() | ||
private val sideEffects: AtomicRef<MutableList<T>> = atomic(ArrayList()) | ||
|
||
// Private constructor to initialize from an Iterable | ||
private constructor(sideEffects: Iterable<T>) : this() { | ||
this.sideEffects.addAll(sideEffects) | ||
this.sideEffects.value.addAll(sideEffects) | ||
} | ||
|
||
public fun add(vararg sideEffectsToAdd: T): SideEffects<T> { | ||
return SideEffects(sideEffects + sideEffectsToAdd) | ||
val newList = sideEffects.value.toMutableList() | ||
newList.addAll(sideEffectsToAdd) | ||
return SideEffects(newList) | ||
} | ||
|
||
public fun clear(): SideEffects<T> { | ||
return SideEffects() | ||
} | ||
|
||
override fun iterator(): Iterator<T> = | ||
iterator { | ||
do { | ||
val nextSideEffect: T? = sideEffects.poll() | ||
nextSideEffect?.let { yield(it) } | ||
} while (nextSideEffect != null) | ||
override fun iterator(): Iterator<T> = iterator { | ||
while (true) { | ||
val currentList = sideEffects.value | ||
if (currentList.isEmpty()) break | ||
val nextSideEffect = currentList.removeFirstOrNull() | ||
nextSideEffect?.let { yield(it) } | ||
} | ||
} | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
35 changes: 35 additions & 0 deletions
35
mvi/src/commonTest/kotlin/com/adidas/mvi/CoroutineListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package com.adidas.mvi | ||
|
||
import io.kotest.core.listeners.TestListener | ||
import io.kotest.core.test.TestCase | ||
import io.kotest.core.test.TestResult | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.cancel | ||
import kotlinx.coroutines.test.TestCoroutineScheduler | ||
import kotlinx.coroutines.test.TestDispatcher | ||
import kotlinx.coroutines.test.UnconfinedTestDispatcher | ||
import kotlinx.coroutines.test.resetMain | ||
import kotlinx.coroutines.test.setMain | ||
|
||
internal class CoroutineListener( | ||
internal val testCoroutineDispatcher: TestDispatcher = UnconfinedTestDispatcher( | ||
TestCoroutineScheduler() | ||
), | ||
) : TestListener { | ||
|
||
internal val dispatchersContainer: DispatchersContainer = | ||
FixedDispatchersContainer(testCoroutineDispatcher) | ||
|
||
override suspend fun beforeContainer(testCase: TestCase) { | ||
Dispatchers.setMain(testCoroutineDispatcher) | ||
} | ||
|
||
override suspend fun afterContainer(testCase: TestCase, result: TestResult) { | ||
Dispatchers.resetMain() | ||
testCoroutineDispatcher.scheduler.cancel() | ||
} | ||
|
||
public fun advanceUntilIdle() { | ||
testCoroutineDispatcher.scheduler.advanceUntilIdle() | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -117,4 +117,4 @@ internal class MultimapTests : BehaviorSpec({ | |
} | ||
} | ||
} | ||
}) | ||
}) |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.