Created
July 23, 2012 11:49
-
-
Save vgheri/3163223 to your computer and use it in GitHub Desktop.
ChatR namespace and ViewModels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* 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