Skip to content

Instantly share code, notes, and snippets.

@dagda1
Created October 31, 2011 10:54
Show Gist options
  • Save dagda1/1327277 to your computer and use it in GitHub Desktop.
Save dagda1/1327277 to your computer and use it in GitHub Desktop.
baseview.coffee
class BaseView
constructor: (options) ->
@bindings = []
Backbone.View.apply(@, [options])
_.extend(BaseView.prototype, Backbone.View.prototype, {
bindTo: (model, ev, callback) ->
model.bind(ev, callback, @)
@bindings.push({model: model, ev: ev, callback: callback})
unbindFromAll: ->
_.each(@bindings, (binding) ->
binding.model.unbind(binding.ev, binding.callback)
)
@bindings = []
dispose: ->
@disposeViews()
@unbindFromAll()
@unbind()
@remove()
renderView: (el, func, view) ->
$.fn[func].call(el, view.render().el)
@views ||= []
@views.push view
disposeViews: ->
if @views
_(@views).each (view) ->
view.dispose()
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment