<@UHAJKUSTU> I’m curious if you’ve ever considered...
# mvikotlin
s
@Arkadii Ivanov I’m curious if you’ve ever considered adding an analog to redux’s middleware? I have a few use-cases where it would be convenient to compare old state to new state and then do something outside the store (or fire a
label
).
Right now I can hack this functionality into a
ViewRenderer
, but that feels wrong.
I guess the other option is to do it outside the framework by listening to
store.states
but it would be nice to be able to fire
label
from this code.
a
You can try wrapping your store with another one, that would compare both states and emit labels. You can write a custom
StoreFactory
that wraps another
StoreFactory
and does the trick. E.g.
LoggingStoreFactory
work this way, it adds logging to every store being created.
For your specific case, perhaps you can just wrap the store, no need to also wrap StoreFactory.
s
hmm, that makes sense. I’ll take a stab at it.
a
However, I find it easier to just observe state changes and perform whatever actions required, instead of sending a Label. By receiving the state change, you can assume you received the Label.
Or maybe just emit the Label directly from the store, when needed.