Created
October 29, 2014 17:26
-
-
Save flintinatux/772455da61354ee2f406 to your computer and use it in GitHub Desktop.
Backbone view layer
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 CompositeView extends Backbone.View | |
initialize: (options) -> | |
super(options) | |
@children = _([]) | |
renderChild: (child) -> | |
@children.push child | |
child.parent = this | |
child.render() | |
remove: -> | |
@trigger 'remove' | |
super() | |
@_removeChildren() | |
@_removeFromParent() | |
this | |
swapped: -> | |
@trigger 'swapped' | |
this | |
_removeChild: (child) -> | |
index = @children.indexOf child | |
@children.splice index, 1 | |
_removeChildren: -> | |
_.each @children.clone(), (child) -> | |
child.remove() | |
_removeFromParent: -> | |
@parent._removeChild(this) if @parent | |
module.exports = CompositeView |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment