Some cleanup:
- Remove unnecessary `GlobalScope`. - Rename `Component` to `Graph`, `DaggerComponentOwner` to `DependencyInjectionGraphOwner`. - Rename component builders to factories, where necessary.
This commit is contained in:
parent
6a05e1b911
commit
08bbe3fdaa
20 changed files with 99 additions and 127 deletions
|
|
@ -10,7 +10,7 @@ package io.element.android.libraries.architecture
|
|||
import android.content.Context
|
||||
import android.content.ContextWrapper
|
||||
import com.bumble.appyx.core.node.Node
|
||||
import io.element.android.libraries.di.DaggerComponentOwner
|
||||
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)
|
||||
|
|
@ -20,9 +20,9 @@ fun <T : Any> Context.bindings(klass: Class<T>): T {
|
|||
// search dagger components in the context hierarchy
|
||||
return generateSequence(this) { (it as? ContextWrapper)?.baseContext }
|
||||
.plus(applicationContext)
|
||||
.filterIsInstance<DaggerComponentOwner>()
|
||||
.map { it.daggerComponent }
|
||||
.flatMap { if (it is Collection<*>) it else listOf(it) }
|
||||
.filterIsInstance<DependencyInjectionGraphOwner>()
|
||||
.map { it.graph }
|
||||
.flatMap { it as? Collection<*> ?: listOf(it) }
|
||||
.filterIsInstance(klass)
|
||||
.firstOrNull()
|
||||
?: error("Unable to find bindings for ${klass.name}")
|
||||
|
|
@ -31,9 +31,9 @@ fun <T : Any> Context.bindings(klass: Class<T>): T {
|
|||
fun <T : Any> Node.optionalBindings(klass: Class<T>): T? {
|
||||
// search dagger components in node hierarchy
|
||||
return generateSequence(this, Node::parent)
|
||||
.filterIsInstance<DaggerComponentOwner>()
|
||||
.map { it.daggerComponent }
|
||||
.flatMap { if (it is Collection<*>) it else listOf(it) }
|
||||
.filterIsInstance<DependencyInjectionGraphOwner>()
|
||||
.map { it.graph }
|
||||
.flatMap { it as? Collection<*> ?: listOf(it) }
|
||||
.filterIsInstance(klass)
|
||||
.firstOrNull()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,10 +8,10 @@
|
|||
package io.element.android.libraries.di
|
||||
|
||||
/**
|
||||
* A [DaggerComponentOwner] is anything that "owns" a Dagger Component.
|
||||
* A [DependencyInjectionGraphOwner] is anything that "owns" a DI Graph.
|
||||
*
|
||||
*/
|
||||
interface DaggerComponentOwner {
|
||||
/** This is either a component, or a list of components. */
|
||||
val daggerComponent: Any
|
||||
interface DependencyInjectionGraphOwner {
|
||||
/** This is either a graph, or a list of graphs. */
|
||||
val graph: Any
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue