Comments (10)
@ATizik Do you have a MvRxStateStore
implementation with coroutines? The main reason we used rx is our own familiarity with rx but if coroutines perform better, it would be worth investigating for sure.
cc @BenSchwab @elihart @hellohuanlin
from mavericks.
@gpeal
I do have something similar in our projects, since you're interested I'll adapt it to MvRx api and share with you
from mavericks.
@ATizik Would love to see a PR. If you have a good way to benchmark it, that would be great too!
from mavericks.
@gpeal
Here it is #84
Speed difference was negligible on existing test, maybe I need a heavier state and operations, i'm in the process of writing more comprehensive benchmark. I'll also test a memory consumption later.
from mavericks.
I still do not understand Why can't simply use the Main Thread to avoid race conditions of setting the state? The stateReducer
is just updating the state, why can't put that in the main thread. And if the state changes very frequently, I would prefer to use the LiveData
to avoid creating new states.
from mavericks.
@luozejiaqun
It's better to offload it to the background, there is nothing specific about main thread that's better for avoiding race conditions than any other thread.
I'm not sure how LiveData
will help avoid creating new states, we still have to run stateReducer
the same amount of times
from mavericks.
First question, if there is nothing specific about main thread, why don't use the main thread. Since every ViewModel
owns a StateStore
, using main thread will avoid creating other threads. I'm not familiar with kotlin coroutines, but the fundamental thing is still threads, less threads achieve the same goal, this my rough understanding. If the stateReducer
is simple, there is no reason why can't put it in main thread.
Second question, there is not contradiction between State
and LiveData
, why can't put a property in LiveData
and remove it from the State
. In this way, the property can be mutable, changes it and sets it to LiveData
's value, then done. The fact is there are some properties we can't use in State
, such as SparseArray
and LongSparseArray
. I put these properties in LiveData
and that works well for me.
from mavericks.
@luozejiaqun A fundamental principle of MvRx is that you observe a stream of immutable state. Storing a SparseArray in LiveData actually enables you to write buggy code. If you modify an element in the array, your LiveData won't update. That's why MvRx enforces immutability.
Regarding the background thread, there are performance advantages in keeping it off the main thread but we have implemented it in such a way that there should be no cognitive overhead for the developer. Why not offload things off the main thread if we can?
from mavericks.
@gpeal I know MvRx enforces immutability, because of the reason, I can't use SparseArray in the State. The MvRx's suggestion is using immutable list, but I don't think that makes sense. Because of performance advantages we use SparseArray, immutable list can't meet that requirements. LiveData maybe buggy, but that's my only choice for now.
Regarding the background thread, I know the performance advantages.But using the main thread and no more new threads also has performance advantages.
from mavericks.
@luozejiaqun Let's separate that discussion from the coroutines state store
from mavericks.
Related Issues (20)
- Calling `mavericksActivityViewModel` in fragment, not working properly HOT 1
- Type com.airbnb.mvrx.AndroidStrictModeExtensionsKt is defined multiple times HOT 1
- possible incompatibility with Kotlin coroutines 1.7.0 HOT 2
- Using androidx.lifecycle:lifecycle-runtime-ktx:2.6.1 problems HOT 13
- Fail State call twice and make error HOT 2
- how to use stateflow in MavericksViewModel HOT 2
- How can I use MavericksView in a View or a Layout
- compare with mvc,mvp,mvvm HOT 2
- The viewModel() method may be missing the postInvalidate() logic. HOT 2
- Hilt and ViewModel initialization with Navigation Component arguments HOT 6
- Exploration of the correct way to update state with List<Data> in state HOT 1
- Ensure that your state properties properly implement hashCode. HOT 7
- I wanted to use the latest version of Epoxy, Mavericks, Paging3 (Epoxy Paging3), but couldn't find the Demo. Is it possible to combine all three?
- java.lang.SecurityException: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified
- java.lang.IllegalStateException HOT 1
- Value classes break State class no zero argument constructor usage HOT 1
- Discuss whenStarted function deprecation HOT 7
- I am using MavericksViewModel on Compose, I want to get the LifecycleOwner object in ViewModel how do I need to get this? HOT 3
- Crash when creating MavericksViewModel HOT 6
- Combining Mavericks with "custom" network response and error handling HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from mavericks.