-
-
Notifications
You must be signed in to change notification settings - Fork 38
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
Error while using the library with Vuex in Quasar App #384
Comments
Hi @sandeeppsmys SOCKET_MESSAGE (state, data) { // everything is in upper case
console.log(data)
} Can you try that? |
Thanks Probil for the quick response. Yeah I tried that one too.. But not getting mutated on the store. Here is my store export default function (/* { ssrContext } */) {
const Store = new Vuex.Store({
modules: {
notificationManager
},
state: {
},
mutations: {
SOCKET_MESSAGE (state, data) {
console.log('SOCKET_MESSAGE')
console.log(data)
}
},
actions: {
socket_message (context, data) {
console.log('action SOCKET_MESSAGE')
console.log(data)
}
},
// enable strict mode (adds overhead!)
// for dev mode only
// strict: process.env.DEV
strict: false
})
return Store
} Please note that I am using a module 'notificationManager' and I tried placing the mutations there also but no luck. |
Are you using server side rendering? |
I am using Quasar Development Server locally. |
@sandeeppsmys Can you show me how do you trigger socket event on the server? |
Service is in python.. Following line emits the socket event. |
@sandeeppsmys Then mutation should look like this: SOCKET_DELETE_EVENT (state, data) {
console.log(data); // prints -> {"id": '12'}
} |
@sandeeppsmys If it doesn't help, can you please create a repo with a minimal reproduction of the bug? I'd like to resolve it |
Getting exactly the same issue, no socket mutation calls are working, but directly listending to the message on a component is fine |
Hi @badders 👋 Sound strange 🤔 Can you please create a repo with bug reproduction? I will be a HUGE step ahead. |
@probil I think if you just install a base quasar build and select vuex during installation that will give you what you need https://quasar.dev/quasar-cli/cli-documentation/vuex-store |
Thanks @KodeStar |
I think it may not like my store, I'm doing the following in router/index.js: import Vue from 'vue'
import VueRouter from 'vue-router'
import socketio from 'socket.io-client'
import VueSocketio from 'vue-socket.io-extended'
import store from '../store'
export const SocketInstance = socketio('http://localhost:3000')
Vue.use(VueRouter)
Vue.use(VueSocketio, SocketInstance, { store }) store/index.js looks like: import Vue from 'vue'
import Vuex from 'vuex'
import app from './app'
import tags from './tags'
import websites from './websites'
import servers from './servers'
import terminals from './terminals'
Vue.use(Vuex)
export default function (/* { ssrContext } */) {
const Store = new Vuex.Store({
state: {
},
modules: {
app, tags, websites, servers, terminals
}
})
return Store
} My store/terminals/mutations.js looks like: export function SOCKET_CONSOLEKEY (state, payload) {
console.log('hit the mutation')
} I've also notice the following pop up in the console:
If I remove the store parts and use |
Wow 👍 Thanks, @KodeStar for pointing out. You are cool 😎 |
No, that error was my fault, I downloaded the src and imported it manually so I could find out where that error was coming from. I should have done: |
I can see the events firing here, so it just never gets past the passToStore part as store is undefined |
Ok, I think it's because quasar uses modules rather than exposing its state/mutations/actions etc at the root level. If I create a new Vuex.store() just for this and pass that then the mutations get fired. Not ideal but will do for now I guess |
@KodeStar in this example #384 (comment)
// router/index.js
///..
import store from '../store'
export const SocketInstance = socketio('http://localhost:3000')
Vue.use(VueRouter)
Vue.use(VueSocketio, SocketInstance, { store: store() }) // <-- calling store function here is important But keep in mind that you should use the same instance of store in both vue-socket.io-extended and main app entry point. So it may look like so: import Store from '../store'
const SocketInstance = socketio('http://localhost:3000')
const store = Store(); // <-- here we create a real instance of the store
Vue.use(VueRouter)
Vue.use(VueSocketio, SocketInstance, { store }) // <-- here we use it
new Vue({
el: '#app',
store, // <-- here we use it one more time but instance is the same
render: h => h(App)
})
Vue.use(VueSocketio, SocketInstance, { store }) // right usage
Vue.use(VueSocketio, SocketInstance, { Store }) // wrong usage |
And it's working :) I think all it needed was the |
That's a good news! |
I've just checked quasar project a little bit. And there is not main app entry point. So my suggestion would be to wrap plugin registration and call it during store init. E.g.: // socket-plugin.js
import Vue from 'vue';
import io from 'socket.io-client';
import VueSocketIoExt from 'vue-socket.io-extended';
export const socket = io('http://localhost:3000');
export default function (store) {
Vue.use(VueSocketIoExt, socket, { store });
} Then // store/index.js
import Vue from 'vue';
import Vuex from 'vuex';
import SocketPlugin from '../socket-plugin';
Vue.use(Vuex);
export default function (/* { ssrContext } */) {
const Store = new Vuex.Store({
mutations: {
SOCKET_CONNECT() {
console.log('CONNECTED');
},
},
strict: process.env.DEV,
});
SocketPlugin(Store); // <--- this line connects plugin in right, quasar-compatible way!
return Store;
} I've just tried it on my local machine and it works just fine! Can you check that @KodeStar and/or @sandeeppsmys ? |
I can confirm that works for me, though the previous |
Thanks everyone. |
Thanks probil.. its working for me too. Appreciate your efforts and enthusiasm in closing the issue. |
I was facing the same issue but using NuxtJs and I found that the parameter
plugins/vue-socket.js
Hope it helps |
Thanks @matiasjg |
Mutations are called when used with Store
My code looks like this..
[In App.vue]
My mutation is like this in my store's mutations
From the server, we are emitting ('message', data)
Please be noted that I am using Quasar and initializing it in App.vue. Works fine with components but not with Vuex store.
The text was updated successfully, but these errors were encountered: