Closed rajdheepak closed 1 year ago
Context around asking this question:
Suggestions apart from above questions:
wdygt?
@pettermahlen Thanks for the answers i think 2 answers all of my questions.
A Follow up question that we had while analysing if mobius loops would fit in for us:
I don't understand the question I'm afraid - 'middleware' can mean many things, and so can 'hooks'. Could you explain what your use case is, and what you're trying to achieve?
@pettermahlen I mean the middleware from the redux one.
More specifically, Middleware in Android development, using Redux approach, is a program layer for asynchronous tasks, their managing, scheduling and subscribing. we can probably use it for API requests, logs, analytics, persistence, other time-consuming operations that you want to execute on a separate thread (to free-up the UI Thread, for example).
In Mobius, you would typically do that using EffectHandlers. Mobius is different from Redux, for example in how it separates Events from Effects, whereas Redux just uses Actions. So if the loop decides something should happen in the outside world, it will dispatch an Effect, which an EffectHandler can decide to handle asynchronously.
@pettermahlen Thanks for the answers, a few more questions we would like to clarify before starting to use mobius loops:
Why should update functions be only pure can I not switch thread and make a request and fire some event that will update the state?
When I have to make parallel requests, I dispatch a set of effects do the events come in clubbed as a result of all of them or will it be separate event actions getting fired? Or is there a better way of doing things around making parallel requests?
If I want to make sequential requests, I can do this in a single effect but its like putting in domain logic into effect handlers. So should we fire an effect which returns an event which in turn fires the effect the for the next request to be made? Or is there a better way of doing this?
@pettermahlen Thanks for the answers, we are from Gojek evaluating architectures and have kinda finalised on using mobius loop core package.
A few more questions coming your way, hope i am not nudging you too much 😉
Lets assume we want to perform heavy computations like on an dataset of huge array, since this being pure function would you still do this on update or in an effect handler? - Slightly a follow up on the first question that we already had asked, Can we do all of the update pure functions on a different thread?
We were thinking of having different loops for each component on the UI screen, have seen a few threads where @anawara suggests using event sources for communication across loops. - Any guidelines or learnings from the spotify context of this?
@pettermahlen Whats the default thread for update and effect functions? i can see here two work runners are created but don't really get what thread they would be running on by default. Does this mean both update and effect functions don't happen on the main thread by default?
` return new Builder<>(
update,
effectHandler,
null,
(Connectable<M, E>) NOOP_EVENT_SOURCE,
(MobiusLoop.Logger<M, E, F>) NOOP_LOGGER,
new Producer<WorkRunner>() {
@Nonnull
@Override
public WorkRunner get() {
return WorkRunners.from(Executors.newSingleThreadExecutor(Builder.THREAD_FACTORY));
}
},
new Producer<WorkRunner>() {
@Nonnull
@Override
public WorkRunner get() {
return WorkRunners.from(Executors.newCachedThreadPool(Builder.THREAD_FACTORY));
}
});
`
Yes, that's what it means.
The Executors class is documented here, in case you need more information about how the different methods work.
@pettermahlen
We have a use case where we need to convert an observable stream to event source.
Checking the API documentation:
In RxMobius we can convert an Observable stream to an event source using fromObservables(). Doc link: https://www.javadoc.io/doc/com.spotify.mobius/mobius-rx2/latest/com/spotify/mobius/rx2/RxEventSources.html
Did not get any luck with Mobius core . Is there any API in Mobius core?
What is the recommended approach to achieve this using mobius-core?
mobius-core does not have any dependencies on RxJava at all by design - if you need rx utilities then you have to include the appropriate mobius-rx/rx2/rx3 library in your project and use the RxEventSources class
Thanks for the previous answers @pettermahlen
Are permission accepted/denied considered External events?
Scenario: Lets take a use case where we want to be making location pings every 5 minutes, for this we will need to ensure location permission is given.
Approach-1: Get permission state in Effect handler by asking platform layer and ask user if not already given (here the access given/denied comes back as a callback to effect handler itself.)
Approach-2: Effect handler asks platform layer to check for permission and this comes back in as a external/user interaction event to the loop.
Which one do you see going with the style of Mobius without breaking principles?
Both are fine, it's a matter of taste.
Hey @pettermahlen we are going ahead with using Mobius architecture for our application.
We were thinking of using coroutines flow. What are your thoughts on the flowbius from trello?
Glad to hear you're moving on with Mobius, I hope it will be useful to you!
I haven't used Flowbius myself, so cannot make a recommendation either way. I think it looks nice though.
I will close this issue as it seems your questions have been answered.
@pettermahlen We are mostly using mobius loops with viewmodel across our app.
What is the use case for a mobius controller?
Can Mobius Controller be thought of an equivalent to VM with loop?
Could you give me actual example use cases for Using Mobius controller over VM with loop?