Other cleanup
This commit is contained in:
parent
ad8ad3d443
commit
8d533e8a20
11 changed files with 14 additions and 20 deletions
|
|
@ -12,12 +12,11 @@ import android.content.ContextWrapper
|
|||
import com.bumble.appyx.core.node.Node
|
||||
import io.element.android.libraries.di.DependencyInjectionGraphOwner
|
||||
|
||||
inline fun <reified T : Any> Node.optionalBindings() = optionalBindings(T::class.java)
|
||||
inline fun <reified T : Any> Node.bindings() = bindings(T::class.java)
|
||||
inline fun <reified T : Any> Context.bindings() = bindings(T::class.java)
|
||||
|
||||
fun <T : Any> Context.bindings(klass: Class<T>): T {
|
||||
// search dagger components in the context hierarchy
|
||||
// search the components in the dependency injection graph
|
||||
return generateSequence(this) { (it as? ContextWrapper)?.baseContext }
|
||||
.plus(applicationContext)
|
||||
.filterIsInstance<DependencyInjectionGraphOwner>()
|
||||
|
|
@ -28,16 +27,13 @@ fun <T : Any> Context.bindings(klass: Class<T>): T {
|
|||
?: error("Unable to find bindings for ${klass.name}")
|
||||
}
|
||||
|
||||
fun <T : Any> Node.optionalBindings(klass: Class<T>): T? {
|
||||
// search dagger components in node hierarchy
|
||||
fun <T : Any> Node.bindings(klass: Class<T>): T {
|
||||
// search the components in the node hierarchy
|
||||
return generateSequence(this, Node::parent)
|
||||
.filterIsInstance<DependencyInjectionGraphOwner>()
|
||||
.map { it.graph }
|
||||
.flatMap { it as? Collection<*> ?: listOf(it) }
|
||||
.filterIsInstance(klass)
|
||||
.firstOrNull()
|
||||
}
|
||||
|
||||
fun <T : Any> Node.bindings(klass: Class<T>): T {
|
||||
return optionalBindings(klass) ?: error("Unable to find bindings for ${klass.name}")
|
||||
?: error("Unable to find bindings for ${klass.name}")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -37,7 +37,7 @@ inline fun <reified N : Node> NodeFactoriesBindings.createNode(
|
|||
val nodeClass = N::class
|
||||
val nodeFactoryMap = nodeFactories()
|
||||
// Note to developers: If you got the error below, make sure to build again after
|
||||
// clearing the cache (sometimes several times) to let Dagger generate the NodeFactory.
|
||||
// clearing the cache (sometimes several times) to let codegen generate the NodeFactory.
|
||||
val nodeFactory = nodeFactoryMap[nodeClass] ?: error("Cannot find NodeFactory for ${nodeClass.java.name}.")
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import kotlin.reflect.KClass
|
|||
|
||||
/**
|
||||
* Annotation to add a factory of type [MediaItemPresenterFactory] to a
|
||||
* Dagger map multi binding keyed with a subclass of [MediaItem.Event].
|
||||
* DI map multi binding keyed with a subclass of [MediaItem.Event].
|
||||
*/
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@MapKey
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ import io.element.android.libraries.mediaviewer.impl.model.MediaItem
|
|||
import kotlin.reflect.KClass
|
||||
|
||||
/**
|
||||
* Dagger module that declares the [MediaItemPresenterFactory] map multi binding.
|
||||
* Container that declares the [MediaItemPresenterFactory] map multi binding.
|
||||
*
|
||||
* Its sole purpose is to support the case of an empty map multibinding.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ import io.element.android.libraries.mediaviewer.impl.model.MediaItem
|
|||
/**
|
||||
* A factory for a [Presenter] associated with a timeline item.
|
||||
*
|
||||
* Implementations should be annotated with [AssistedFactory] to be created by Dagger.
|
||||
* Implementations should be annotated with [dev.zacsweers.metro.AssistedFactory] to be created.
|
||||
*
|
||||
* @param C The timeline item's [MediaItem.Event] subtype.
|
||||
* @param S The [Presenter]'s state class.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue