Skip to content

Commit

Permalink
Merge pull request #2 from teleportd/batch
Browse files Browse the repository at this point in the history
Please review: [Add batch function]
  • Loading branch information
MOI Anthony committed Oct 1, 2012
2 parents ac10870 + 6354d76 commit 72e9b89
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
5 changes: 3 additions & 2 deletions cell-0.3.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions src/container.js
Expand Up @@ -60,6 +60,7 @@ CELL.container = function(spec, my) {
// protected
var load; /* load(); */
var refresh; /* refresh(); */
var batch; /* batch(fn, params); */


var that = CELL.emitter({});
Expand Down Expand Up @@ -106,11 +107,34 @@ CELL.container = function(spec, my) {
throw new Error('`load` must be implemented : ' + my.path);
};

/**
* Calls the given function for every children.
* @param fn can be a string representing the function name
* or a function(child, params)
* @param params
*/
batch = function() {
var args = Array.prototype.slice.call(arguments);
var fn = args.shift();

for(var c in my.children) {
if(my.children.hasOwnProperty(c)) {
if(typeof fn === 'string' && typeof my.children[c][fn] === 'function') {
my.children[c][fn].apply(this, args);
}
else if(typeof fn === 'function') {
var child_args = [ my.children[c] ].concat(args);
fn.apply(this, child_args);
}
}
}
};


CELL.method(that, 'load', load, _super);
CELL.method(that, 'refresh', refresh, _super);
CELL.method(that, 'find', find, _super);
CELL.method(that, 'batch', batch, _super);

CELL.getter(that, 'children', my, 'children');
CELL.getter(that, 'name', my, 'name');
Expand Down

0 comments on commit 72e9b89

Please sign in to comment.