Permalink
Browse files

Merge pull request #4 from taskrabbit/container-removes-all-children

Adding a removeChildren method
  • Loading branch information...
robrobbins committed Apr 2, 2013
2 parents 428ad37 + 395a50b commit cf66641e1f10299c6618a0014171199550848ec5
Showing with 31 additions and 0 deletions.
  1. +12 −0 build/debug/sudo-x.js
  2. +12 −0 container/container.js
  3. +7 −0 container/spec/container.spec.js
View
@@ -423,6 +423,18 @@ sudo.Container.prototype.removeChild = function removeChild(arg) {
this._indexChildren_(i);
return this;
};
+
+// ###removeChildren
+// Remove all children, removing the name references and index
+// This method calls removeFromParent on each child. If it's a DataView also removes the child's DOM.
+// `returns` {Object} `this`
+sudo.Container.prototype.removeChildren = function removeChildren(arg) {
+ while(this.children.length) {
+ this.children.shift().removeFromParent();
+ }
+ return this;
+};
+
// ###removeFromParent
// Remove this object from its parents list of children.
// Does not alter the dom - do that yourself by overriding this method
View
@@ -86,6 +86,18 @@ sudo.Container.prototype.removeChild = function removeChild(arg) {
this._indexChildren_(i);
return this;
};
+
+// ###removeChildren
+// Remove all children, removing the name references and index
+// This method calls removeFromParent on each child. If it's a DataView also removes the child's DOM.
+// `returns` {Object} `this`
+sudo.Container.prototype.removeChildren = function removeChildren(arg) {
+ while(this.children.length) {
+ this.children.shift().removeFromParent();
+ }
+ return this;
+};
+
// ###removeFromParent
// Remove this object from its parents list of children.
// Does not alter the dom - do that yourself by overriding this method
@@ -45,6 +45,13 @@ describe('Sudo Container Class', function() {
expect(c.length).toBe(0);
});
+ it('Removes all children', function() {
+ container.addChild(child1, 'Galahad').addChild(child2, 'Robin');
+ expect(container.children.length).toBe(2);
+ container.removeChildren();
+ expect(container.children.length).toBe(0);
+ });
+
it('Indexes children correctly, maintaining when adjusted', function() {
container.addChild(child1, 'Galahad').addChild(child2, 'Robin');
expect(child1.index).toBe(0);

0 comments on commit cf66641

Please sign in to comment.