Skip to content

Instantly share code, notes, and snippets.

@seanhess
Created April 12, 2012 22:52
Show Gist options
  • Save seanhess/2371610 to your computer and use it in GitHub Desktop.
Save seanhess/2371610 to your computer and use it in GitHub Desktop.
Watchers.coffee
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()
@ryanflorence
Copy link

Since you're using coffeescript's class syntax, you can write less code and use some fat arrows for your event handlers :)

class Watchers extends View
    template: template
    initialize: () ->
      @collection.on 'add', @addWatcher
      @collection.on 'remove', @removeWatcher

    addWatcher: (w) =>

    removeWatcher: (w) =>

@seanhess
Copy link
Author

seanhess commented Apr 13, 2012 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment