Skip to content

Instantly share code, notes, and snippets.

@vgheri
Created July 23, 2012 11:49
Show Gist options
  • Save vgheri/3163223 to your computer and use it in GitHub Desktop.
Save vgheri/3163223 to your computer and use it in GitHub Desktop.
ChatR namespace and ViewModels
/*
* Author: Valerio Gheri
* Date: 22/07/2012
* Description: ChatR namespace js file and viewmodels declaration
*/
// Namespace
var chatR = {};
// Models
chatR.chatMessage = function (sender, content, dateSent) {
var self = this;
self.username = sender;
self.content = content;
if (dateSent != null) {
self.timestamp = dateSent;
}
}
chatR.user = function (username, connectionId) {
var self = this;
self.username = username;
self.id = connectionId;
}
// ViewModels
chatR.chatViewModel = function () {
var self = this;
self.messages = ko.observableArray();
}
chatR.connectedUsersViewModel = function () {
var self = this;
self.contacts = ko.observableArray();
self.customRemove = function (userToRemove) {
var userIdToRemove = userToRemove.id;
self.contacts.remove(function (item) {
return item.id === userIdToRemove;
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment