Created
January 17, 2018 14:07
-
-
Save anonymous/640ae42b66695ece5af27d9f3b250f9a to your computer and use it in GitHub Desktop.
Módulo con Vuex y Vue-Socket.IO
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const counterModule = { | |
state: { | |
count: 0 | |
}, | |
//estas mutaciones serán ejecutadas por Node.js, deben comenzar por SOCKET_ | |
mutations: { | |
SOCKET_COUNTER_INCREMENT (state) { | |
state.count = state.count + 1 | |
}, | |
SOCKET_COUNTER_DECREMENT (state) { | |
state.count = state.count - 1 | |
} | |
}, | |
//emitimos acciones desde nuestra app | |
actions: { | |
socket_increment: ({commit, state, rootState}) => { | |
rootState.io.emit('increment', state.count) //emitimos al server el evento increment | |
}, | |
socket_decrement: ({commit, state, rootState}) => { | |
rootState.io.emit('decrement', state.count) //emitimos al server el evento decrement | |
} | |
} | |
} | |
export default counterModule |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment