-
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.
Integrations implemented
- Loading branch information
Showing
19 changed files
with
449 additions
and
69 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,24 +1,9 @@ | ||
/.idea/ | ||
|
||
/build/ | ||
/buildSrc/build/ | ||
/core/build/ | ||
/files/build/ | ||
/local-storage/build/ | ||
/shared-preferences/build/ | ||
/bundle/build/ | ||
/json/build/ | ||
/json/json-files/build/ | ||
/json/json-local-storage/build/ | ||
/json/json-shared-preferences/build/ | ||
/json/json-bundle/ | ||
|
||
/.gradle/ | ||
/buildSrc/.gradle/ | ||
.idea | ||
build | ||
.gradle | ||
|
||
/data/ | ||
/json/json-files/data/ | ||
|
||
/local.properties | ||
/deploy.properties | ||
/android-app-provider/build/ |
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,6 +1,6 @@ | ||
object AppInfo { | ||
const val PACKAGE = "fun.kotlingang.kds" | ||
const val VERSION = "1.0.1" | ||
const val VERSION = "1.1.0" | ||
const val NAME = "Kotlin Data Storage" | ||
const val DESCRIPTION = "Multiplatform Coroutine-Based Kotlin Library for storing data via kotlinx.serialization" | ||
} |
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,3 +1,9 @@ | ||
// Used in library | ||
const val serialization = "org.jetbrains.kotlinx:kotlinx-serialization-json:${Version.SERIALIZATION}" | ||
const val coroutines = "org.jetbrains.kotlinx:kotlinx-coroutines-core:${Version.COROUTINES}" | ||
const val nodejsExternals = "org.jetbrains.kotlinx:kotlinx-nodejs:${Version.NODEJS_EXTERNALS}" | ||
|
||
// Used for integrations | ||
const val composeRuntime = "androidx.compose.runtime:runtime:${Version.COMPOSE}" | ||
const val kvision = "io.kvision:kvision:${Version.KVISION}" | ||
|
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Extensions | ||
> Modules in this directory contains extensions to use with other frameworks |
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,3 @@ | ||
configure<`fun`.kotlingang.deploy.DeployEntity> { | ||
ignore = true | ||
} |
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,30 @@ | ||
plugins { | ||
id(plugin.androidLibrary) | ||
kotlin(plugin.android) | ||
} | ||
|
||
android { | ||
// Workaround since explicitApi() does not work for android | ||
kotlinOptions.freeCompilerArgs += "-Xexplicit-api=strict" | ||
kotlinOptions.freeCompilerArgs += "-Xopt-in=kotlin.RequiresOptIn" | ||
|
||
compileSdk = Version.COMPILE_SDK | ||
|
||
defaultConfig { | ||
targetSdk = Version.COMPILE_SDK | ||
minSdk = Version.MIN_SDK | ||
} | ||
|
||
buildFeatures { | ||
buildConfig = false | ||
} | ||
} | ||
|
||
configure<`fun`.kotlingang.deploy.DeployEntity> { | ||
componentName = "release" | ||
} | ||
|
||
dependencies { | ||
api(core) | ||
implementation(composeRuntime) | ||
} |
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 @@ | ||
<manifest package="fun.kotlingang.kds"/> |
78 changes: 78 additions & 0 deletions
78
...ns-androidx/src/main/java/fun/kotlingang/kds/compose/mutable_state/StorageMutableState.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,78 @@ | ||
package `fun`.kotlingang.kds.compose.mutable_state | ||
|
||
import `fun`.kotlingang.kds.annotation.RawSetterGetter | ||
import `fun`.kotlingang.kds.annotation.UnsafeKType | ||
import `fun`.kotlingang.kds.optional.getOrDefault | ||
import `fun`.kotlingang.kds.storage.KTypeDataStorage | ||
import androidx.compose.runtime.MutableState | ||
import androidx.compose.runtime.SnapshotMutationPolicy | ||
import androidx.compose.runtime.mutableStateOf | ||
import androidx.compose.runtime.structuralEqualityPolicy | ||
import kotlin.reflect.KProperty | ||
import kotlin.reflect.KType | ||
import kotlin.reflect.typeOf | ||
|
||
|
||
public inline fun <reified T> KTypeDataStorage.mutableState ( | ||
policy: SnapshotMutationPolicy<T?> = structuralEqualityPolicy(), | ||
): StorageMutableStateProvider<T?> = mutableState(policy) { null } | ||
|
||
|
||
@OptIn(ExperimentalStdlibApi::class, UnsafeKType::class) | ||
public inline fun <reified T> KTypeDataStorage.mutableState ( | ||
policy: SnapshotMutationPolicy<T> = structuralEqualityPolicy(), | ||
noinline defaultValue: () -> T, | ||
): StorageMutableStateProvider<T> = StorageMutableStateProvider ( | ||
storage = this, | ||
type = typeOf<T>(), | ||
defaultValue = defaultValue, | ||
policy = policy | ||
) | ||
|
||
|
||
@OptIn(UnsafeKType::class) | ||
public class StorageMutableStateProvider<T> @UnsafeKType constructor ( | ||
private val storage: KTypeDataStorage, | ||
private val type: KType, | ||
private val defaultValue: () -> T, | ||
private val policy: SnapshotMutationPolicy<T> | ||
) { | ||
private lateinit var name: String | ||
private val state by lazy { StorageMutableState(storage, name, type, defaultValue, policy) } | ||
|
||
public operator fun getValue(thisRef: Any?, property: KProperty<*>): StorageMutableState<T> { | ||
name = property.name | ||
return state | ||
} | ||
|
||
} | ||
|
||
@OptIn(RawSetterGetter::class, UnsafeKType::class) | ||
public class StorageMutableState<T> @UnsafeKType constructor ( | ||
private val storage: KTypeDataStorage, | ||
private val key: String, | ||
private val type: KType, | ||
defaultValue: () -> T, | ||
policy: SnapshotMutationPolicy<T> | ||
) : MutableState<T> { | ||
private val state = mutableStateOf ( | ||
storage.getWithKType<T>(key, type).getOrDefault(defaultValue), | ||
policy = policy | ||
) | ||
|
||
override var value: T | ||
get() = state.value | ||
set(value) { | ||
storage.putWithKType(key, type, value) | ||
state.value = value | ||
} | ||
|
||
override fun component1(): T = value | ||
|
||
override fun component2(): (T) -> Unit = { value = it } | ||
|
||
public operator fun getValue(thisRef: Any?, property: KProperty<*>): T = value | ||
public operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) { | ||
this.value = value | ||
} | ||
} |
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,28 @@ | ||
@file:Suppress("UNUSED_VARIABLE") | ||
|
||
plugins { | ||
kotlin(plugin.multiplatform) | ||
} | ||
|
||
kotlin { | ||
explicitApi() | ||
|
||
jvm() | ||
js(IR) { | ||
nodejs() | ||
browser() | ||
} | ||
|
||
sourceSets { | ||
val commonMain by getting { | ||
dependencies { | ||
api(core) | ||
implementation(coroutines) | ||
} | ||
} | ||
|
||
all { | ||
languageSettings.useExperimentalAnnotation("kotlin.RequiresOptIn") | ||
} | ||
} | ||
} |
Oops, something went wrong.