From ffbf48ee2861865c9ce713a195e70764b114de71 Mon Sep 17 00:00:00 2001 From: lastmirage Date: Mon, 19 Mar 2018 15:15:41 +0900 Subject: [PATCH] indent --- src/Emitter.js | 6 +++--- src/Main.js | 12 ++++++------ src/Observer.js | 34 +++++++++++++++++----------------- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/Emitter.js b/src/Emitter.js index c98984e..caf0bc4 100755 --- a/src/Emitter.js +++ b/src/Emitter.js @@ -4,9 +4,9 @@ export default new class { } addListener(label, callback, vm) { - if(typeof callback == 'function'){ + if (typeof callback == 'function') { this.listeners.has(label) || this.listeners.set(label, []); - this.listeners.get(label).push({callback: callback, vm: vm}); + this.listeners.get(label).push({ callback: callback, vm: vm }); return true } @@ -39,7 +39,7 @@ export default new class { if (listeners && listeners.length) { listeners.forEach((listener) => { - listener.callback.call(listener.vm,...args) + listener.callback.call(listener.vm, ...args) }); return true; } diff --git a/src/Main.js b/src/Main.js index f19a820..f98223d 100755 --- a/src/Main.js +++ b/src/Main.js @@ -3,16 +3,16 @@ import Emitter from './Emitter' export default { - install(Vue, connection, store){ + install(Vue, connection, store) { - if(!connection) throw new Error("[Vue-Socket.io] cannot locate connection") + if (!connection) throw new Error("[Vue-Socket.io] cannot locate connection") let observer = new Observer(connection, store) Vue.prototype.$socket = observer.Socket; Vue.mixin({ - created(){ + created() { let sockets = this.$options['sockets'] this.$options.sockets = new Proxy({}, { @@ -28,16 +28,16 @@ export default { } }) - if(sockets){ + if (sockets) { Object.keys(sockets).forEach((key) => { this.$options.sockets[key] = sockets[key]; }); } }, - beforeDestroy(){ + beforeDestroy() { let sockets = this.$options['sockets'] - if(sockets){ + if (sockets) { Object.keys(sockets).forEach((key) => { delete this.$options.sockets[key] }); diff --git a/src/Observer.js b/src/Observer.js index 514f93e..698058a 100755 --- a/src/Observer.js +++ b/src/Observer.js @@ -1,30 +1,30 @@ import Emitter from './Emitter' import Socket from 'socket.io-client' -export default class{ +export default class { constructor(connection, store) { - if(typeof connection == 'string'){ + if (typeof connection == 'string') { this.Socket = Socket(connection); - }else{ + } else { this.Socket = connection } - if(store) this.store = store; + if (store) this.store = store; this.onEvent() } - onEvent(){ + onEvent() { var super_onevent = this.Socket.onevent; this.Socket.onevent = (packet) => { super_onevent.call(this.Socket, packet); Emitter.emit.apply(Emitter, packet.data); - if(this.store) this.passToStore('SOCKET_'+packet.data[0], [ ...packet.data.slice(1)]) + if (this.store) this.passToStore('SOCKET_' + packet.data[0], [...packet.data.slice(1)]) }; let _this = this; @@ -33,30 +33,30 @@ export default class{ .forEach((value) => { _this.Socket.on(value, (data) => { Emitter.emit(value, data); - if(_this.store) _this.passToStore('SOCKET_'+value, data) + if (_this.store) _this.passToStore('SOCKET_' + value, data) }) }) } - passToStore(event, payload){ - if(!event.startsWith('SOCKET_')) return + passToStore(event, payload) { + if (!event.startsWith('SOCKET_')) return - for(let namespaced in this.store._mutations) { + for (let namespaced in this.store._mutations) { let mutation = namespaced.split('/').pop() - if(mutation === event.toUpperCase()) this.store.commit(namespaced, payload) + if (mutation === event.toUpperCase()) this.store.commit(namespaced, payload) } - for(let namespaced in this.store._actions) { + for (let namespaced in this.store._actions) { let action = namespaced.split('/').pop() - if(!action.startsWith('socket_')) continue + if (!action.startsWith('socket_')) continue - let camelcased = 'socket_'+event.toLowerCase() - .replace('SOCKET_', '') - .replace(/[\W\s_]+(\w)/g, (match, p1) => p1.toUpperCase()) + let camelcased = 'socket_' + event.toLowerCase() + .replace('SOCKET_', '') + .replace(/[\W\s_]+(\w)/g, (match, p1) => p1.toUpperCase()) - if(action === camelcased) this.store.dispatch(namespaced, payload) + if (action === camelcased) this.store.dispatch(namespaced, payload) } } }