Sprinkle some ES6 on it
This commit is contained in:
parent
518d3eaa07
commit
fca2985d9b
@ -32,10 +32,8 @@ var TabList = React.createClass({
|
|||||||
},
|
},
|
||||||
|
|
||||||
render: function() {
|
render: function() {
|
||||||
var self = this;
|
var tabs = _.map(this.state.channels, (server, address) => {
|
||||||
|
var serverTabs = _.map(server, (channel, name) => {
|
||||||
var tabs = _.map(this.state.channels, function(server, address) {
|
|
||||||
var serverTabs = _.map(server, function(channel, name) {
|
|
||||||
return (
|
return (
|
||||||
<TabListItem
|
<TabListItem
|
||||||
server={address}
|
server={address}
|
||||||
@ -45,7 +43,7 @@ var TabList = React.createClass({
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
_.each(self.state.privateChats[address], function(chat, nick) {
|
_.each(this.state.privateChats[address], (chat, nick) => {
|
||||||
serverTabs.push(
|
serverTabs.push(
|
||||||
<TabListItem
|
<TabListItem
|
||||||
server={address}
|
server={address}
|
||||||
|
@ -1,29 +1,21 @@
|
|||||||
var EventEmitter = require('events').EventEmitter;
|
var EventEmitter = require('events').EventEmitter;
|
||||||
|
|
||||||
var _ = require('lodash');
|
class Socket extends EventEmitter {
|
||||||
|
constructor() {
|
||||||
|
this.ws = new WebSocket('ws://' + window.location.host + '/ws');
|
||||||
|
|
||||||
var ws = new WebSocket('ws://' + window.location.host + '/ws');
|
this.ws.onopen = () => this.emit('connect');
|
||||||
|
this.ws.onclose = () => this.emit('disconnect');
|
||||||
var socket = {
|
this.ws.onmessage = (e) => {
|
||||||
send: function(type, data) {
|
|
||||||
ws.send(JSON.stringify({ type: type, request: data }));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
_.extend(socket, EventEmitter.prototype);
|
|
||||||
|
|
||||||
ws.onopen = function() {
|
|
||||||
socket.emit('connect');
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onclose = function() {
|
|
||||||
socket.emit('disconnect');
|
|
||||||
};
|
|
||||||
|
|
||||||
ws.onmessage = function(e) {
|
|
||||||
var msg = JSON.parse(e.data);
|
var msg = JSON.parse(e.data);
|
||||||
|
|
||||||
socket.emit(msg.type, msg.response);
|
this.emit(msg.type, msg.response);
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
module.exports = socket;
|
send(type, data) {
|
||||||
|
this.ws.send(JSON.stringify({ type: type, request: data }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = new Socket();
|
@ -23,9 +23,9 @@ var selectedTabStore = Reflux.createStore({
|
|||||||
this.listenTo(serverActions.load, 'loadServers');
|
this.listenTo(serverActions.load, 'loadServers');
|
||||||
},
|
},
|
||||||
|
|
||||||
select: function(server, channel) {
|
select: function(server, channel = null) {
|
||||||
selectedTab.server = server;
|
selectedTab.server = server;
|
||||||
selectedTab.channel = channel || null;
|
selectedTab.channel = channel;
|
||||||
|
|
||||||
if (channel) {
|
if (channel) {
|
||||||
selectedTab.name = channel;
|
selectedTab.name = channel;
|
||||||
|
@ -16,9 +16,7 @@ exports.timestamp = function(date) {
|
|||||||
return h + ':' + m;
|
return h + ':' + m;
|
||||||
};
|
};
|
||||||
|
|
||||||
exports.wrapMessages = function(messages, width, charWidth, indent) {
|
exports.wrapMessages = function(messages, width, charWidth, indent = 0) {
|
||||||
indent = indent || 0;
|
|
||||||
|
|
||||||
for (var j = 0, llen = messages.length; j < llen; j++) {
|
for (var j = 0, llen = messages.length; j < llen; j++) {
|
||||||
var message = messages[j];
|
var message = messages[j];
|
||||||
var words = message.message.split(' ');
|
var words = message.message.split(' ');
|
||||||
|
Loading…
Reference in New Issue
Block a user