ganfra
2 years ago
2 changed files with 6 additions and 6 deletions
@ -1,21 +1,21 @@
@@ -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…
Reference in new issue