Comments (1)
This is covered in the documentation:
Note: although the handler receives the current state when an action is performed, if the handler performs a slow operation, the handler will no longer know the most recent state. This is why the handler canβt mutate the state directly.
From https://pedroql.github.io/mvflow/#reducer
The reason we can't have the handler receiving the current state is because there's no way to guarantee that this is and remains the most up to date state while the handler does something with it because there could be multiple coroutines accessing and mutating the state.
Instead, MVFlow ensures that calls to the reducer don't interleave so it's the only safe place to update the state.
We do have unit tests for the scenarios you highlight here.
--
You need to update your code sample and use the mutations in a different way. In your mutations, you pass the desired final value. Instead, you should pass what you want to do to the state. So it goes from emit(MyMutation.IncrementCount(state.count + 1))
to emit(MyMutation.IncrementCount(1))
. And your reducer (with a renamed property) becomes state.copy(count = state.count+ mutation.changeValue)
.
This is what we mean when we say
Keep also in mind that Mutations should indicate how to change the state, but should not rely on/assume what the current state is (as of when the action was emitted).
--
Let me know if you have ideas to improve the documentation so other people don't miss this important detail!
from mvflow.
Related Issues (11)
- Is it possible to add time travel debugger? HOT 4
- Unit Test samples HOT 1
- Ability to allow same Flow emission HOT 4
- is it possible to use MVFlow in Jetpack Compose? HOT 1
- Consider moving from SharedFlow to Channel HOT 1
- Best practices to send a throwable from Fragment/Activity? HOT 2
- Is it possible to combine reducer & handler? HOT 1
- Migrate from jcenter HOT 1
- How to stop an async task launched by the handler HOT 2
- Android sample app wont even sync on latest Android Studio Iguana 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 mvflow.