Use LifecycleOwner instead of explicit Node on presenterConnector
This commit is contained in:
parent
eeebb99292
commit
a37cf3adde
2 changed files with 6 additions and 6 deletions
|
|
@ -31,7 +31,7 @@ class RoomListNode @AssistedInject constructor(
|
|||
fun onRoomClicked(roomId: RoomId)
|
||||
}
|
||||
|
||||
private val connector = presenterConnector(presenter)
|
||||
private val connector by presenterConnector(presenter)
|
||||
|
||||
private fun updateFilter(filter: String) {
|
||||
connector.emitEvent(RoomListEvents.UpdateFilter(filter))
|
||||
|
|
|
|||
|
|
@ -1,21 +1,21 @@
|
|||
package io.element.android.x.architecture
|
||||
|
||||
import androidx.lifecycle.LifecycleOwner
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import app.cash.molecule.AndroidUiDispatcher
|
||||
import app.cash.molecule.RecompositionClock
|
||||
import app.cash.molecule.launchMolecule
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.flow.MutableSharedFlow
|
||||
import kotlinx.coroutines.flow.StateFlow
|
||||
|
||||
inline fun <reified State, reified Event> Node.presenterConnector(presenter: Presenter<State, Event>): NodePresenterConnector<State, Event> {
|
||||
return NodePresenterConnector(node = this, presenter = presenter)
|
||||
inline fun <reified State, reified Event> LifecycleOwner.presenterConnector(presenter: Presenter<State, Event>): Lazy<LifecyclePresenterConnector<State, Event>> = lazy {
|
||||
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)
|
||||
|
||||
val stateFlow: StateFlow<State> = moleculeScope.launchMolecule(RecompositionClock.ContextClock) {
|
||||
Loading…
Add table
Add a link
Reference in a new issue