generated from yumemi-inc/multiplatform-library-template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from yumemi-inc/add_modules
Add modules
- Loading branch information
Showing
29 changed files
with
878 additions
and
456 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
plugins { | ||
alias(libs.plugins.androidLibrary) apply false | ||
alias(libs.plugins.kotlinMultiplatform) apply false | ||
alias(libs.plugins.kotlinMultiplatform) apply false | ||
alias(libs.plugins.compose.compiler) apply false | ||
alias(libs.plugins.vanniktech.mavenPublish) apply false | ||
} |
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,13 +1,20 @@ | ||
[versions] | ||
agp = "8.6.1" | ||
kotlin = "2.0.20" | ||
android-minSdk = "24" | ||
coroutines = "1.9.0" | ||
compose = "1.7.5" | ||
kermit = "1.2.2" | ||
android-minSdk = "21" | ||
android-compileSdk = "34" | ||
|
||
[libraries] | ||
coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref = "coroutines" } | ||
compose-runtime = { group = "androidx.compose.runtime", name = "runtime", version.ref = "compose" } | ||
logger-kermit = { group = "co.touchlab", name = "kermit", version.ref = "kermit" } | ||
kotlin-test = { module = "org.jetbrains.kotlin:kotlin-test", version.ref = "kotlin" } | ||
|
||
[plugins] | ||
androidLibrary = { id = "com.android.library", version.ref = "agp" } | ||
kotlinMultiplatform = { id = "org.jetbrains.kotlin.multiplatform", version.ref = "kotlin" } | ||
compose-compiler = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" } | ||
vanniktech-mavenPublish = { id = "com.vanniktech.maven.publish", version = "0.29.0" } |
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 0 additions & 4 deletions
4
library/src/androidMain/kotlin/io/yumemi/something/fibiprops.android.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
library/src/androidUnitTest/kotlin/io/yumemi/something/AndroidFibiTest.kt
This file was deleted.
Oops, something went wrong.
17 changes: 0 additions & 17 deletions
17
library/src/commonMain/kotlin/io/yumemi/something/CustomFibi.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
library/src/commonTest/kotlin/io/yumemi/something/FibiTest.kt
This file was deleted.
Oops, something went wrong.
4 changes: 0 additions & 4 deletions
4
library/src/iosMain/kotlin/io/yumemi/something/fibiprops.ios.kt
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
library/src/iosTest/kotlin/io/yumemi/something/IosFibiTest.kt
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import com.vanniktech.maven.publish.SonatypeHost | ||
import org.jetbrains.kotlin.gradle.ExperimentalKotlinGradlePluginApi | ||
import org.jetbrains.kotlin.gradle.dsl.JvmTarget | ||
|
||
plugins { | ||
alias(libs.plugins.kotlinMultiplatform) | ||
alias(libs.plugins.androidLibrary) | ||
alias(libs.plugins.compose.compiler) | ||
alias(libs.plugins.vanniktech.mavenPublish) | ||
} | ||
|
||
group = "io.yumemi.tart" | ||
version = "1.0.0-beta01" | ||
|
||
kotlin { | ||
androidTarget { | ||
publishLibraryVariants("release") | ||
@OptIn(ExperimentalKotlinGradlePluginApi::class) | ||
compilerOptions { | ||
jvmTarget.set(JvmTarget.JVM_1_8) | ||
} | ||
} | ||
// FIXME: comment out iOS because build error | ||
// iosX64() | ||
// iosArm64() | ||
// iosSimulatorArm64() | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
// put your multiplatform dependencies here | ||
implementation(project(":tart-core")) | ||
implementation(libs.compose.runtime) | ||
} | ||
} | ||
val commonTest by getting { | ||
dependencies { | ||
implementation(libs.kotlin.test) | ||
} | ||
} | ||
} | ||
} | ||
|
||
android { | ||
namespace = "io.yumemi.tart.compose" | ||
compileSdk = libs.versions.android.compileSdk.get().toInt() | ||
defaultConfig { | ||
minSdk = libs.versions.android.minSdk.get().toInt() | ||
} | ||
} | ||
|
||
mavenPublishing { | ||
publishToMavenCentral(SonatypeHost.CENTRAL_PORTAL) | ||
|
||
if (System.getenv("ORG_GRADLE_PROJECT_mavenCentralUsername") != null) { | ||
signAllPublications() | ||
} | ||
|
||
coordinates(group.toString(), "tart-compose", version.toString()) | ||
|
||
pom { | ||
name = "Tart" | ||
description = "A Kotlin Multiplatform Flux framework." | ||
inceptionYear = "2024" | ||
url = "https://github.com/yumemi-inc/Tart/" | ||
licenses { | ||
license { | ||
name = "MIT" | ||
url = "https://opensource.org/licenses/MIT" | ||
distribution = "https://opensource.org/licenses/MIT" | ||
} | ||
} | ||
developers { | ||
developer { | ||
id = "yumemi-inc" | ||
name = "YUMEMI Inc." | ||
url = "https://github.com/yumemi-inc/" | ||
} | ||
} | ||
scm { | ||
url = "https://github.com/yumemi-inc/Tart/" | ||
connection = "scm:git:git://github.com/yumemi-inc/Tart.git" | ||
developerConnection = "scm:git:git://github.com/yumemi-inc/Tart.git" | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
tart-compose/src/commonMain/kotlin/io/yumemi/tart/compose/ComposeStore.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,63 @@ | ||
package io.yumemi.tart.compose | ||
|
||
import androidx.compose.runtime.Composable | ||
import androidx.compose.runtime.LaunchedEffect | ||
import androidx.compose.runtime.collectAsState | ||
import androidx.compose.runtime.getValue | ||
import io.yumemi.tart.core.Action | ||
import io.yumemi.tart.core.Event | ||
import io.yumemi.tart.core.State | ||
import io.yumemi.tart.core.Store | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.emptyFlow | ||
import kotlinx.coroutines.flow.filter | ||
|
||
@Suppress("unused") | ||
class ComposeStore<S : State, A : Action, E : Event> private constructor( | ||
val state: S, | ||
val dispatch: (action: A) -> Unit, | ||
val eventFlow: Flow<E>, | ||
) { | ||
@Composable | ||
inline fun <reified S2 : S> render(block: ComposeStore<S2, A, E>.() -> Unit) { | ||
if (state is S2) { | ||
block( | ||
mock( | ||
state = state, | ||
dispatch = dispatch, | ||
eventFlow = eventFlow, | ||
), | ||
) | ||
} | ||
} | ||
|
||
@Composable | ||
inline fun <reified E2 : E> handle(crossinline block: ComposeStore<S, A, E>.(event: E2) -> Unit) { | ||
LaunchedEffect(Unit) { | ||
eventFlow.filter { it is E2 }.collect { | ||
block(this@ComposeStore, it as E2) | ||
} | ||
} | ||
} | ||
|
||
companion object { | ||
@Composable | ||
fun <S : State, A : Action, E : Event> create(store: Store<S, A, E>): ComposeStore<S, A, E> { | ||
val state by store.state.collectAsState() | ||
return ComposeStore( | ||
state = state, | ||
dispatch = store::dispatch, | ||
eventFlow = store.event, | ||
) | ||
} | ||
|
||
@Composable | ||
fun <S : State, A : Action, E : Event> mock(state: S, dispatch: (action: A) -> Unit = {}, eventFlow: Flow<E> = emptyFlow()): ComposeStore<S, A, E> { | ||
return ComposeStore( | ||
state = state, | ||
dispatch = dispatch, | ||
eventFlow = eventFlow, | ||
) | ||
} | ||
} | ||
} |
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
5 changes: 5 additions & 0 deletions
5
tart-core/src/commonMain/kotlin/io/yumemi/tart/core/Contract.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,5 @@ | ||
package io.yumemi.tart.core | ||
|
||
interface State | ||
interface Action | ||
interface Event |
19 changes: 19 additions & 0 deletions
19
tart-core/src/commonMain/kotlin/io/yumemi/tart/core/Middleware.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,19 @@ | ||
package io.yumemi.tart.core | ||
|
||
import kotlinx.coroutines.CoroutineScope | ||
|
||
interface Middleware<S : State, A : Action, E : Event> { | ||
suspend fun onInit(store: Store<S, A, E>, coroutineScope: CoroutineScope) {} | ||
suspend fun beforeActionDispatch(state: S, action: A) {} | ||
suspend fun afterActionDispatch(state: S, action: A, nextState: S) {} | ||
suspend fun beforeEventEmit(state: S, event: E) {} | ||
suspend fun afterEventEmit(state: S, event: E) {} | ||
suspend fun beforeStateEnter(state: S) {} | ||
suspend fun afterStateEnter(state: S, nextState: S) {} | ||
suspend fun beforeStateExit(state: S) {} | ||
suspend fun afterStateExit(state: S) {} | ||
suspend fun beforeStateChange(state: S, nextState: S) {} | ||
suspend fun afterStateChange(state: S, prevState: S) {} | ||
suspend fun beforeError(state: S, error: Throwable) {} | ||
suspend fun afterError(state: S, nextState: S, error: Throwable) {} | ||
} |
Oops, something went wrong.