Nikola Milovic
08/13/2021, 12:12 PMprivate inner class ExecutorImpl : ReaktiveExecutor<Intent, Unit, State, Result, Label>() {
override fun executeAction(action: Unit, getState: () -> State) {
dispatch(Result.Loading())
val user = firebaseAuth.currentUser
if (user != null) {
publish(Label.LoggedIn)
}
}
I am binding to the store.label output in the init block of the componentArkadii Ivanov
08/13/2021, 12:21 PMBootstrapper
emits the Unit
action synchronously, then by default it will be processed during Store
instantiation. So your binding code did not run yet. You should either postpone the emission in your Bootstrapper, or use manual Store
initialization (available from version 3.x). Please check out the documentation section "Initializing a Store".
BA assumeNikola Milovic
08/13/2021, 2:37 PMArkadii Ivanov
08/13/2021, 3:11 PMUnit
from the Bootstrapper
. E.g.:
private class BootstrapperImpl : ReaktiveBootstrapper<Unit>() {
override fun invoke() {
singleOf(Unit).observeOn(mainScheduler).subscribeScoped(onSuccess = ::dispatch)
}
}
This will ensure that all bindings and subscriptions are performed before the emission.
Another way is to initialise the Store
manually:
class MyStoreFactory(
private val storeFactory: StoreFactory
) {
fun create(): MyStore =
object : MyStore, Store<MyStore.Intent, MyStore.State, MyStore.Label> by storeFactory.create(
name = "MyStore",
isAutoInit = false, // Disable automatic initialisation
// The rest of the code
) {}
}
class Some(storeFactory: StoreFactory) {
private val store = MyStoreFactory(storeFactory).create()
init {
// Setup bindings and subscriptions
store.init() // Initialise the store
}
}
Arkadii Ivanov
08/13/2021, 3:12 PMNikola Milovic
08/13/2021, 3:26 PM