Skip to content
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

Closed
MarlBurroW opened this issue Feb 13, 2017 · 5 comments
Closed

Trigger Vuex action with on socket event #34

MarlBurroW opened this issue Feb 13, 2017 · 5 comments
Labels

Comments

@MarlBurroW
Copy link

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.

@MetinSeylan
Copy link
Owner

added roadmap

@michgeek
Copy link
Contributor

hey @MarlBurroW can you tell more about this ? I'm not sure to understand, maybe I can help

@MarlBurroW
Copy link
Author

MarlBurroW commented Mar 19, 2017

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.
it could be nice to do the same thing for actions, because sometime you need to trigger more than one mutation on a socket event. Sometime you need to make some other operations, asynchrone calls, etc... and actions are made for that.

@michgeek
Copy link
Contributor

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 actions or mutations or both

@MarlBurroW
Copy link
Author

MarlBurroW commented Mar 19, 2017

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');
    }
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants