Permalink
Browse files

add multifetch method

  • Loading branch information...
1 parent eeb94ad commit 42f4fd2860084443c883bd416ed6eea3e41b910a @kkaefer kkaefer committed Sep 16, 2011
Showing with 18 additions and 0 deletions.
  1. +18 −0 shared/utils.js
View
@@ -12,6 +12,24 @@ Bones.utils.callback = function(callback) {
};
};
+// Multifetch. Pass a hash of models and fetch each in parallel.
+Bones.utils.fetch(models, callback) {
+ var remaining = _(models).size();
+ var error = null;
+ _(models).each(function(model) {
+ model.fetch({
+ success: function() {
+ if (--remaining === 0) callback(err, models);
+ },
+ error: function(m, err) {
+ if (!error) error = err;
+ model.error = err;
+ if (--remaining === 0) callback(err, 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 42f4fd2

Please sign in to comment.