Update mixin.js

This commit is contained in:
NeonKaa 2018-11-26 10:40:54 +02:00 committed by GitHub
parent 4b7c282d0c
commit fc7ad95293
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,29 +5,24 @@ export default {
*/ */
created(){ created(){
if(this.$options.sockets){ this.sockets = {
subscribe: (event, callback) => {
this.$vueSocketIo.emitter.addListener(event, callback, this);
},
unsubscribe: (event) => {
this.$vueSocketIo.emitter.removeListener(event, this);
}
};
Object.keys(this.$options.sockets).forEach(event => { if(this.sockets){
Object.keys(this.sockets).forEach(event => {
if(event !== 'subscribe' && event !== 'unsubscribe') { if(event !== 'subscribe' && event !== 'unsubscribe') {
this.$vueSocketIo.emitter.addListener(event, this.$options.sockets[event], this); 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(){ 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); this.$vueSocketIo.emitter.removeListener(event, this);