State Provider
A provider of a state for a StateHolder.
Sometimes we can have a simple state object that does not rely on outside sources. In that case you can just use provideState, like so:
val stateContainer = StateContainer.create(provideState(42))Content copied to clipboard
However sometimes we need to use a more complex state object that relies on outside sources. For that we might need to inject in some dependencies and create the state object.
class MyRepo {
fun getSomeData(): Int = 42
}
class MyStateProvider @Inject constructor(repo: MyRepo): StateProvider<Int> {
override fun provide() = repo.getSomeData()
}
class MyModel @Inject constructor(stateProvider: MyStateProvider) : ViewModel() {
private val container = stateContainer(stateProvider)
}Content copied to clipboard
This provides a testable way to provide state for a StateHolder.