Created
July 31, 2012 06:20
-
-
Save adbrowne/3214211 to your computer and use it in GitHub Desktop.
Sample CoffeeScript ViewModel for KnockoutJS
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
class SampleViewModel | |
constructor: (values) -> | |
this.title = ko.observable() | |
this.description = ko.observable() | |
this.isPrivate = ko.observable() | |
this.status = ko.observable "Active" | |
this.showApproveReject = ko.computed => @isActive() | |
this.statusUrl = ko.observable() | |
this.privacyUrl = ko.observable() | |
_.extend(this, Backbone.Events) | |
this.isPrivate.subscribe (newValue) => | |
this.trigger("privacyChanged", newValue) | |
isActive: -> | |
@status() == "Active" | |
approve: -> | |
@trigger("approved") | |
@status("Approved") | |
return false | |
reject: -> | |
@trigger("rejected") | |
@status("Rejected") | |
return false | |
window.app = window.app || {} | |
window.app.SampleViewModel = SampleViewModel |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment