From fca2985d9b3abb95cdf70c2a4f272dec02a877cf Mon Sep 17 00:00:00 2001 From: khlieng Date: Sat, 21 Feb 2015 07:48:25 +0100 Subject: [PATCH] Sprinkle some ES6 on it --- client/src/js/components/TabList.jsx | 8 +++---- client/src/js/socket.js | 36 +++++++++++----------------- client/src/js/stores/selectedTab.js | 4 ++-- client/src/js/util.js | 4 +--- 4 files changed, 20 insertions(+), 32 deletions(-) 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(' ');