mirror of
https://github.com/MetinSeylan/Vue-Socket.io.git
synced 2025-04-16 15:21:28 +02:00
Update mixin.js
This commit is contained in:
parent
4b7c282d0c
commit
fc7ad95293
1 changed files with 17 additions and 22 deletions
39
src/mixin.js
39
src/mixin.js
|
@ -4,32 +4,27 @@ export default {
|
|||
* lets collect all socket callback functions then register
|
||||
*/
|
||||
created(){
|
||||
|
||||
this.sockets = {
|
||||
subscribe: (event, callback) => {
|
||||
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
||||
},
|
||||
unsubscribe: (event) => {
|
||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||
}
|
||||
};
|
||||
|
||||
if(this.$options.sockets){
|
||||
|
||||
Object.keys(this.$options.sockets).forEach(event => {
|
||||
if(this.sockets){
|
||||
|
||||
Object.keys(this.sockets).forEach(event => {
|
||||
|
||||
if(event !== 'subscribe' && event !== 'unsubscribe') {
|
||||
this.$vueSocketIo.emitter.addListener(event, this.$options.sockets[event], this);
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
this.sockets = {
|
||||
subscribe: (event, callback) => {
|
||||
|
||||
this.$vueSocketIo.emitter.addListener(event, callback, this);
|
||||
|
||||
},
|
||||
unsubscribe: (event) => {
|
||||
|
||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -37,9 +32,9 @@ export default {
|
|||
*/
|
||||
beforeDestroy(){
|
||||
|
||||
if(this.$options.sockets){
|
||||
if(this.sockets){
|
||||
|
||||
Object.keys(this.$options.sockets).forEach(event => {
|
||||
Object.keys(this.sockets).forEach(event => {
|
||||
|
||||
this.$vueSocketIo.emitter.removeListener(event, this);
|
||||
|
||||
|
@ -49,4 +44,4 @@ export default {
|
|||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue