mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2026-04-23 01:42:28 +00:00
Compare commits
5 Commits
v0.24.8
...
c216dba69d
| Author | SHA1 | Date | |
|---|---|---|---|
| c216dba69d | |||
| d4148d52e3 | |||
| feb52ecbd1 | |||
| 706a787163 | |||
| f00cb81db1 |
@@ -1,5 +1,7 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.24.9
|
||||||
|
|
||||||
## 0.24.8
|
## 0.24.8
|
||||||
|
|
||||||
* `Versions`:
|
* `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
|
package dev.inmo.micro_utils.coroutines
|
||||||
|
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
|
import kotlinx.coroutines.test.runTest
|
||||||
import kotlin.test.Test
|
import kotlin.test.Test
|
||||||
|
|
||||||
class HandleSafelyCoroutineContextTest {
|
class HandleSafelyCoroutineContextTest {
|
||||||
@Test
|
@Test
|
||||||
fun testHandleSafelyCoroutineContext() {
|
fun testHandleSafelyCoroutineContext() = runTest {
|
||||||
val scope = CoroutineScope(Dispatchers.Default)
|
val scope = this
|
||||||
var contextHandlerHappen = false
|
var contextHandlerHappen = false
|
||||||
var localHandlerHappen = false
|
var localHandlerHappen = false
|
||||||
var defaultHandlerHappen = false
|
|
||||||
defaultSafelyExceptionHandler = {
|
|
||||||
defaultHandlerHappen = true
|
|
||||||
throw it
|
|
||||||
}
|
|
||||||
val contextHandler: ExceptionHandler<Unit> = {
|
|
||||||
contextHandlerHappen = true
|
|
||||||
}
|
|
||||||
val checkJob = scope.launch {
|
val checkJob = scope.launch {
|
||||||
safelyWithContextExceptionHandler(contextHandler) {
|
runCatchingLogging ({
|
||||||
safely(
|
contextHandlerHappen = true
|
||||||
|
}) {
|
||||||
|
runCatchingLogging (
|
||||||
{
|
{
|
||||||
localHandlerHappen = true
|
localHandlerHappen = true
|
||||||
}
|
}
|
||||||
@@ -29,10 +24,8 @@ class HandleSafelyCoroutineContextTest {
|
|||||||
println(coroutineContext)
|
println(coroutineContext)
|
||||||
error("That must happen too:)")
|
error("That must happen too:)")
|
||||||
}
|
}
|
||||||
}
|
}.join()
|
||||||
launchSynchronously { checkJob.join() }
|
|
||||||
assert(contextHandlerHappen)
|
assert(contextHandlerHappen)
|
||||||
assert(localHandlerHappen)
|
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.SortedBinaryTreeNode
|
||||||
import dev.inmo.micro_utils.coroutines.collections.addSubNode
|
import dev.inmo.micro_utils.coroutines.collections.addSubNode
|
||||||
import dev.inmo.micro_utils.coroutines.collections.findNode
|
import dev.inmo.micro_utils.coroutines.collections.findNode
|
||||||
@@ -10,8 +12,6 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
import kotlin.time.Duration.Companion.seconds
|
import kotlin.time.Duration.Companion.seconds
|
||||||
|
|
||||||
expect val AllowDeepInsertOnWorksTest: Boolean
|
|
||||||
|
|
||||||
class SortedBinaryTreeNodeTests {
|
class SortedBinaryTreeNodeTests {
|
||||||
@Test
|
@Test
|
||||||
fun insertOnZeroLevelWorks() = runTest {
|
fun insertOnZeroLevelWorks() = runTest {
|
||||||
@@ -46,7 +46,6 @@ class SortedBinaryTreeNodeTests {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
fun deepReInsertOnWorks() = runTest(timeout = 300.seconds) {
|
fun deepReInsertOnWorks() = runTest(timeout = 300.seconds) {
|
||||||
if (AllowDeepInsertOnWorksTest == false) return@runTest
|
|
||||||
val zeroNode = SortedBinaryTreeNode(0)
|
val zeroNode = SortedBinaryTreeNode(0)
|
||||||
val rangeRadius = 500
|
val rangeRadius = 500
|
||||||
val nodes = mutableMapOf<Int, SortedBinaryTreeNode<Int>>()
|
val nodes = mutableMapOf<Int, SortedBinaryTreeNode<Int>>()
|
||||||
@@ -124,7 +123,6 @@ class SortedBinaryTreeNodeTests {
|
|||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
fun deepInsertOnWorks() = runTest(timeout = 240.seconds) {
|
fun deepInsertOnWorks() = runTest(timeout = 240.seconds) {
|
||||||
if (AllowDeepInsertOnWorksTest == false) return@runTest
|
|
||||||
val zeroNode = SortedBinaryTreeNode(0)
|
val zeroNode = SortedBinaryTreeNode(0)
|
||||||
val rangeRadius = 500
|
val rangeRadius = 500
|
||||||
val nodes = mutableMapOf<Int, SortedBinaryTreeNode<Int>>()
|
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
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.24.8
|
version=0.24.9
|
||||||
android_code_version=288
|
android_code_version=289
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ class InfinityPagedComponentContext<T> internal constructor(
|
|||||||
size: Int
|
size: Int
|
||||||
) {
|
) {
|
||||||
internal val startPage = SimplePagination(page, size)
|
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 val dataState: MutableState<List<T>?> = mutableStateOf(null)
|
||||||
internal var lastPageLoaded = false
|
internal var lastPageLoaded = false
|
||||||
|
|
||||||
@@ -27,11 +27,11 @@ class InfinityPagedComponentContext<T> internal constructor(
|
|||||||
*/
|
*/
|
||||||
fun loadNext() {
|
fun loadNext() {
|
||||||
if (lastPageLoaded) return
|
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 {
|
iterationState.value = iterationState.value.let {
|
||||||
if ((it.second as? PaginationResult<*>) ?.isLastPage == true) return
|
if ((it as? PaginationResult<*>) ?.isLastPage == true) return
|
||||||
(it.first + 1) to (it.second ?: startPage).nextPage()
|
(it ?: startPage).nextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,7 +42,7 @@ class InfinityPagedComponentContext<T> internal constructor(
|
|||||||
dataState.value = null
|
dataState.value = null
|
||||||
lastPageLoaded = false
|
lastPageLoaded = false
|
||||||
iterationState.value = iterationState.value.let {
|
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) }
|
val context = remember { InfinityPagedComponentContext<T>(page, size) }
|
||||||
|
|
||||||
LaunchedEffect(context.iterationState.value.first) {
|
LaunchedEffect(context.iterationState.value ?.page) {
|
||||||
val paginationResult = loader(context, context.iterationState.value.second ?: context.startPage)
|
val paginationResult = loader(context, context.iterationState.value ?: context.startPage)
|
||||||
if (paginationResult.isLastPage) {
|
if (paginationResult.isLastPage) {
|
||||||
context.lastPageLoaded = true
|
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
|
context.dataState.value = (context.dataState.value ?: emptyList()) + paginationResult.results
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ class PagedComponentContext<T> internal constructor(
|
|||||||
initialPage: Int,
|
initialPage: Int,
|
||||||
size: 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
|
internal var dataOptional: PaginationResult<T>? = preset
|
||||||
private set
|
private set
|
||||||
@@ -35,7 +35,7 @@ class PagedComponentContext<T> internal constructor(
|
|||||||
fun loadNext() {
|
fun loadNext() {
|
||||||
iterationState.value = iterationState.value.let {
|
iterationState.value = iterationState.value.let {
|
||||||
if (dataState.value ?.isLastPage == true) return
|
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() {
|
fun loadPrevious() {
|
||||||
iterationState.value = iterationState.value.let {
|
iterationState.value = iterationState.value.let {
|
||||||
if (it.second.isFirstPage) return
|
if (it.isFirstPage) return
|
||||||
(it.first - 1) to SimplePagination(
|
SimplePagination(
|
||||||
it.second.page - 1,
|
it.page - 1,
|
||||||
it.second.size
|
it.size
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -57,7 +57,7 @@ class PagedComponentContext<T> internal constructor(
|
|||||||
*/
|
*/
|
||||||
fun reload() {
|
fun reload() {
|
||||||
iterationState.value = iterationState.value.let {
|
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) }
|
val context = remember { PagedComponentContext(preload, initialPage, size) }
|
||||||
|
|
||||||
LaunchedEffect(context.iterationState.value) {
|
LaunchedEffect(context.iterationState.value.page, context.iterationState.value.hashCode()) {
|
||||||
context.dataState.value = loader(context, context.iterationState.value.second)
|
context.dataState.value = loader(context, context.iterationState.value)
|
||||||
}
|
}
|
||||||
|
|
||||||
context.dataState.value ?.let {
|
context.dataState.value ?.let {
|
||||||
|
|||||||
@@ -30,8 +30,8 @@ class InfinityPagedComponentTests {
|
|||||||
}
|
}
|
||||||
) {
|
) {
|
||||||
if (it == null) {
|
if (it == null) {
|
||||||
if (this.iterationState.value.second != null) {
|
if (this.iterationState.value != null) {
|
||||||
assertEquals(0, (this.iterationState.value.second as? SimplePagination) ?.page)
|
assertEquals(0, (this.iterationState.value as? SimplePagination) ?.page)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
assertEquals(expectedList, it)
|
assertEquals(expectedList, it)
|
||||||
|
|||||||
Reference in New Issue
Block a user