This commit is contained in:
Gabe Kangas
2020-05-23 17:57:49 -07:00
commit cc48f86b85
84 changed files with 1978 additions and 0 deletions

View File

@@ -0,0 +1,25 @@
define(
"Message",
[],
function() {
function Message(model) {
if (model !== undefined) {
this.author = ko.observable(model.author);
this.body = ko.observable(model.body);
} else {
this.author = ko.observable("Anonymous");
this.body = ko.observable("");
}
this.toModel = function() {
return {
author: this.author(),
body: this.body()
};
}
}
return Message;
}
);

View File

@@ -0,0 +1,31 @@
define(
"MessageList",
[
"Message"
],
function(Message) {
function MessageList(ws) {
var that = this;
this.messages = ko.observableArray();
this.editingMessage = ko.observable(new Message());
this.send = function() {
var model = this.editingMessage().toModel();
ws.send($.toJSON(model));
var message = new Message();
message.author(model.author);
this.editingMessage(message);
};
ws.onmessage = function(e) {
var model = $.evalJSON(e.data);
var msg = new Message(model);
that.messages.push(msg);
};
}
return MessageList;
}
);

View File

@@ -0,0 +1,11 @@
define(
"main",
[
"MessageList"
],
function(MessageList) {
var ws = new WebSocket("ws://localhost:8080/entry");
var list = new MessageList(ws);
ko.applyBindings(list);
}
);