mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
update mixin for https://github.com/MetinSeylan/Vue-Socket.io/issues/168
This commit is contained in:
parent
4b7c282d0c
commit
176c060356
3 changed files with 21 additions and 17 deletions
2
dist/vue-socketio.js
vendored
2
dist/vue-socketio.js
vendored
File diff suppressed because one or more lines are too long
|
@ -1,7 +1,7 @@
|
|||
{
|
||||
"name": "vue-socket.io",
|
||||
"author": "Metin Seylan <metinsyln@gmail.com>",
|
||||
"version": "3.0.3",
|
||||
"version": "3.0.4",
|
||||
"description": "socket.io implemantation for vuejs and vuex",
|
||||
"main": "dist/vue-socketio.js",
|
||||
"scripts": {
|
||||
|
|
34
src/mixin.js
34
src/mixin.js
|
@ -1,9 +1,26 @@
|
|||
export default {
|
||||
|
||||
/**
|
||||
* lets collect all socket callback functions then register
|
||||
* Assign runtime callbacks
|
||||
*/
|
||||
created(){
|
||||
beforeCreate(){
|
||||
|
||||
if(!this.sockets) this.sockets = {};
|
||||
|
||||
this.sockets.subscribe = (event, callback) => {
|
||||
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
||||
};
|
||||
|
||||
this.sockets.unsubscribe = (event) => {
|
||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||
};
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
* Register all socket events
|
||||
*/
|
||||
mounted(){
|
||||
|
||||
if(this.$options.sockets){
|
||||
|
||||
|
@ -15,19 +32,6 @@ export default {
|
|||
|
||||
});
|
||||
|
||||
this.sockets = {
|
||||
subscribe: (event, callback) => {
|
||||
|
||||
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
||||
|
||||
},
|
||||
unsubscribe: (event) => {
|
||||
|
||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
},
|
||||
|
|
Loading…
Add table
Reference in a new issue