Giter VIP home page Giter VIP logo

Comments (7)

darklow avatar darklow commented on July 24, 2024

I noticed same behaviour with performing one task too.
If task is asynchronous and any other actions were perfomed while task haven't completed, then after task completes subscribed component handlers never get called.

In my example below i am using websockets on my app and I have following initSocket action.
The first two states: connecting and connecting are dispatched correctly.

Afterwards my app calls lot of different actions and mutations and if server gets disconnected, my subscribed component handlers never get called on disconnect event. State mutation is called, but not subscribed component handlers. However if I don't call any other actions after connected state and just for test turn off server, then disconnect works as intended and all handlers that are subscribed to wsState gets called.

Looks like there riotux is some kind of singleton and you can't process multiple things or actions at parallel and riotux keeps last action state and only that is getting dispatched. Is this something that can be fixed? Thank you.

riotux.Store({
    state: {
        wsState: null
    },
    mutations: {
        setWsState: function (state, value) {
            state.wsState = value;
        }
    }
});

riotux.Actions({
    initSocket: function (store) {
        // ... socket connect here

        store.dispatch('setWsState', 'connecting');

        socket.onmessage = function (message) {
           //...
        };

        socket.onopen = function () {
            store.dispatch('setWsState', 'connected');
        };
        socket.onclose = function () {
            store.dispatch('setWsState', 'disconnected');
        };
    },
});

from mockstate.

darklow avatar darklow commented on July 24, 2024

Sorry if it is hard to understand, but in other words if you call two actions right one after each other and each action should update different store properties aka states, then only second will be dispatched to component handler because by looking at the code _currentState is global and being overriden right on action call and when handlers are being called it uses same global _currentState.

riotux.action(‘items’, ‘doSomethingAsync’, function(){ }); // Components subscribed to `items` state are never called
riotux.action(‘count’, ‘doSomethingNow’, function(){ });

from mockstate.

darklow avatar darklow commented on July 24, 2024

I created a fix/workaround that solves my issue, could you take a look please?
Now state name from action is forwarded to the update() and handlers are called based on what was state name when action was called, not based on _currentState
Thanks.

from mockstate.

fkei avatar fkei commented on July 24, 2024

👍

from mockstate.

darklow avatar darklow commented on July 24, 2024

Waiting for @luisvinicius167 to comment my solution, if he agrees, I can make a PR. My fix is working great so far, tried many simultaneous actions which perform mutations on asynchronous responses and so far no issues.

from mockstate.

luisvinicius167 avatar luisvinicius167 commented on July 24, 2024

Sorry for long response time! Working a lot :) I understood about this bug, very excited about your PR, I will waiting! @darklow Thank you so much! I'm thinking to create a Riotux dev tools, would be nice. Thanks bro!

from mockstate.

luisvinicius167 avatar luisvinicius167 commented on July 24, 2024

@darklow see that: Version 2.0 :)

from mockstate.

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.