-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trigger Vuex action with on socket event #34
Comments
added roadmap |
hey @MarlBurroW can you tell more about this ? I'm not sure to understand, maybe I can help |
Hey, i'll try to explain you: With Vuex, you can:
Currently, with Vue-Socket.io, you can trigger Vuex mutations on a socket.io event by prefixing the name of the mutation with "SOCKET_". BUT (if I'm not wrong) you can't dispatch actions by this same way. |
What do you think of having the same concept for actions ? {
mutations: {
my_mutation: (state) => { /*...*/ },
another_mutation: (state) => { /*...*/ },
SOCKET_USER_MESSAGE: (state) => { /*...*/ }
],
actions: {
SOCKET_USER_MESSAGE: (context, payload) => {
// ... do things ...
context.dispatch('my_mutation', payload);
context.dispatch('another_mutation', payload);
}
}
} You can decide to declare the socket event either in |
Yes, sounds great for me ! I think it's important because it allow to create more complex flow when a socket event is triggered: EXAMPLE: actions: {
SOCKET_USER_MESSAGE: (context, payload) => {
context.dispatch('new_message_notification', payload);
context.commit('add_message', payload);
AudioManager.play('new_message_received');
}
} |
Hello,
Currently, you can trigger vuex mutations with the "SOCKET_" prefix and this is nice !
But sometime, socket events must do more that just change the vuex state. for me it's also very important to be able to trigger Vuex actions by a similar way. Somehting like "event-name" triggering "socketEventName" action.
The text was updated successfully, but these errors were encountered: