Skip to content

Instantly share code, notes, and snippets.

@marcuswestin
Created December 3, 2010 01:01
Show Gist options
  • Save marcuswestin/726413 to your computer and use it in GitHub Desktop.
Save marcuswestin/726413 to your computer and use it in GitHub Desktop.
A chat application written in fun with multiple chat rooms
import Local
import Global
<div class="rooms">
<input data=Local.newRoomName />
<button>"Create new room"</button onclick=handler() {
let newRoom = new { name:Local.newRoomName, messages:[] }
Global.rooms.unshift(newRoom)
Local.newRoomName.set('')
}>
for (room in Global.rooms) {
<div class="room" style={ cursor:'pointer' }>
<div class="name">room.name</div onclick=handler() {
Local.currentRoom.set(room)
}>
</div>
}
</div>
if (Local.currentRoom) {
<div class="currentChatroom">
<div class="messages">
for (message in Local.currentRoom.messages) {
<div class="message">
message
</div>
}
</div>
<input data=Local.messageText /><button>"Send"</button onclick=handler() {
Local.currentRoom.messages.push(Local.messageText)
Local.messageText.set('')
}>
</div>
} else {
"Click on a room to join it"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment