Skip to content

Commit

Permalink
Updated targets and made API explicit for parcelable-compose module
Browse files Browse the repository at this point in the history
  • Loading branch information
chRyNaN committed Aug 27, 2024
1 parent 6c13a56 commit 359d26f
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 753 deletions.
696 changes: 19 additions & 677 deletions kotlin-js-store/yarn.lock

Large diffs are not rendered by default.

24 changes: 2 additions & 22 deletions parcelable-compose/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,11 @@ plugins {
id("org.jetbrains.dokka")
id("org.jetbrains.compose")
id("org.jetbrains.kotlin.plugin.compose")
id("parcelable.multiplatform")
id("parcelable.publish")
}

kotlin {
applyDefaultHierarchyTemplate()

androidTarget()

jvm()

js(IR) {
browser()
}

@Suppress("OPT_IN_USAGE")
wasmJs {
browser()
}

iosX64()
iosArm64()
iosSimulatorArm64()
macosX64()
macosArm64()

sourceSets {
all {
languageSettings.optIn("kotlin.RequiresOptIn")
Expand All @@ -41,7 +21,7 @@ kotlin {
dependencies {
implementation(project(":parcelable-core"))

implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:_")
implementation(KotlinX.serialization.json)

implementation(compose.runtime)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ package com.chrynan.parcelable.compose
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState

actual typealias Saver<Original, Saveable> = androidx.compose.runtime.saveable.Saver<Original, Saveable>
public actual typealias Saver<Original, Saveable> = androidx.compose.runtime.saveable.Saver<Original, Saveable>

actual typealias SaverScope = androidx.compose.runtime.saveable.SaverScope
public actual typealias SaverScope = androidx.compose.runtime.saveable.SaverScope

actual fun <Original, Saveable : Any> Saver(
public actual fun <Original, Saveable : Any> Saver(
save: SaverScope.(value: Original) -> Saveable?,
restore: (value: Saveable) -> Original?
): Saver<Original, Saveable> = androidx.compose.runtime.saveable.Saver(save = save, restore = restore)

actual fun <T> autoSaver(): Saver<T, Any> = androidx.compose.runtime.saveable.autoSaver()
public actual fun <T> autoSaver(): Saver<T, Any> = androidx.compose.runtime.saveable.autoSaver()

actual fun <Original, Saveable> listSaver(
public actual fun <Original, Saveable> listSaver(
save: SaverScope.(value: Original) -> List<Saveable>,
restore: (list: List<Saveable>) -> Original?
): Saver<Original, Any> = androidx.compose.runtime.saveable.listSaver(save = save, restore = restore)

actual fun <T> mapSaver(
public actual fun <T> mapSaver(
save: SaverScope.(value: T) -> Map<String, Any?>,
restore: (Map<String, Any?>) -> T?
): Saver<T, Any> = androidx.compose.runtime.saveable.mapSaver(save = save, restore = restore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ internal expect fun <T : Any> InternalParcelableSaver(
* Creates a [Saver] that uses the provided [parcelable] and [serializer] to save and restore the value.
*/
@ExperimentalSerializationApi
fun <T : Any> ParcelableSaver(
public fun <T : Any> ParcelableSaver(
parcelable: Parcelable = Parcelable.Default,
serializer: KSerializer<T>
): Saver<T, *> = InternalParcelableSaver(
Expand All @@ -31,7 +31,7 @@ fun <T : Any> ParcelableSaver(
*/
@Composable
@ExperimentalSerializationApi
fun <T : Any> rememberSavable(
public fun <T : Any> rememberSavable(
vararg inputs: Any?,
parcelable: Parcelable = Parcelable.Default,
serializer: KSerializer<T>,
Expand All @@ -48,7 +48,7 @@ fun <T : Any> rememberSavable(
*/
@Composable
@ExperimentalSerializationApi
fun <T : Any> rememberSaveable(
public fun <T : Any> rememberSaveable(
vararg inputs: Any?,
parcelable: Parcelable = Parcelable.Default,
serializer: KSerializer<T>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,32 +5,32 @@ package com.chrynan.parcelable.compose
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState

expect interface Saver<Original, Saveable : Any> {
public expect interface Saver<Original, Saveable : Any> {

fun SaverScope.save(value: Original): Saveable?
public fun SaverScope.save(value: Original): Saveable?

fun restore(value: Saveable): Original?
public fun restore(value: Saveable): Original?
}

expect fun interface SaverScope {
public expect fun interface SaverScope {

fun canBeSaved(value: Any): Boolean
public fun canBeSaved(value: Any): Boolean
}

@Suppress("FunctionName")
expect fun <Original, Saveable : Any> Saver(
public expect fun <Original, Saveable : Any> Saver(
save: SaverScope.(value: Original) -> Saveable?,
restore: (value: Saveable) -> Original?
): Saver<Original, Saveable>

expect fun <T> autoSaver(): Saver<T, Any>
public expect fun <T> autoSaver(): Saver<T, Any>

expect fun <Original, Saveable> listSaver(
public expect fun <Original, Saveable> listSaver(
save: SaverScope.(value: Original) -> List<Saveable>,
restore: (list: List<Saveable>) -> Original?
): Saver<Original, Any>

expect fun <T> mapSaver(
public expect fun <T> mapSaver(
save: SaverScope.(value: T) -> Map<String, Any?>,
restore: (Map<String, Any?>) -> T?
): Saver<T, Any>
Expand All @@ -52,17 +52,18 @@ internal expect fun <T> internalRememberSaveable(
): MutableState<T>

@Composable
fun <T : Any> rememberSaveable(
public fun <T : Any> rememberSaveable(
vararg inputs: Any?,
saver: Saver<T, out Any> = autoSaver(),
key: String? = null,
init: () -> T
): T = internalRememberSaveable(inputs = inputs, saver = saver, key = key, init = init)

@Composable
fun <T> rememberSaveable(
public fun <T> rememberSaveable(
vararg inputs: Any?,
stateSaver: Saver<T, out Any>,
key: String? = null,
init: () -> MutableState<T>
): MutableState<T> = internalRememberSaveable(inputs = inputs, stateSaver = stateSaver, key = key, init = init)
): MutableState<T> =
internalRememberSaveable(inputs = inputs, stateSaver = stateSaver, key = key, init = init)
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.remember

actual interface Saver<Original, Saveable : Any> {
public actual interface Saver<Original, Saveable : Any> {

actual fun SaverScope.save(value: Original): Saveable?
public actual fun SaverScope.save(value: Original): Saveable?

actual fun restore(value: Saveable): Original?
public actual fun restore(value: Saveable): Original?
}

actual fun interface SaverScope {
public actual fun interface SaverScope {

actual fun canBeSaved(value: Any): Boolean
public actual fun canBeSaved(value: Any): Boolean
}

actual fun <Original, Saveable : Any> Saver(
public actual fun <Original, Saveable : Any> Saver(
save: SaverScope.(value: Original) -> Saveable?,
restore: (value: Saveable) -> Original?
): Saver<Original, Saveable> = object : Saver<Original, Saveable> {
Expand All @@ -30,7 +30,7 @@ actual fun <Original, Saveable : Any> Saver(
override fun restore(value: Saveable): Original? = restore(value)
}

actual fun <T> autoSaver(): Saver<T, Any> =
public actual fun <T> autoSaver(): Saver<T, Any> =
@Suppress("UNCHECKED_CAST")
(AutoSaver as Saver<T, Any>)

Expand All @@ -39,7 +39,7 @@ private val AutoSaver = Saver<Any?, Any>(
restore = { it }
)

actual fun <Original, Saveable> listSaver(
public actual fun <Original, Saveable> listSaver(
save: SaverScope.(value: Original) -> List<Saveable>,
restore: (list: List<Saveable>) -> Original?
): Saver<Original, Any> =
Expand All @@ -57,7 +57,7 @@ actual fun <Original, Saveable> listSaver(
restore = restore as (Any) -> Original?
)

actual fun <T> mapSaver(
public actual fun <T> mapSaver(
save: SaverScope.(value: T) -> Map<String, Any?>,
restore: (Map<String, Any?>) -> T?
): Saver<T, Any> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,23 @@ package com.chrynan.parcelable.compose
import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState

actual typealias Saver<Original, Saveable> = androidx.compose.runtime.saveable.Saver<Original, Saveable>
public actual typealias Saver<Original, Saveable> = androidx.compose.runtime.saveable.Saver<Original, Saveable>

actual typealias SaverScope = androidx.compose.runtime.saveable.SaverScope
public actual typealias SaverScope = androidx.compose.runtime.saveable.SaverScope

actual fun <Original, Saveable : Any> Saver(
public actual fun <Original, Saveable : Any> Saver(
save: SaverScope.(value: Original) -> Saveable?,
restore: (value: Saveable) -> Original?
): Saver<Original, Saveable> = androidx.compose.runtime.saveable.Saver(save = save, restore = restore)

actual fun <T> autoSaver(): Saver<T, Any> = androidx.compose.runtime.saveable.autoSaver()
public actual fun <T> autoSaver(): Saver<T, Any> = androidx.compose.runtime.saveable.autoSaver()

actual fun <Original, Saveable> listSaver(
public actual fun <Original, Saveable> listSaver(
save: SaverScope.(value: Original) -> List<Saveable>,
restore: (list: List<Saveable>) -> Original?
): Saver<Original, Any> = androidx.compose.runtime.saveable.listSaver(save = save, restore = restore)

actual fun <T> mapSaver(
public actual fun <T> mapSaver(
save: SaverScope.(value: T) -> Map<String, Any?>,
restore: (Map<String, Any?>) -> T?
): Saver<T, Any> = androidx.compose.runtime.saveable.mapSaver(save = save, restore = restore)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.remember

actual interface Saver<Original, Saveable : Any> {
public actual interface Saver<Original, Saveable : Any> {

actual fun SaverScope.save(value: Original): Saveable?
public actual fun SaverScope.save(value: Original): Saveable?

actual fun restore(value: Saveable): Original?
public actual fun restore(value: Saveable): Original?
}

actual fun interface SaverScope {
public actual fun interface SaverScope {

actual fun canBeSaved(value: Any): Boolean
public actual fun canBeSaved(value: Any): Boolean
}

actual fun <Original, Saveable : Any> Saver(
public actual fun <Original, Saveable : Any> Saver(
save: SaverScope.(value: Original) -> Saveable?,
restore: (value: Saveable) -> Original?
): Saver<Original, Saveable> = object : Saver<Original, Saveable> {
Expand All @@ -30,7 +30,7 @@ actual fun <Original, Saveable : Any> Saver(
override fun restore(value: Saveable): Original? = restore(value)
}

actual fun <T> autoSaver(): Saver<T, Any> =
public actual fun <T> autoSaver(): Saver<T, Any> =
@Suppress("UNCHECKED_CAST")
(AutoSaver as Saver<T, Any>)

Expand All @@ -39,7 +39,7 @@ private val AutoSaver = Saver<Any?, Any>(
restore = { it }
)

actual fun <Original, Saveable> listSaver(
public actual fun <Original, Saveable> listSaver(
save: SaverScope.(value: Original) -> List<Saveable>,
restore: (list: List<Saveable>) -> Original?
): Saver<Original, Any> =
Expand All @@ -57,7 +57,7 @@ actual fun <Original, Saveable> listSaver(
restore = restore as (Any) -> Original?
)

actual fun <T> mapSaver(
public actual fun <T> mapSaver(
save: SaverScope.(value: T) -> Map<String, Any?>,
restore: (Map<String, Any?>) -> T?
): Saver<T, Any> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ import androidx.compose.runtime.Composable
import androidx.compose.runtime.MutableState
import androidx.compose.runtime.remember

actual interface Saver<Original, Saveable : Any> {
public actual interface Saver<Original, Saveable : Any> {

actual fun SaverScope.save(value: Original): Saveable?
public actual fun SaverScope.save(value: Original): Saveable?

actual fun restore(value: Saveable): Original?
public actual fun restore(value: Saveable): Original?
}

actual fun interface SaverScope {
public actual fun interface SaverScope {

actual fun canBeSaved(value: Any): Boolean
public actual fun canBeSaved(value: Any): Boolean
}

actual fun <Original, Saveable : Any> Saver(
public actual fun <Original, Saveable : Any> Saver(
save: SaverScope.(value: Original) -> Saveable?,
restore: (value: Saveable) -> Original?
): Saver<Original, Saveable> = object : Saver<Original, Saveable> {
Expand All @@ -30,7 +30,7 @@ actual fun <Original, Saveable : Any> Saver(
override fun restore(value: Saveable): Original? = restore(value)
}

actual fun <T> autoSaver(): Saver<T, Any> =
public actual fun <T> autoSaver(): Saver<T, Any> =
@Suppress("UNCHECKED_CAST")
(AutoSaver as Saver<T, Any>)

Expand All @@ -39,7 +39,7 @@ private val AutoSaver = Saver<Any?, Any>(
restore = { it }
)

actual fun <Original, Saveable> listSaver(
public actual fun <Original, Saveable> listSaver(
save: SaverScope.(value: Original) -> List<Saveable>,
restore: (list: List<Saveable>) -> Original?
): Saver<Original, Any> =
Expand All @@ -57,7 +57,7 @@ actual fun <Original, Saveable> listSaver(
restore = restore as (Any) -> Original?
)

actual fun <T> mapSaver(
public actual fun <T> mapSaver(
save: SaverScope.(value: T) -> Map<String, Any?>,
restore: (Map<String, Any?>) -> T?
): Saver<T, Any> =
Expand Down

0 comments on commit 359d26f

Please sign in to comment.