Compare commits

...

5 Commits

13 changed files with 33 additions and 52 deletions

View File

@@ -1,5 +1,7 @@
# Changelog
## 0.24.9
## 0.24.8
* `Versions`:

View File

@@ -1,2 +0,0 @@
actual val AllowDeepInsertOnWorksTest: Boolean
get() = true

View File

@@ -1,2 +0,0 @@
actual val AllowDeepInsertOnWorksTest: Boolean
get() = false

View File

@@ -1,2 +0,0 @@
actual val AllowDeepInsertOnWorksTest: Boolean
get() = true

View File

@@ -1,25 +1,20 @@
package dev.inmo.micro_utils.coroutines
import kotlinx.coroutines.*
import kotlinx.coroutines.test.runTest
import kotlin.test.Test
class HandleSafelyCoroutineContextTest {
@Test
fun testHandleSafelyCoroutineContext() {
val scope = CoroutineScope(Dispatchers.Default)
fun testHandleSafelyCoroutineContext() = runTest {
val scope = this
var contextHandlerHappen = false
var localHandlerHappen = false
var defaultHandlerHappen = false
defaultSafelyExceptionHandler = {
defaultHandlerHappen = true
throw it
}
val contextHandler: ExceptionHandler<Unit> = {
contextHandlerHappen = true
}
val checkJob = scope.launch {
safelyWithContextExceptionHandler(contextHandler) {
safely(
runCatchingLogging ({
contextHandlerHappen = true
}) {
runCatchingLogging (
{
localHandlerHappen = true
}
@@ -29,10 +24,8 @@ class HandleSafelyCoroutineContextTest {
println(coroutineContext)
error("That must happen too:)")
}
}
launchSynchronously { checkJob.join() }
}.join()
assert(contextHandlerHappen)
assert(localHandlerHappen)
assert(defaultHandlerHappen)
}
}

View File

@@ -1,3 +1,5 @@
package dev.inmo.micro_utils.coroutines
import dev.inmo.micro_utils.coroutines.collections.SortedBinaryTreeNode
import dev.inmo.micro_utils.coroutines.collections.addSubNode
import dev.inmo.micro_utils.coroutines.collections.findNode
@@ -10,8 +12,6 @@ import kotlin.test.assertEquals
import kotlin.test.assertTrue
import kotlin.time.Duration.Companion.seconds
expect val AllowDeepInsertOnWorksTest: Boolean
class SortedBinaryTreeNodeTests {
@Test
fun insertOnZeroLevelWorks() = runTest {
@@ -46,7 +46,6 @@ class SortedBinaryTreeNodeTests {
}
@Test
fun deepReInsertOnWorks() = runTest(timeout = 300.seconds) {
if (AllowDeepInsertOnWorksTest == false) return@runTest
val zeroNode = SortedBinaryTreeNode(0)
val rangeRadius = 500
val nodes = mutableMapOf<Int, SortedBinaryTreeNode<Int>>()
@@ -124,7 +123,6 @@ class SortedBinaryTreeNodeTests {
}
@Test
fun deepInsertOnWorks() = runTest(timeout = 240.seconds) {
if (AllowDeepInsertOnWorksTest == false) return@runTest
val zeroNode = SortedBinaryTreeNode(0)
val rangeRadius = 500
val nodes = mutableMapOf<Int, SortedBinaryTreeNode<Int>>()

View File

@@ -1,2 +0,0 @@
actual val AllowDeepInsertOnWorksTest: Boolean
get() = true

View File

@@ -1,2 +0,0 @@
actual val AllowDeepInsertOnWorksTest: Boolean
get() = true

View File

@@ -1,2 +0,0 @@
actual val AllowDeepInsertOnWorksTest: Boolean
get() = true

View File

@@ -15,5 +15,5 @@ crypto_js_version=4.1.1
# Project data
group=dev.inmo
version=0.24.8
android_code_version=288
version=0.24.9
android_code_version=289

View File

@@ -18,7 +18,7 @@ class InfinityPagedComponentContext<T> internal constructor(
size: Int
) {
internal val startPage = SimplePagination(page, size)
internal val iterationState: MutableState<Pair<Int, Pagination?>> = mutableStateOf(0 to null)
internal val iterationState: MutableState<Pagination?> = mutableStateOf(null)
internal val dataState: MutableState<List<T>?> = mutableStateOf(null)
internal var lastPageLoaded = false
@@ -27,11 +27,11 @@ class InfinityPagedComponentContext<T> internal constructor(
*/
fun loadNext() {
if (lastPageLoaded) return
if (iterationState.value.second is SimplePagination) return // Data loading has been inited but not loaded yet
if (iterationState.value is SimplePagination) return // Data loading has been inited but not loaded yet
iterationState.value = iterationState.value.let {
if ((it.second as? PaginationResult<*>) ?.isLastPage == true) return
(it.first + 1) to (it.second ?: startPage).nextPage()
if ((it as? PaginationResult<*>) ?.isLastPage == true) return
(it ?: startPage).nextPage()
}
}
@@ -42,7 +42,7 @@ class InfinityPagedComponentContext<T> internal constructor(
dataState.value = null
lastPageLoaded = false
iterationState.value = iterationState.value.let {
(it.first + 1) to null
null
}
}
}
@@ -66,12 +66,12 @@ internal fun <T> InfinityPagedComponent(
) {
val context = remember { InfinityPagedComponentContext<T>(page, size) }
LaunchedEffect(context.iterationState.value.first) {
val paginationResult = loader(context, context.iterationState.value.second ?: context.startPage)
LaunchedEffect(context.iterationState.value ?.page) {
val paginationResult = loader(context, context.iterationState.value ?: context.startPage)
if (paginationResult.isLastPage) {
context.lastPageLoaded = true
}
context.iterationState.value = context.iterationState.value.copy(second = paginationResult)
context.iterationState.value = paginationResult
context.dataState.value = (context.dataState.value ?: emptyList()) + paginationResult.results
}

View File

@@ -23,7 +23,7 @@ class PagedComponentContext<T> internal constructor(
initialPage: Int,
size: Int
) {
internal val iterationState: MutableState<Pair<Int, Pagination>> = mutableStateOf(0 to SimplePagination(preset?.page ?: initialPage, preset?.size ?: size))
internal val iterationState: MutableState<Pagination> = mutableStateOf(SimplePagination(preset?.page ?: initialPage, preset?.size ?: size))
internal var dataOptional: PaginationResult<T>? = preset
private set
@@ -35,7 +35,7 @@ class PagedComponentContext<T> internal constructor(
fun loadNext() {
iterationState.value = iterationState.value.let {
if (dataState.value ?.isLastPage == true) return
(it.first + 1) to it.second.nextPage()
it.nextPage()
}
}
@@ -44,10 +44,10 @@ class PagedComponentContext<T> internal constructor(
*/
fun loadPrevious() {
iterationState.value = iterationState.value.let {
if (it.second.isFirstPage) return
(it.first - 1) to SimplePagination(
it.second.page - 1,
it.second.size
if (it.isFirstPage) return
SimplePagination(
it.page - 1,
it.size
)
}
}
@@ -57,7 +57,7 @@ class PagedComponentContext<T> internal constructor(
*/
fun reload() {
iterationState.value = iterationState.value.let {
it.copy(it.first + 1)
SimplePagination(it.page, it.size)
}
}
}
@@ -82,8 +82,8 @@ internal fun <T> PagedComponent(
) {
val context = remember { PagedComponentContext(preload, initialPage, size) }
LaunchedEffect(context.iterationState.value) {
context.dataState.value = loader(context, context.iterationState.value.second)
LaunchedEffect(context.iterationState.value.page, context.iterationState.value.hashCode()) {
context.dataState.value = loader(context, context.iterationState.value)
}
context.dataState.value ?.let {

View File

@@ -30,8 +30,8 @@ class InfinityPagedComponentTests {
}
) {
if (it == null) {
if (this.iterationState.value.second != null) {
assertEquals(0, (this.iterationState.value.second as? SimplePagination) ?.page)
if (this.iterationState.value != null) {
assertEquals(0, (this.iterationState.value as? SimplePagination) ?.page)
}
} else {
assertEquals(expectedList, it)