mirror of
https://github.com/InsanusMokrassar/MicroUtils.git
synced 2024-11-18 22:33:49 +00:00
commit
6279a2c40a
10
CHANGELOG.md
10
CHANGELOG.md
@ -1,5 +1,15 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
|
|
||||||
|
## 0.9.16
|
||||||
|
|
||||||
|
* `Common`:
|
||||||
|
* New extension `Node#onRemoved`
|
||||||
|
* `Compose`:
|
||||||
|
* New extension `Composition#linkWithRoot` for removing of composition with root element
|
||||||
|
* `Coroutines`:
|
||||||
|
* `Compose`:
|
||||||
|
* New function `renderComposableAndLinkToContextAndRoot` with linking of composition to root element
|
||||||
|
|
||||||
## 0.9.15
|
## 0.9.15
|
||||||
|
|
||||||
* `FSM`:
|
* `FSM`:
|
||||||
|
@ -0,0 +1,9 @@
|
|||||||
|
package dev.inmo.micro_utils.common.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.Composition
|
||||||
|
import dev.inmo.micro_utils.common.onRemoved
|
||||||
|
import org.w3c.dom.Element
|
||||||
|
|
||||||
|
fun Composition.linkWithElement(element: Element) {
|
||||||
|
element.onRemoved { dispose() }
|
||||||
|
}
|
@ -0,0 +1,13 @@
|
|||||||
|
package dev.inmo.micro_utils.common.compose
|
||||||
|
|
||||||
|
import androidx.compose.runtime.*
|
||||||
|
import org.jetbrains.compose.web.dom.DOMScope
|
||||||
|
import org.w3c.dom.Element
|
||||||
|
|
||||||
|
fun <TElement : Element> renderComposableAndLinkToRoot(
|
||||||
|
root: TElement,
|
||||||
|
monotonicFrameClock: MonotonicFrameClock = DefaultMonotonicFrameClock,
|
||||||
|
content: @Composable DOMScope<TElement>.() -> Unit
|
||||||
|
): Composition = org.jetbrains.compose.web.renderComposable(root, monotonicFrameClock, content).apply {
|
||||||
|
linkWithElement(root)
|
||||||
|
}
|
@ -0,0 +1,21 @@
|
|||||||
|
package dev.inmo.micro_utils.common
|
||||||
|
|
||||||
|
import kotlinx.browser.document
|
||||||
|
import org.w3c.dom.*
|
||||||
|
|
||||||
|
fun Node.onRemoved(block: () -> Unit) {
|
||||||
|
lateinit var observer: MutationObserver
|
||||||
|
|
||||||
|
observer = MutationObserver { _, _ ->
|
||||||
|
fun checkIfRemoved(node: Node): Boolean {
|
||||||
|
return node.parentNode != document && (node.parentNode ?.let { checkIfRemoved(it) } ?: true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (checkIfRemoved(this)) {
|
||||||
|
observer.disconnect()
|
||||||
|
block()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
observer.observe(document, MutationObserverInit(childList = true, subtree = true))
|
||||||
|
}
|
@ -13,6 +13,7 @@ kotlin {
|
|||||||
dependencies {
|
dependencies {
|
||||||
api libs.kt.coroutines
|
api libs.kt.coroutines
|
||||||
api project(":micro_utils.coroutines")
|
api project(":micro_utils.coroutines")
|
||||||
|
api project(":micro_utils.common.compose")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package dev.inmo.micro_utils.coroutines.compose
|
package dev.inmo.micro_utils.coroutines.compose
|
||||||
|
|
||||||
import androidx.compose.runtime.*
|
import androidx.compose.runtime.*
|
||||||
|
import dev.inmo.micro_utils.common.compose.linkWithElement
|
||||||
import kotlinx.coroutines.*
|
import kotlinx.coroutines.*
|
||||||
import org.jetbrains.compose.web.dom.DOMScope
|
import org.jetbrains.compose.web.dom.DOMScope
|
||||||
import org.w3c.dom.Element
|
import org.w3c.dom.Element
|
||||||
@ -14,3 +15,12 @@ suspend fun <TElement : Element> renderComposableAndLinkToContext(
|
|||||||
currentCoroutineContext()
|
currentCoroutineContext()
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun <TElement : Element> renderComposableAndLinkToContextAndRoot(
|
||||||
|
root: TElement,
|
||||||
|
monotonicFrameClock: MonotonicFrameClock = DefaultMonotonicFrameClock,
|
||||||
|
content: @Composable DOMScope<TElement>.() -> Unit
|
||||||
|
): Composition = org.jetbrains.compose.web.renderComposable(root, monotonicFrameClock, content).apply {
|
||||||
|
linkWithContext(currentCoroutineContext())
|
||||||
|
linkWithElement(root)
|
||||||
|
}
|
||||||
|
@ -14,5 +14,5 @@ crypto_js_version=4.1.1
|
|||||||
# Project data
|
# Project data
|
||||||
|
|
||||||
group=dev.inmo
|
group=dev.inmo
|
||||||
version=0.9.15
|
version=0.9.16
|
||||||
android_code_version=105
|
android_code_version=106
|
||||||
|
Loading…
Reference in New Issue
Block a user