Permalink
Browse files

Remove a bit of duplication in 'Backbone.Collection.prototype.url'

  • Loading branch information...
1 parent 7359271 commit 6402fe5e6daf61fce1538f9c78493f100c378310 @PaulUithol PaulUithol committed Jul 15, 2011
Showing with 4 additions and 8 deletions.
  1. +4 −8 backbone-tastypie.js
View
@@ -68,21 +68,17 @@
};
Backbone.Collection.prototype.url = function( models ) {
+ var url = this.urlRoot || ( models && models.length && models[0].urlRoot );
+ url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
+
// Build a url to retrieve a set of models. This assume the last part of each model's idAttribute
// (set to 'resource_uri') contains the model's id.
if ( models && models.length ) {
- var root = this.urlRoot || models[0].urlRoot;
- root && ( root += ( root.length > 0 && root.charAt( root.length - 1 ) === '/' ) ? '' : '/' );
-
var ids = _.map( models, function( model ) {
var parts = _.compact( model.id.split('/') );
return parts[ parts.length - 1 ];
});
- var url = root + 'set/' + ids.join(';') + '/';
- }
- else {
- var url = this.urlRoot;
- url && ( url += ( url.length > 0 && url.charAt( url.length - 1 ) === '/' ) ? '' : '/' );
+ url += 'set/' + ids.join(';') + '/';
}
return url;

0 comments on commit 6402fe5

Please sign in to comment.