Created
April 12, 2012 22:52
-
-
Save seanhess/2371610 to your computer and use it in GitHub Desktop.
Watchers.coffee
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
define [ | |
'text!views/start/Watchers.html' | |
'views/View' | |
'cs!models/Watchers' | |
'cs!views/start/Watcher' | |
], (template, View, WatchersCollection, Watcher) -> | |
class Watchers extends View | |
template: template | |
initialize: () -> | |
@views = {} | |
@$watchers = @$el.find(".faces") | |
@collection = new WatchersCollection() | |
@collection.on 'add', this.addWatcher, this | |
@collection.on 'remove', this.removeWatcher, this | |
@collection.fetch {add:true} | |
#render: -> @template.update(@watchers.toJSON()) | |
addWatcher: (w) -> | |
view = new Watcher(w) | |
@$watchers.append view.$el | |
@views[w.id] = view | |
removeWatcher: (w) -> | |
view = @views[w.id] | |
view.$el.remove() | |
view.destroy() |
Author
seanhess
commented
Apr 13, 2012
via email
Cool. I didn't know you could use the fat arrows on class functions like that. I've only used them on nested ones.
Thanks!
…On Apr 12, 2012, at 9:36 PM, Ryan ***@***.*** wrote:
Since you're using coffeescript's class syntax, you can write less code and use some fat arrows for your event handlers :)
``` coffee
class Watchers extends View
template: template
initialize: () ->
@collection.on 'add', @addWatcher
@collection.on 'remove', @removeWatcher
addWatcher: (w) =>
removeWatcher: (w) =>
```
---
Reply to this email directly or view it on GitHub:
https://gist.github.com/2371610
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment