mirror of
https://github.com/uber/RIBs.git
synced 2026-06-16 12:54:31 +00:00
Adding WeakHashMap to hold scopes for ScopeProviders
This commit is contained in:
+1
-2
@@ -35,10 +35,9 @@ class MainInteractor(
|
||||
|
||||
override fun didBecomeActive(savedInstanceState: Bundle?) {
|
||||
super.didBecomeActive(savedInstanceState)
|
||||
CoroutineScope(RibDispatchers.Main).launch { }
|
||||
|
||||
router.view.setContent { MainView(childContent = childContent) }
|
||||
authStream.observe()
|
||||
authStream.observe()
|
||||
.onEach {
|
||||
if (it.isLoggedIn) {
|
||||
router.detachLoggedOut()
|
||||
|
||||
-1
@@ -35,7 +35,6 @@ class LoggedOutInteractor(
|
||||
private val eventStream: EventStream<LoggedOutEvent>,
|
||||
private val stateStream: StateStream<LoggedOutViewModel>
|
||||
) : BasicInteractor<ComposePresenter, LoggedOutRouter>(presenter) {
|
||||
|
||||
override fun didBecomeActive(savedInstanceState: Bundle?) {
|
||||
super.didBecomeActive(savedInstanceState)
|
||||
eventStream.observe()
|
||||
|
||||
+22
-12
@@ -3,21 +3,31 @@ package com.uber.rib.core
|
||||
import com.uber.autodispose.ScopeProvider
|
||||
import com.uber.autodispose.coroutinesinterop.asCoroutineScope
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.SupervisorJob
|
||||
import java.util.*
|
||||
import kotlin.reflect.KProperty
|
||||
|
||||
//TODO add weak hashmap to hold values of getters.
|
||||
val ScopeProvider.defaultScope by LazyWithReceiver<ScopeProvider, CoroutineScope> {
|
||||
asCoroutineScope(SupervisorJob() + RibDispatchers.Main)
|
||||
}
|
||||
|
||||
val ScopeProvider.defaultScope: CoroutineScope
|
||||
get() = asCoroutineScope(SupervisorJob() + RibDispatchers.Default)
|
||||
val ScopeProvider.mainScope by LazyWithReceiver<ScopeProvider, CoroutineScope> {
|
||||
asCoroutineScope(SupervisorJob() + RibDispatchers.Main)
|
||||
}
|
||||
|
||||
val ScopeProvider.mainScope: CoroutineScope
|
||||
get() = asCoroutineScope(SupervisorJob() + RibDispatchers.Main)
|
||||
|
||||
val ScopeProvider.ioScope: CoroutineScope
|
||||
get() = asCoroutineScope(SupervisorJob() + RibDispatchers.IO)
|
||||
|
||||
val ScopeProvider.unconfinedScope: CoroutineScope
|
||||
get() = asCoroutineScope(SupervisorJob() + RibDispatchers.Unconfined)
|
||||
val ScopeProvider.ioScope by LazyWithReceiver<ScopeProvider, CoroutineScope> {
|
||||
asCoroutineScope(SupervisorJob() + RibDispatchers.IO)
|
||||
}
|
||||
val ScopeProvider.unconfinedScope by LazyWithReceiver<ScopeProvider, CoroutineScope> {
|
||||
asCoroutineScope(SupervisorJob() + RibDispatchers.Unconfined)
|
||||
}
|
||||
|
||||
private class LazyWithReceiver<This,Return>(val initializer:This.()->Return)
|
||||
{
|
||||
private val values = WeakHashMap<This,Return>()
|
||||
|
||||
operator fun getValue(thisRef:This, property: KProperty<*>):Return = synchronized(values)
|
||||
{
|
||||
return values.getOrPut(thisRef) { thisRef.initializer() }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user