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

New socket instance created if vuex’s store mutation function called inside socket #338

Open
JH-Eric-Yang opened this issue Oct 12, 2022 · 0 comments

Comments

@JH-Eric-Yang
Copy link

Hi, I tired to call a mutation function in the vuex's store inside a socket event listener. It looks something like this

import { createStore } from "vuex";

export default createStore({
    state() {
        return {
            message: "default message",
        };
    },
    mutations: {
        SOCKET_updateMessage(state, message) {
            console.log("SOCKET_updateMessage: message:", message);
            state.message = message;
            this.updateMessage(message);
        },
       
	 updateMessage(message) {
            console.log(message)
	        },
    },
});

It will work but I notice that it will recreate a new socket instance. The client will create and communicate with the server with the new socket instance (with different socket.id). I wonder why this is happening. Thank you.

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

No branches or pull requests

1 participant