Skip to content

Instantly share code, notes, and snippets.

@sharshenov
Last active January 3, 2016 02:39
Show Gist options
  • Save sharshenov/8397474 to your computer and use it in GitHub Desktop.
Save sharshenov/8397474 to your computer and use it in GitHub Desktop.
chain: function() {
collection.fetch()
whenFetched(collection,function() {
...
another_collection.fetch()
whenFetched(another_collection,function() {
...
});
);
},
tree: function() {
collection.fetch()
whenFetched(collection,function() {
subordinate_collection2.fetch()
whenFetched(subordinate_collection2,function() {
...
});
subordinate_collection1.fetch()
whenFetched(subordinate_collection1,function() {
...
});
};
},
whenFetched: function(collection, callback) {
$.when(_.chain([collection]).flatten().pluck("_fetch").value()).done function(){
callback();
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment