From d8f01f21a000e0528ab874717f151603300893b0 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Jun 2022 16:09:35 +0600 Subject: [PATCH 1/6] start 0.11.4 --- CHANGELOG.md | 2 ++ gradle.properties | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c3f89fb99d..8efa8d77640 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +## 0.11.4 + ## 0.11.3 * `Ktor`: diff --git a/gradle.properties b/gradle.properties index 8ff6592186e..27e35f6180e 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,5 +14,5 @@ crypto_js_version=4.1.1 # Project data group=dev.inmo -version=0.11.3 -android_code_version=127 +version=0.11.4 +android_code_version=128 From 86e74c0a6fc3abbbfb826f006e481d9be2d0195d Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Jun 2022 16:09:52 +0600 Subject: [PATCH 2/6] add extension toMutableListState --- CHANGELOG.md | 2 ++ .../coroutines/compose/FlowToListState.kt | 21 +++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToListState.kt diff --git a/CHANGELOG.md b/CHANGELOG.md index 8efa8d77640..a0166baf150 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.11.4 +* Add extension `StateFlow#toMutableListState` + ## 0.11.3 * `Ktor`: diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToListState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToListState.kt new file mode 100644 index 00000000000..1635b6b0ea4 --- /dev/null +++ b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToListState.kt @@ -0,0 +1,21 @@ +package dev.inmo.micro_utils.coroutines.compose + +import androidx.compose.runtime.* +import androidx.compose.runtime.snapshots.SnapshotStateList +import dev.inmo.micro_utils.common.applyDiff +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow + +@Suppress("NOTHING_TO_INLINE") +inline fun StateFlow>.toMutableListState( + scope: CoroutineScope +): SnapshotStateList { + val state = mutableStateListOf(*value.toTypedArray()) + subscribeSafelyWithoutExceptions(scope) { + state.applyDiff(it) + } + return state +} + From 91a5af6a9ad09b68ecab79cbd5e827c19340a44b Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Jun 2022 16:10:58 +0600 Subject: [PATCH 3/6] fix of changelog --- CHANGELOG.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a0166baf150..5dffd0b9740 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,9 @@ ## 0.11.4 -* Add extension `StateFlow#toMutableListState` +* `Coroutines`: + * `Compose`: + * Add extension `StateFlow#toMutableListState` ## 0.11.3 From c6551076814fc05ebf42be3e526b162ee279babf Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Jun 2022 16:52:19 +0600 Subject: [PATCH 4/6] renames in compose states creation --- CHANGELOG.md | 3 +- ...{FlowToListState.kt => FlowAsListState.kt} | 8 +++-- .../coroutines/compose/FlowAsState.kt | 35 +++++++++++++++++++ .../{FlowToState.kt => FlowToMutableState.kt} | 0 4 files changed, 43 insertions(+), 3 deletions(-) rename coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/{FlowToListState.kt => FlowAsListState.kt} (71%) create mode 100644 coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt rename coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/{FlowToState.kt => FlowToMutableState.kt} (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5dffd0b9740..3b41260eb6a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,8 @@ * `Coroutines`: * `Compose`: - * Add extension `StateFlow#toMutableListState` + * Add extension `StateFlow#asMutableComposeListState` and `StateFlow#asComposeList` + * Add extension `StateFlow#asMutableComposeState`/`StateFlow#asComposeState` ## 0.11.3 diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToListState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt similarity index 71% rename from coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToListState.kt rename to coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt index 1635b6b0ea4..6004f9d918f 100644 --- a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToListState.kt +++ b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt @@ -5,11 +5,10 @@ import androidx.compose.runtime.snapshots.SnapshotStateList import dev.inmo.micro_utils.common.applyDiff import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import kotlinx.coroutines.CoroutineScope -import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow @Suppress("NOTHING_TO_INLINE") -inline fun StateFlow>.toMutableListState( +inline fun StateFlow>.asMutableComposeListState( scope: CoroutineScope ): SnapshotStateList { val state = mutableStateListOf(*value.toTypedArray()) @@ -19,3 +18,8 @@ inline fun StateFlow>.toMutableListState( return state } +@Suppress("NOTHING_TO_INLINE") +inline fun StateFlow>.asComposeList( + scope: CoroutineScope +): List = asMutableComposeListState(scope) + diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt new file mode 100644 index 00000000000..334c5dcb6ea --- /dev/null +++ b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsState.kt @@ -0,0 +1,35 @@ +package dev.inmo.micro_utils.coroutines.compose + +import androidx.compose.runtime.* +import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions +import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow +import kotlinx.coroutines.flow.StateFlow + +fun Flow.asMutableComposeState( + initial: T, + scope: CoroutineScope +): MutableState { + val state = mutableStateOf(initial) + subscribeSafelyWithoutExceptions(scope) { state.value = it } + return state +} + +@Suppress("NOTHING_TO_INLINE") +inline fun StateFlow.asMutableComposeState( + scope: CoroutineScope +): MutableState = asMutableComposeState(value, scope) + +fun Flow.asComposeState( + initial: T, + scope: CoroutineScope +): State { + val state = asMutableComposeState(initial, scope) + return derivedStateOf { state.value } +} + +@Suppress("NOTHING_TO_INLINE") +inline fun StateFlow.asComposeState( + scope: CoroutineScope +): State = asComposeState(value, scope) + diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToMutableState.kt similarity index 100% rename from coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToState.kt rename to coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowToMutableState.kt From 9cf01ab54fd9d91bebee8455b07e07de7970ee21 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Jun 2022 16:56:51 +0600 Subject: [PATCH 5/6] improve compose list state creation --- .../inmo/micro_utils/coroutines/compose/FlowAsListState.kt | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt index 6004f9d918f..3ce3e860eac 100644 --- a/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt +++ b/coroutines/compose/src/commonMain/kotlin/dev/inmo/micro_utils/coroutines/compose/FlowAsListState.kt @@ -5,13 +5,14 @@ import androidx.compose.runtime.snapshots.SnapshotStateList import dev.inmo.micro_utils.common.applyDiff import dev.inmo.micro_utils.coroutines.subscribeSafelyWithoutExceptions import kotlinx.coroutines.CoroutineScope +import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.StateFlow @Suppress("NOTHING_TO_INLINE") -inline fun StateFlow>.asMutableComposeListState( +inline fun Flow>.asMutableComposeListState( scope: CoroutineScope ): SnapshotStateList { - val state = mutableStateListOf(*value.toTypedArray()) + val state = mutableStateListOf() subscribeSafelyWithoutExceptions(scope) { state.applyDiff(it) } @@ -19,7 +20,7 @@ inline fun StateFlow>.asMutableComposeListState( } @Suppress("NOTHING_TO_INLINE") -inline fun StateFlow>.asComposeList( +inline fun Flow>.asComposeList( scope: CoroutineScope ): List = asMutableComposeListState(scope) From 121e513fdd9d2da3ad890463f985441cf4512568 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 22 Jun 2022 22:36:06 +0600 Subject: [PATCH 6/6] fixes in tempUpload of js part --- .../ktor/client/ActualTemporalUpload.kt | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/ktor/client/src/jsMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt b/ktor/client/src/jsMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt index 0824c19c516..33c8a4910f5 100644 --- a/ktor/client/src/jsMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt +++ b/ktor/client/src/jsMain/kotlin/dev/inmo/micro_utils/ktor/client/ActualTemporalUpload.kt @@ -4,7 +4,10 @@ import dev.inmo.micro_utils.common.MPPFile import dev.inmo.micro_utils.ktor.common.TemporalFileId import io.ktor.client.HttpClient import kotlinx.coroutines.* +import org.w3c.dom.mediasource.ENDED +import org.w3c.dom.mediasource.ReadyState import org.w3c.xhr.* +import org.w3c.xhr.XMLHttpRequest.Companion.DONE suspend fun tempUpload( fullTempUploadDraftPath: String, @@ -12,7 +15,7 @@ suspend fun tempUpload( onUpload: (Long, Long) -> Unit ): TemporalFileId { val formData = FormData() - val answer = CompletableDeferred() + val answer = CompletableDeferred(currentCoroutineContext().job) formData.append( "data", @@ -37,17 +40,15 @@ suspend fun tempUpload( request.open("POST", fullTempUploadDraftPath, true) request.send(formData) - val handle = currentCoroutineContext().job.invokeOnCompletion { + answer.invokeOnCompletion { runCatching { - request.abort() + if (request.readyState != DONE) { + request.abort() + } } } - return runCatching { - answer.await() - }.also { - handle.dispose() - }.getOrThrow() + return answer.await() }