Just stumbled unto this, but after publishing a la...
# mvikotlin
n
Just stumbled unto this, but after publishing a label in ReaktiveExecutor execute action (checking if user session is still valid) it doesn't get propagated to the store. Is this intended behavior? My code
Copy code
private 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 component
a
If the
Bootstrapper
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 assume
n
@Arkadii Ivanov Sorry, can I ask for an explanation on either of these, anything will do. I tried implementing both but feel short. Not sure how to delay the bootstrapper properly and initing I don't really understand when is the proper time to init. Sorry again for bothering you, feels awful to struggle with this😬
a
No worries, I will explain. One of the ways to solve it, is to postpone (schedule) the emission of
Unit
from the
Bootstrapper
. E.g.:
Copy code
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:
Copy code
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
    }
}
The second way seems more explicit and testable.
n
Thank you! I learned something useful today
🎉 1