mirror of
https://github.com/ENSL/ensl_gathers.git
synced 2024-11-26 22:31:08 +00:00
ES2015 strikes again
This commit is contained in:
parent
6ecdba9232
commit
c7c7c4eb24
4 changed files with 42 additions and 43 deletions
|
@ -2,8 +2,8 @@
|
|||
|
||||
var socket;
|
||||
|
||||
function initialiseVisibilityMonitoring (socket) {
|
||||
var hidden, visibilityChange;
|
||||
var initialiseVisibilityMonitoring = (socket) => {
|
||||
let hidden, visibilityChange;
|
||||
if (typeof document.hidden !== "undefined") { // Opera 12.10 and Firefox 18 and later support
|
||||
hidden = "hidden";
|
||||
visibilityChange = "visibilitychange";
|
||||
|
@ -18,7 +18,7 @@ function initialiseVisibilityMonitoring (socket) {
|
|||
visibilityChange = "webkitvisibilitychange";
|
||||
}
|
||||
|
||||
document.addEventListener(visibilityChange, function () {
|
||||
document.addEventListener(visibilityChange, () => {
|
||||
if (document[hidden]) {
|
||||
socket.emit("users:away");
|
||||
} else {
|
||||
|
@ -27,16 +27,16 @@ function initialiseVisibilityMonitoring (socket) {
|
|||
}, false);
|
||||
}
|
||||
|
||||
function initialiseComponents () {
|
||||
var socketUrl = window.location.protocol + "//" + window.location.host;
|
||||
var initialiseComponents = () => {
|
||||
let socketUrl = window.location.protocol + "//" + window.location.host;
|
||||
socket = io(socketUrl)
|
||||
.on("connect", function () {
|
||||
.on("connect", () => {
|
||||
console.log("Connected");
|
||||
})
|
||||
.on("reconnect", function () {
|
||||
.on("reconnect", () => {
|
||||
console.log("Reconnected");
|
||||
})
|
||||
.on("disconnect", function () {
|
||||
.on("disconnect", () => {
|
||||
console.log("Disconnected")
|
||||
});
|
||||
|
||||
|
|
|
@ -32,18 +32,17 @@ var Chatroom = React.createClass({
|
|||
|
||||
sendMessage(message) {
|
||||
socket.emit("newMessage", {message: message});
|
||||
}
|
||||
},
|
||||
|
||||
scrollToBottom() {
|
||||
var node = React.findDOMNode(this.refs.messageContainer);
|
||||
let node = React.findDOMNode(this.refs.messageContainer);
|
||||
node.scrollTop = node.scrollHeight;
|
||||
},
|
||||
|
||||
render() {
|
||||
var messages = this.props.history.map(message => {
|
||||
return (<ChatMessage message={message} key={message.id} />);
|
||||
});
|
||||
}
|
||||
let messages = this.props.history.map(message =>
|
||||
<ChatMessage message={message} key={message.id} />
|
||||
);
|
||||
return (
|
||||
<div className="panel panel-default">
|
||||
<div className="panel-heading">Gather Chat</div>
|
||||
|
@ -60,22 +59,21 @@ var Chatroom = React.createClass({
|
|||
}
|
||||
});
|
||||
|
||||
var updateMessageCallbacks = [];
|
||||
let updateMessageCallbacks = [];
|
||||
|
||||
var timer = setInterval(function () {
|
||||
updateMessageCallbacks.forEach(function (callback) {
|
||||
callback();
|
||||
});
|
||||
let timer = setInterval(() => {
|
||||
updateMessageCallbacks.forEach(callback => callback())
|
||||
}, 60000);
|
||||
|
||||
var ChatMessage = React.createClass({
|
||||
componentDidMount: function () {
|
||||
var self = this;
|
||||
updateMessageCallbacks.push(function () {
|
||||
componentDidMount() {
|
||||
let self = this;
|
||||
updateMessageCallbacks.push(() => {
|
||||
self.forceUpdate();
|
||||
});
|
||||
},
|
||||
render: function () {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<li className="left clearfix">
|
||||
<span className="chat-img pull-left">
|
||||
|
@ -101,20 +99,22 @@ var ChatMessage = React.createClass({
|
|||
});
|
||||
|
||||
var MessageBar = React.createClass({
|
||||
sendMessage: function (content) {
|
||||
sendMessage(content) {
|
||||
socket.emit("message:new", {
|
||||
content: content
|
||||
});
|
||||
},
|
||||
handleSubmit: function (e) {
|
||||
|
||||
handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
var content = React.findDOMNode(this.refs.content).value.trim();
|
||||
let content = React.findDOMNode(this.refs.content).value.trim();
|
||||
if (!content) return;
|
||||
React.findDOMNode(this.refs.content).value = '';
|
||||
this.sendMessage(content);
|
||||
return;
|
||||
},
|
||||
render: function () {
|
||||
|
||||
render() {
|
||||
return (
|
||||
<form onSubmit={this.handleSubmit} >
|
||||
<div className="input-group">
|
||||
|
@ -136,3 +136,4 @@ var MessageBar = React.createClass({
|
|||
);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -142,3 +142,4 @@ var CurrentUser = React.createClass({
|
|||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -929,8 +929,9 @@ var CompletedGather = React.createClass({
|
|||
|
||||
var socket;
|
||||
|
||||
function initialiseVisibilityMonitoring(socket) {
|
||||
var hidden, visibilityChange;
|
||||
var initialiseVisibilityMonitoring = function initialiseVisibilityMonitoring(socket) {
|
||||
var hidden = undefined,
|
||||
visibilityChange = undefined;
|
||||
if (typeof document.hidden !== "undefined") {
|
||||
// Opera 12.10 and Firefox 18 and later support
|
||||
hidden = "hidden";
|
||||
|
@ -953,9 +954,9 @@ function initialiseVisibilityMonitoring(socket) {
|
|||
socket.emit("users:online");
|
||||
}
|
||||
}, false);
|
||||
}
|
||||
};
|
||||
|
||||
function initialiseComponents() {
|
||||
var initialiseComponents = function initialiseComponents() {
|
||||
var socketUrl = window.location.protocol + "//" + window.location.host;
|
||||
socket = io(socketUrl).on("connect", function () {
|
||||
console.log("Connected");
|
||||
|
@ -985,9 +986,9 @@ var Chatroom = React.createClass({
|
|||
history: []
|
||||
};
|
||||
},
|
||||
|
||||
componentDidMount: function componentDidMount() {
|
||||
var self = this;
|
||||
var TIMER_INTERVAL = 5000; // Every minute
|
||||
|
||||
socket.on("message:new", function (data) {
|
||||
var history = self.props.history;
|
||||
|
@ -1007,27 +1008,20 @@ var Chatroom = React.createClass({
|
|||
});
|
||||
|
||||
socket.emit("message:refresh", {});
|
||||
|
||||
self.timer = setInterval(function () {
|
||||
self.forceUpdate();
|
||||
}, TIMER_INTERVAL);
|
||||
},
|
||||
|
||||
componentDidUnmount: function componentDidUnmount() {
|
||||
clearInterval(this.timer);
|
||||
},
|
||||
sendMessage: function sendMessage(message) {
|
||||
socket.emit("newMessage", { message: message });
|
||||
},
|
||||
|
||||
scrollToBottom: function scrollToBottom() {
|
||||
var node = React.findDOMNode(this.refs.messageContainer);
|
||||
node.scrollTop = node.scrollHeight;
|
||||
},
|
||||
|
||||
render: function render() {
|
||||
var messages = this.props.history.map(function (message) {
|
||||
return React.createElement(ChatMessage, {
|
||||
message: message,
|
||||
key: message.id });
|
||||
return React.createElement(ChatMessage, { message: message, key: message.id });
|
||||
});
|
||||
return React.createElement(
|
||||
"div",
|
||||
|
@ -1059,7 +1053,7 @@ var updateMessageCallbacks = [];
|
|||
|
||||
var timer = setInterval(function () {
|
||||
updateMessageCallbacks.forEach(function (callback) {
|
||||
callback();
|
||||
return callback();
|
||||
});
|
||||
}, 60000);
|
||||
|
||||
|
@ -1072,6 +1066,7 @@ var ChatMessage = React.createClass({
|
|||
self.forceUpdate();
|
||||
});
|
||||
},
|
||||
|
||||
render: function render() {
|
||||
return React.createElement(
|
||||
"li",
|
||||
|
@ -1123,6 +1118,7 @@ var MessageBar = React.createClass({
|
|||
content: content
|
||||
});
|
||||
},
|
||||
|
||||
handleSubmit: function handleSubmit(e) {
|
||||
e.preventDefault();
|
||||
var content = React.findDOMNode(this.refs.content).value.trim();
|
||||
|
@ -1131,6 +1127,7 @@ var MessageBar = React.createClass({
|
|||
this.sendMessage(content);
|
||||
return;
|
||||
},
|
||||
|
||||
render: function render() {
|
||||
return React.createElement(
|
||||
"form",
|
||||
|
|
Loading…
Reference in a new issue