Last active
January 12, 2023 18:19
-
-
Save gpeal/b463928f601c47ad9df8b3483bf2ffc8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inline fun <reified T : Any> Fragment.fragmentComponent(crossinline factory: (CoroutineScope, Application) -> T) = lazy { | |
ViewModelProvider(this)[DaggerComponentHolderViewModel::class.java].get<T>(factory) | |
} | |
class DaggerComponentHolderViewModel(app: Application) : AndroidViewModel(app) { | |
val map = ConcurrentHashMap<Class<*>, Any>() | |
inline fun <reified T> get(factory: (CoroutineScope, Application) -> T): T { | |
return map.getOrPut(T::class.java) { factory(viewModelScope, getApplication()) } as T | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GuidedWorkoutFragment : TonalFragment(R.layout.guided_workout_fragment) { | |
override val daggerComponent: GuidedWorkoutMergeComponent by fragmentComponent { scope, app -> | |
app.bindings<GuidedWorkoutMergeComponent.Parent>().guidedWorkoutComponentBuilder() | |
.coroutineScope(WorkoutCoroutineScope(scope)) | |
.args(arg) | |
.build() | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment