mirror of
https://github.com/Novaloop-AG/element-x-android.git
synced 2026-11-02 21:32:34 +00:00
Use LifecycleOwner instead of explicit Node on presenterConnector
This commit is contained in:
+1
-1
@@ -31,7 +31,7 @@ class RoomListNode @AssistedInject constructor(
|
|||||||
fun onRoomClicked(roomId: RoomId)
|
fun onRoomClicked(roomId: RoomId)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val connector = presenterConnector(presenter)
|
private val connector by presenterConnector(presenter)
|
||||||
|
|
||||||
private fun updateFilter(filter: String) {
|
private fun updateFilter(filter: String) {
|
||||||
connector.emitEvent(RoomListEvents.UpdateFilter(filter))
|
connector.emitEvent(RoomListEvents.UpdateFilter(filter))
|
||||||
|
|||||||
+5
-5
@@ -1,21 +1,21 @@
|
|||||||
package io.element.android.x.architecture
|
package io.element.android.x.architecture
|
||||||
|
|
||||||
|
import androidx.lifecycle.LifecycleOwner
|
||||||
import androidx.lifecycle.lifecycleScope
|
import androidx.lifecycle.lifecycleScope
|
||||||
import app.cash.molecule.AndroidUiDispatcher
|
import app.cash.molecule.AndroidUiDispatcher
|
||||||
import app.cash.molecule.RecompositionClock
|
import app.cash.molecule.RecompositionClock
|
||||||
import app.cash.molecule.launchMolecule
|
import app.cash.molecule.launchMolecule
|
||||||
import com.bumble.appyx.core.node.Node
|
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||||
import kotlinx.coroutines.flow.StateFlow
|
import kotlinx.coroutines.flow.StateFlow
|
||||||
|
|
||||||
inline fun <reified State, reified Event> Node.presenterConnector(presenter: Presenter<State, Event>): NodePresenterConnector<State, Event> {
|
inline fun <reified State, reified Event> LifecycleOwner.presenterConnector(presenter: Presenter<State, Event>): Lazy<LifecyclePresenterConnector<State, Event>> = lazy {
|
||||||
return NodePresenterConnector(node = this, presenter = presenter)
|
LifecyclePresenterConnector(lifecycleOwner = this, presenter = presenter)
|
||||||
}
|
}
|
||||||
|
|
||||||
class NodePresenterConnector<State, Event>(private val node: Node, presenter: Presenter<State, Event>) {
|
class LifecyclePresenterConnector<State, Event>(lifecycleOwner: LifecycleOwner, presenter: Presenter<State, Event>) {
|
||||||
|
|
||||||
private val moleculeScope = CoroutineScope(node.lifecycleScope.coroutineContext + AndroidUiDispatcher.Main)
|
private val moleculeScope = CoroutineScope(lifecycleOwner.lifecycleScope.coroutineContext + AndroidUiDispatcher.Main)
|
||||||
private val eventFlow: MutableSharedFlow<Event> = MutableSharedFlow(extraBufferCapacity = 64)
|
private val eventFlow: MutableSharedFlow<Event> = MutableSharedFlow(extraBufferCapacity = 64)
|
||||||
|
|
||||||
val stateFlow: StateFlow<State> = moleculeScope.launchMolecule(RecompositionClock.ContextClock) {
|
val stateFlow: StateFlow<State> = moleculeScope.launchMolecule(RecompositionClock.ContextClock) {
|
||||||
Reference in New Issue
Block a user