diff --git a/client/src/js/components/TabList.jsx b/client/src/js/components/TabList.jsx index 86b30771..51eedb26 100644 --- a/client/src/js/components/TabList.jsx +++ b/client/src/js/components/TabList.jsx @@ -32,10 +32,8 @@ var TabList = React.createClass({ }, render: function() { - var self = this; - - var tabs = _.map(this.state.channels, function(server, address) { - var serverTabs = _.map(server, function(channel, name) { + var tabs = _.map(this.state.channels, (server, address) => { + var serverTabs = _.map(server, (channel, name) => { return ( { serverTabs.push( this.emit('connect'); + this.ws.onclose = () => this.emit('disconnect'); + this.ws.onmessage = (e) => { + var msg = JSON.parse(e.data); -var socket = { - send: function(type, data) { - ws.send(JSON.stringify({ type: type, request: data })); + this.emit(msg.type, msg.response); + } } -}; -_.extend(socket, EventEmitter.prototype); + send(type, data) { + this.ws.send(JSON.stringify({ type: type, request: data })); + } +} -ws.onopen = function() { - socket.emit('connect'); -}; - -ws.onclose = function() { - socket.emit('disconnect'); -}; - -ws.onmessage = function(e) { - var msg = JSON.parse(e.data); - - socket.emit(msg.type, msg.response); -}; - -module.exports = socket; \ No newline at end of file +module.exports = new Socket(); \ No newline at end of file diff --git a/client/src/js/stores/selectedTab.js b/client/src/js/stores/selectedTab.js index f64f5b3e..97a71b05 100644 --- a/client/src/js/stores/selectedTab.js +++ b/client/src/js/stores/selectedTab.js @@ -23,9 +23,9 @@ var selectedTabStore = Reflux.createStore({ this.listenTo(serverActions.load, 'loadServers'); }, - select: function(server, channel) { + select: function(server, channel = null) { selectedTab.server = server; - selectedTab.channel = channel || null; + selectedTab.channel = channel; if (channel) { selectedTab.name = channel; diff --git a/client/src/js/util.js b/client/src/js/util.js index c87c3487..c7a1a123 100644 --- a/client/src/js/util.js +++ b/client/src/js/util.js @@ -16,9 +16,7 @@ exports.timestamp = function(date) { return h + ':' + m; }; -exports.wrapMessages = function(messages, width, charWidth, indent) { - indent = indent || 0; - +exports.wrapMessages = function(messages, width, charWidth, indent = 0) { for (var j = 0, llen = messages.length; j < llen; j++) { var message = messages[j]; var words = message.message.split(' ');