Giter Site home page Giter Site logo

Comments (1)

pedroql avatar pedroql commented on May 27, 2024 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).

MVFlow.kt#L28

--

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.