Skip to content

Commit

Permalink
Set up sample
Browse files Browse the repository at this point in the history
  • Loading branch information
matt-ramotar committed Apr 21, 2024
1 parent 3c0d3fc commit ff4ec28
Show file tree
Hide file tree
Showing 65 changed files with 1,647 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ kotlin {
nodejs()
}
cocoapods {
summary = "Market/core"
summary = "Market"
homepage = "https://github.com/MobileNativeFoundation/Store"
ios.deploymentTarget = "13"
version = libs.versions.store.get()
Expand Down Expand Up @@ -54,7 +54,7 @@ kotlin {
}

android {
namespace = "org.mobilenativefoundation.market.core"
namespace = "org.mobilenativefoundation.market"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
compileSdk = 33
Expand Down
File renamed without changes.
122 changes: 122 additions & 0 deletions experimental/market/repository/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
import com.vanniktech.maven.publish.SonatypeHost
import org.jetbrains.dokka.gradle.DokkaTask

plugins {
kotlin("multiplatform")
kotlin("plugin.serialization")
id("com.android.library")
id("com.vanniktech.maven.publish")
id("org.jetbrains.dokka")
id("org.jetbrains.kotlinx.kover")
id("co.touchlab.faktory.kmmbridge")
`maven-publish`
kotlin("native.cocoapods")
id("kotlinx-atomicfu")
}

kotlin {
android()
jvm()
iosArm64()
iosX64()
linuxX64()
iosSimulatorArm64()
js {
browser()
nodejs()
}
cocoapods {
summary = "Market/repository"
homepage = "https://github.com/MobileNativeFoundation/Store"
ios.deploymentTarget = "13"
version = libs.versions.store.get()
}

sourceSets {
val commonMain by getting {
dependencies {
implementation(libs.kotlin.stdlib)
implementation(libs.kotlinx.coroutines.core)
}
}

val androidMain by getting
val commonTest by getting {
dependencies {
implementation(kotlin("test"))
implementation(libs.turbine)
implementation(libs.kotlinx.coroutines.test)
}
}
}

jvmToolchain(11)
}

android {
namespace = "org.mobilenativefoundation.market.repository"

sourceSets["main"].manifest.srcFile("src/androidMain/AndroidManifest.xml")
compileSdk = 33

defaultConfig {
minSdk = 24
targetSdk = 33
}

lint {
disable += "ComposableModifierFactory"
disable += "ModifierFactoryExtensionFunction"
disable += "ModifierFactoryReturnType"
disable += "ModifierFactoryUnreferencedReceiver"
}

compileOptions {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
}

tasks.withType<DokkaTask>().configureEach {
dokkaSourceSets.configureEach {
reportUndocumented.set(false)
skipDeprecated.set(true)
jdkVersion.set(11)
}
}

mavenPublishing {
publishToMavenCentral(SonatypeHost.S01)
signAllPublications()
}

addGithubPackagesRepository()
kmmbridge {
githubReleaseArtifacts()
githubReleaseVersions()
versionPrefix.set(libs.versions.market.get())
spm()
}

koverMerged {
enable()

xmlReport {
onCheck.set(true)
reportFile.set(layout.projectDirectory.file("kover/coverage.xml"))
}

htmlReport {
onCheck.set(true)
reportDir.set(layout.projectDirectory.dir("kover/html"))
}

verify {
onCheck.set(true)
}
}

atomicfu {
transformJvm = false
transformJs = false
}
3 changes: 3 additions & 0 deletions experimental/market/repository/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
POM_NAME=org.mobilenativefoundation.store
POM_ARTIFACT_ID=paging5
POM_PACKAGING=jar
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mobilenativefoundation.market.repository

enum class ConflictResolutionStrategy {
DESTRUCTIVE, // Overwrite local changes that haven't synced with the network
DEFER, // Before pulling, push local changes that haven't synced with the network
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.mobilenativefoundation.market.repository

enum class DataSource {
MEMORY_CACHE,
SOURCE_OF_TRUTH,
NETWORK
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package org.mobilenativefoundation.market.repository

fun interface Delete<K : Any, D : Any, E : Any> {
suspend fun delete(request: Request<K, D>): Response<E>

data class Request<K : Any, D : Any>(
val key: K,
val strategy: Strategy
)

data class Strategy(
val caches: Boolean,
val network: Boolean
)

sealed interface Response<out E : Any> {
data object Success : Response<Nothing>

data class Error<E : Any>(
val error: E
) : Response<E>
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package org.mobilenativefoundation.market.repository

interface MutableRepository<K : Any, D : Any, E : Any> : Repository<K, D, E>, Write<K, D, E>
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package org.mobilenativefoundation.market.repository


fun interface Read<K : Any, D : Any, E : Any> {
suspend fun read(request: Request<K>): Response<D, E>

data class Request<K : Any>(
val key: K,
val strategy: Strategy
)

sealed interface Response<out D : Any, out E : Any> {
data class Success<D : Any>(val data: D, val origin: DataSource) : Response<D, Nothing>
data class Error<E : Any>(val error: E) : Response<Nothing, E>
}

data class Strategy(
val order: List<DataSource>,
val conflictResolutionStrategy: ConflictResolutionStrategy
) {
companion object {
val CACHE_FIRST = Strategy(
order = listOf(
DataSource.MEMORY_CACHE,
DataSource.SOURCE_OF_TRUTH,
DataSource.NETWORK
),
conflictResolutionStrategy = ConflictResolutionStrategy.DEFER
)
}
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mobilenativefoundation.market.repository

interface Repository<K : Any, D : Any, E : Any> :
Stream<K, D, E>,
Read<K, D, E>,
Delete<K, D, E>
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.mobilenativefoundation.market.repository

import kotlinx.coroutines.flow.Flow

fun interface Stream<K : Any, D : Any, E : Any> {
fun stream(request: Request<K>): Flow<Response<D, E>>

data class Request<K : Any>(
val key: K,
val strategy: Strategy
)

sealed interface Response<out D : Any, out E : Any> {
data class Success<D : Any>(val data: D) : Response<D, Nothing>
data class Error<E : Any>(val error: E) : Response<Nothing, E>
data object Loading : Response<Nothing, Nothing>
}

sealed interface Strategy
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.mobilenativefoundation.market.repository

fun interface Write<K : Any, D : Any, E : Any> {
fun write(request: Request<K, D>): Response<D, E>

data class Request<K : Any, D : Any>(
val key: K,
val data: D,
val strategy: Strategy
)

data class Strategy(
val caches: Boolean,
val network: Boolean
)

sealed interface Response<D : Any, E : Any> {
data class Success<D : Any>(
val data: D
) : Response<D, Nothing>

data class Error<E : Any>(
val error: E
) : Response<Nothing, E>
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.mobilenativefoundation.market

interface Market {
interface State
interface Action
interface Middleware

fun interface Reducer<S : State, A : Action> {
fun reduce(state: S, action: A): S
}
}
Loading

0 comments on commit ff4ec28

Please sign in to comment.