Permalink
Browse files

Merge branch 'master' of github.com:taskrabbit/sudojs

  • Loading branch information...
robrobbins committed Apr 22, 2013
2 parents c5cdd69 + d9d29df commit 66930a51cd76b606114ae5a11b17d5a028322db2
View
@@ -2,8 +2,8 @@
## Overview
-High-level, "Model/View" (or "Presentation Model") style object oriented library made to aid you in your quest for Javascript
-awsomeness by assisting with such things as implementing inheritance patterns, handling data-mutation observation,
+High-level, "Model/View" (or "Presentation Model") style object oriented library made to aide you in your quest for Javascript
+awesomeness by assisting with such things as implementing inheritance patterns, handling data-mutation observation,
establishing hierarchies of objects which have intrinsic knowledge of their responsibilies, and the making of sandwiches.
## Documentaion
View
@@ -423,6 +423,19 @@ sudo.Container.prototype.removeChild = function removeChild(arg) {
this._indexChildren_(i);
return this;
};
+
+// ###removeChildren
+// Remove all children, name references and adjust indexes accordingly.
+// This method calls removeFromParent as each child may have overridden logic there.
+//
+// `returns` {object} `this`
+sudo.Container.prototype.removeChildren = function removeChildren() {
+ 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
@@ -440,6 +453,9 @@ sudo.Container.prototype.role = 'container';
// What this does is allow children of a `sudo.Container` to simply pass
// events upward, delegating the responsibility of deciding what to do to the parent.
//
+// TODO Currently, only the first target method found is called, then the
+// bubbling is stopped. Should bubbling continue all the way up the 'chain'?
+//
// `param` {*} Any number of arguments is supported, but the first is the only one searched for info.
// A sendMethod will be located by:
// 1. using the first argument if it is a string
@@ -1574,7 +1590,7 @@ sudo.extensions.persistable = {
//
// `returns` {object} A normalized params object for the XHR call
_normalizeParams_: function _normalizeParams_(meth, opts, params) {
- opts || (opts = this.data.ajax);
+ opts || (opts = $.extend({}, this.data.ajax));
opts.url || (opts.url = this.url(opts.baseUrl));
opts.type || (opts.type = meth);
opts.dataType || (opts.dataType = 'json');
@@ -1617,7 +1633,7 @@ sudo.extensions.persistable = {
//
// `returns` {object} jqXhr
_sendData_: function _sendData_(meth, params) {
- opts = this.data.ajax;
+ opts = $.extend({}, this.data.ajax);
opts.contentType || (opts.contentType = 'application/json');
opts.data || (opts.data = this.data);
// non GET requests do not 'processData'
View
@@ -86,6 +86,19 @@ sudo.Container.prototype.removeChild = function removeChild(arg) {
this._indexChildren_(i);
return this;
};
+
+// ###removeChildren
+// Remove all children, name references and adjust indexes accordingly.
+// This method calls removeFromParent as each child may have overridden logic there.
+//
+// `returns` {object} `this`
+sudo.Container.prototype.removeChildren = function removeChildren() {
+ 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
@@ -103,6 +116,9 @@ sudo.Container.prototype.role = 'container';
// What this does is allow children of a `sudo.Container` to simply pass
// events upward, delegating the responsibility of deciding what to do to the parent.
//
+// TODO Currently, only the first target method found is called, then the
+// bubbling is stopped. Should bubbling continue all the way up the 'chain'?
+//
// `param` {*} Any number of arguments is supported, but the first is the only one searched for info.
// A sendMethod will be located by:
// 1. using the first argument if it is a string
@@ -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);
Oops, something went wrong.

0 comments on commit 66930a5

Please sign in to comment.