Code quality

Code quality
This commit is contained in:
Benoit Marty 2022-12-21 15:32:53 +01:00
parent 4c88d8e3c2
commit 0644a5822f
30 changed files with 44 additions and 51 deletions

View file

@ -27,7 +27,7 @@ inline fun <reified T : Any> Context.bindings() = bindings(T::class.java)
*/
inline fun <reified T : Any> Fragment.bindings() = bindings(T::class.java)
/** Use no-arg extension function instead: [Context.bindings] */
/** Use no-arg extension function instead: [Context.bindings]. */
fun <T : Any> Context.bindings(klass: Class<T>): T {
// search dagger components in the context hierarchy
return generateSequence(this) { (it as? ContextWrapper)?.baseContext }
@ -40,7 +40,7 @@ fun <T : Any> Context.bindings(klass: Class<T>): T {
?: error("Unable to find bindings for ${klass.name}")
}
/** Use no-arg extension function instead: [Fragment.bindings] */
/** Use no-arg extension function instead: [Fragment.bindings]. */
fun <T : Any> Fragment.bindings(klass: Class<T>): T {
// search dagger components in fragment hierarchy, then fallback to activity and application
return generateSequence(this, Fragment::getParentFragment)
@ -50,4 +50,4 @@ fun <T : Any> Fragment.bindings(klass: Class<T>): T {
.filterIsInstance(klass)
.firstOrNull()
?: requireActivity().bindings(klass)
}
}

View file

@ -7,4 +7,4 @@ package io.element.android.x.core.di
interface DaggerComponentOwner {
/** This is either a component, or a list of components. */
val daggerComponent: Any
}
}

View file

@ -29,6 +29,8 @@ inline fun <reified VM : MavericksViewModel<S>, S : MavericksState> daggerMaveri
* using its AssistedInject Factory. This class should be implemented by the companion object
* of every ViewModel which uses AssistedInject via [daggerMavericksViewModelFactory].
*
* @param VM The ViewModel type
* @param S The ViewState type
* @param viewModelClass The [Class] of the ViewModel being requested for creation
*
* This class accesses the map of ViewModel class to [AssistedViewModelFactory]s from the nearest [DaggerComponentOwner] and
@ -57,4 +59,4 @@ class DaggerMavericksViewModelFactory<VM : MavericksViewModel<S>, S : MavericksS
interface DaggerMavericksBindings {
fun viewModelFactories(): Map<Class<out MavericksViewModel<*>>, AssistedViewModelFactory<*, *>>
}
}