Created
November 13, 2011 14:09
-
-
Save dagda1/1362143 to your computer and use it in GitHub Desktop.
baseview.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
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() | |
@views = [] | |
}) | |
@.BaseView = BaseView | |
@.BaseView.extend = Backbone.View.extend |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment