Backbone.mixins = Backbone.mixins || {};

(function(mixins){

    var EVENT_DISPOSE = 'onDispose',
        FUNC_DISPOSE = 'dispose';

	mixins.DisposableTreeNode = {

        initialize: function(){

            // children to be accessed by cid
            this._children = {};

            // separate storage of cids in the order in which they were added to guarantee order
            this._orderedChildIds = [];

        },

        // helper isOfType bool
		isDisposableTreeNode: true,

		hasChildren: function(){
			return _(this._children).isEmpty();
		},

        children: function(){
            return _.map(this._orderedChildIds, function(id){
                return this._children[id];
            }, this);
        },


        /**
         * internal version of add child that expects an already
         * constructed child storage object
         * @private
         * @param childStorage see format above
         */
        addChild: function(child){

            var id = child.cid || _.identity(child);

            this._children[id] = child;
            this._orderedChildIds.push(id);
        },


        /**
         * @param children may be an array
         * or as a list of arguments, making the only invalid
         * class to use this mixin with (you guessed it!) Array.
         * limitation: accepted
         *
         * expects children as formatted in the comments above
         */
		addChildren: function(children){

			children = _.isArray(children)
				? children
				: Array.prototype.slice.call(arguments);

			_(children).each(function(child){
				this.addChild(child);
			}, this);

		},

        /**
         *
         * @param id
         */
        getChild: function(id){
            return this._children[id];
        },


        /**
         * calls dispose on its children and then
         * its own dispose handler
         */
		dispose: function () {

			var __this = _(this);

			this.disposeChildren();

			__this.result(EVENT_DISPOSE);
		},

        /**
         * disposes of a particular child by its identifier
         * @param childId
         */
        disposeChild: function(childId){
            _(this._children[childId])
                .result(FUNC_DISPOSE);

            delete this._children[childId];
            this._orderedChildIds = _.without(this._orderedChildIds, childId);
        },


		disposeChildren: function(){
			_(this._children).each(function(child){
				_(child).result(FUNC_DISPOSE);
			});
			this._children = {};
			this._orderedChildIds = [];
		}
	};

})(Backbone.mixins);
@@ -127,17 +127,20 @@
 pose';%0A%0A
-%09
+    
 mixins.D
@@ -457,18 +457,24 @@
 pe bool%0A
-%09%09
+        
 isDispos
@@ -494,18 +494,24 @@
  true,%0A%0A
-%09%09
+        
 hasChild
@@ -527,19 +527,28 @@
 tion()%7B%0A
-%09%09%09
+            
 return _
@@ -575,18 +575,24 @@
 mpty();%0A
-%09%09
+        
 %7D,%0A%0A    
@@ -1445,18 +1445,24 @@
      */%0A
-%09%09
+        
 addChild
@@ -1487,19 +1487,28 @@
 dren)%7B%0A%0A
-%09%09%09
+            
 children
@@ -1534,27 +1534,51 @@
 en)%0A
-%09%09%09%09? children%0A%09%09%09%09
+                ? children%0A                
 : Ar
@@ -1615,19 +1615,28 @@
 ents);%0A%0A
-%09%09%09
+            
 _(childr
@@ -1661,20 +1661,32 @@
 child)%7B%0A
-%09%09%09%09
+                
 this.add
@@ -1699,19 +1699,28 @@
 child);%0A
-%09%09%09
+            
 %7D, this)
@@ -1722,18 +1722,24 @@
 this);%0A%0A
-%09%09
+        
 %7D,%0A%0A    
@@ -1865,33 +1865,32 @@
 d%5D;%0A        %7D,%0A%0A
-%0A
         /**%0A    
@@ -1982,18 +1982,24 @@
      */%0A
-%09%09
+        
 dispose:
@@ -2014,19 +2014,28 @@
 n () %7B%0A%0A
-%09%09%09
+            
 var __th
@@ -2049,19 +2049,28 @@
 this);%0A%0A
-%09%09%09
+            
 this.dis
@@ -2086,19 +2086,28 @@
 ren();%0A%0A
-%09%09%09
+            
 __this.r
@@ -2128,18 +2128,25 @@
 SPOSE);%0A
-%09%09
+%0A        
 %7D,%0A%0A    
@@ -2506,19 +2506,24 @@
     %7D,%0A%0A
-%0A%09%09
+        
 disposeC
@@ -2543,19 +2543,28 @@
 tion()%7B%0A
-%09%09%09
+            
 _(this._
@@ -2634,18 +2634,36 @@
 E);%0A
-%09%09%09%7D);%0A%09%09%09
+            %7D);%0A            
 this
@@ -2679,19 +2679,28 @@
 n = %7B%7D;%0A
-%09%09%09
+            
 this._or
@@ -2723,13 +2723,22 @@
 %5B%5D;%0A
-%09%09%7D%0A%09
+        %7D%0A    
 %7D;%0A%0A

space is the place