mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-04-18 23:42:31 +00:00
Compare commits
5 Commits
v0.24.8
...
c216dba69d
| Author | SHA1 | Date | |
|---|---|---|---|
| c216dba69d | |||
| d4148d52e3 | |||
| feb52ecbd1 | |||
| 706a787163 | |||
| f00cb81db1 |
@@ -1,5 +1,7 @@
|
||||
# Changelog
|
||||
|
||||
## 0.24.9
|
||||
|
||||
## 0.24.8
|
||||
|
||||
* `Versions`:
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
actual val AllowDeepInsertOnWorksTest: Boolean
|
||||
get() = true
|
||||
@@ -1,2 +0,0 @@
|
||||
actual val AllowDeepInsertOnWorksTest: Boolean
|
||||
get() = false
|
||||
@@ -1,2 +0,0 @@
|
||||
actual val AllowDeepInsertOnWorksTest: Boolean
|
||||
get() = true
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
@@ -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>>()
|
||||
@@ -1,2 +0,0 @@
|
||||
actual val AllowDeepInsertOnWorksTest: Boolean
|
||||
get() = true
|
||||
@@ -1,2 +0,0 @@
|
||||
actual val AllowDeepInsertOnWorksTest: Boolean
|
||||
get() = true
|
||||
@@ -1,2 +0,0 @@
|
||||
actual val AllowDeepInsertOnWorksTest: Boolean
|
||||
get() = true
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user