StateProvider

fun interface StateProvider<State>

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))

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)
}

This provides a testable way to provide state for a StateHolder.

Functions

Link copied to clipboard
abstract fun provide(): State