Skip to content
Browse files

Merge branch 'master' of github.com:developmentseed/bones

  • Loading branch information...
2 parents d98256b + 76143f3 commit 2b0c2121d9b806e206a6c1d93610cd993d795335 @miccolis miccolis committed Sep 16, 2011
Showing with 18 additions and 0 deletions.
  1. +18 −0 shared/utils.js
View
18 shared/utils.js
@@ -12,6 +12,24 @@ Bones.utils.callback = function(callback) {
};
};
+// Multifetch. Pass a hash of models and fetch each in parallel.
+Bones.utils.fetch = function(models, callback) {
+ var remaining = _(models).size();
+ var error = null;
+ _(models).each(function(model) {
+ model.fetch({
+ success: function() {
+ if (--remaining === 0) callback(error, models);
+ },
+ error: function(m, err) {
+ if (!error) error = err;
+ model.error = err;
+ if (--remaining === 0) callback(error, models);
+ }
+ });
+ });
+};
+
// From https://github.com/visionmedia/lingo/blob/master/lib/languages/en.js
Bones.utils.uncountable = [ 'advice', 'enegery', 'excretion', 'digestion',
'cooperation', 'health', 'justice', 'jeans', 'labour', 'machinery',

0 comments on commit 2b0c212

Please sign in to comment.
Something went wrong with that request. Please try again.