From fc7ad95293109ee0d396e2e496f690bf2b39aab7 Mon Sep 17 00:00:00 2001 From: NeonKaa <40620679+neonkaafi@users.noreply.github.com> Date: Mon, 26 Nov 2018 10:40:54 +0200 Subject: [PATCH] Update mixin.js --- src/mixin.js | 39 +++++++++++++++++---------------------- 1 file changed, 17 insertions(+), 22 deletions(-) diff --git a/src/mixin.js b/src/mixin.js index 35c5657..f9e9b8d 100644 --- a/src/mixin.js +++ b/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 { } -} \ No newline at end of file +}