Building a Chat Web App With Signal R, Part 2: Listing 4
The KnockOutJS personViewModel.
function personViewModel(id, firstName, lastName, email, owner) {
this.id = id;
this.firstName = ko.observable(firstName);
this.lastName = ko.observable(lastName);
this.email = ko.observable(email);
this.removePerson = function () {
owner.deletePerson(this.id)
}
var self = this;
this.firstName.subscribe(function (newValue) {
owner.updatePerson(ko.toJS(self));
});
this.lastName.subscribe(function (newValue) {
owner.updatePerson(ko.toJS(self));
});
this.email.subscribe(function (newValue) {
owner.updatePerson(ko.toJS(self));
});
}
About the Author
Eric Vogel is a Senior Software Developer for Red Cedar Solutions Group in Okemos, Michigan. He is the president of the Greater Lansing User Group for .NET. Eric enjoys learning about software architecture and craftsmanship, and is always looking for ways to create more robust and testable applications. Contact him at [email protected].