Comments (7)
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.
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.
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.
from mockstate.
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.
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.
@darklow see that: Version 2.0 :)
from mockstate.
Related Issues (11)
- What is the reason having state name when calling action? HOT 1
- Version 2.0 HOT 4
- There are some problems that need to confirm HOT 2
- Actions being triggered multiple times HOT 2
- Cannot unsubscribe (el is undefined)
- Cannot provide multiple arguments for trigger method HOT 8
- Actions as store functions HOT 4
- Is it possible to have multiple stores? HOT 2
- Typos, naming and a question HOT 4
- Usage question on Actions 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 mockstate.