Created
June 26, 2011 13:37
-
-
Save colwilson/1047624 to your computer and use it in GitHub Desktop.
simple backbone with coffeescript
This file contains hidden or 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
window.app = {} | |
app.controllers = {} | |
app.models = {} | |
app.views = {} | |
class window.MainController extends Backbone.Controller | |
routes : | |
"": "home" | |
"home": "home" | |
home: -> | |
app.views.counter.render() | |
class window.Counter extends Backbone.Model | |
defaults: | |
count: 0 | |
class window.CounterView extends Backbone.View | |
initialize: -> | |
@counter = new Counter() | |
@render() | |
el: $('#counter') | |
events: | |
'click button#inc-count' : 'inc' | |
'click button#dec-count' : 'dec' | |
render: -> | |
$(@el).find("#count").html "The count is " \ | |
+ @counter.get("count") | |
@ | |
inc: -> | |
ct = @counter.get("count") | |
@counter.set(count: ct+1) | |
@render() | |
dec: -> | |
ct = @counter.get("count") | |
@counter.set(count: ct-1) | |
@render() | |
head.ready -> | |
app.controllers.main = new MainController() | |
app.views.counter = new CounterView() | |
app.models.counter = new Counter() | |
Backbone.history.start() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment