"use strict"; var Chatroom = React.createClass({ getDefaultProps() { return { history: [] }; }, componentDidMount() { let self = this; socket.on("message:new", data => { let history = self.props.history; history.push(data); self.setProps({ history: history }); self.scrollToBottom(); }); // Message History Retrieved socket.on("message:refresh", data => { self.setProps({ history: data.chatHistory }); self.scrollToBottom(); }); socket.emit("message:refresh", {}); }, sendMessage(message) { socket.emit("newMessage", {message: message}); }, scrollToBottom() { let node = React.findDOMNode(this.refs.messageContainer); node.scrollTop = node.scrollHeight; }, render() { let messages = this.props.history.map(message => ); return (
Gather Chat
    {messages}
); } }); let updateMessageCallbacks = []; let timer = setInterval(() => { updateMessageCallbacks.forEach(callback => callback()) }, 60000); var ChatMessage = React.createClass({ componentDidMount() { let self = this; updateMessageCallbacks.push(() => { self.forceUpdate(); }); }, render() { return (
  • User Avatar
    {this.props.message.author.username} {$.timeago(this.props.message.createdAt)}

    {this.props.message.content}

  • ); } }); var MessageBar = React.createClass({ sendMessage(content) { socket.emit("message:new", { content: content }); }, handleSubmit(e) { e.preventDefault(); let content = React.findDOMNode(this.refs.content).value.trim(); if (!content) return; React.findDOMNode(this.refs.content).value = ''; this.sendMessage(content); return; }, render() { return (
    ); } });