backbone-child-collections
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -0,1 +1,3 @@ | ||
var async = require('async'); | ||
module.exports = function(Backbone) { | ||
@@ -9,19 +11,27 @@ | ||
Backbone.Model.prototype.recursiveFetch = function() { | ||
if (!this._child_collections) return; | ||
this._child_collections.forEach(function(collection){ | ||
collection.recursiveFetch(); | ||
}); | ||
Backbone.Model.prototype.visitDepthFirst = function(visitor, done) { | ||
if (!this._child_collections) return done(); | ||
async.each(Array.from(this._child_collections), function(collection, callback){ | ||
collection.visitDepthFirst(visitor, callback); | ||
}, done); | ||
}; | ||
Backbone.Collection.prototype.recursiveFetch = function() { | ||
this.fetch({ | ||
success: function() { | ||
this.each(function(m) { | ||
m.recursiveFetch(); | ||
}); | ||
}.bind(this) | ||
}); | ||
Backbone.Collection.prototype.visitDepthFirst = function(visitor, done) { | ||
visitor(this, function(err){ | ||
if (err) return done(err); | ||
async.each(this, function(model, callback){ | ||
model.visitDepthFirst(visitor, callback); | ||
}, done); | ||
}.bind(this)); | ||
}; | ||
Backbone.Model.prototype.recursiveFetch = | ||
Backbone.Collection.prototype.recursiveFetch = function(done) { | ||
this.visitDepthFirst(function(collection, callback){ | ||
collection.fetch({ | ||
success: function() { callback(); }, | ||
error: function() { callback(new Error('fetch failed')); } | ||
}); | ||
}, done); | ||
}; | ||
}; |
{ | ||
"name": "backbone-child-collections", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "Plugin to allow tracking of child collections on models, and recursive fetching of model/collection trees", | ||
@@ -18,3 +18,6 @@ "main": "backbone.childCollections.js", | ||
}, | ||
"homepage": "https://github.com/Coggle/backbone-child-collections#readme" | ||
"homepage": "https://github.com/Coggle/backbone-child-collections#readme", | ||
"dependencies": { | ||
"async": "^1.5.2" | ||
} | ||
} |
2172
31
1
+ Addedasync@^1.5.2
+ Addedasync@1.5.2(transitive)