Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A somewhat smarter approach (more DRY).
  • Loading branch information
PaulUithol committed Mar 22, 2011
1 parent ed5a88d commit 8f80fb1
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions backbone.js
Expand Up @@ -267,8 +267,7 @@
if (success) success(model, resp);
};
options.error = wrapError(options.error, model, options);
var request = (this.sync || Backbone.sync).call(this, 'read', this, options);
this.promise = _.isFunction( request.promise ) ? request.promise() : request;
this.promise = (this.sync || Backbone.sync).call(this, 'read', this, options);
return this;
},

Expand All @@ -286,8 +285,7 @@
};
options.error = wrapError(options.error, model, options);
var method = this.isNew() ? 'create' : 'update';
var request = (this.sync || Backbone.sync).call(this, method, this, options);
this.promise = _.isFunction( request.promise ) ? request.promise() : request;
this.promise = (this.sync || Backbone.sync).call(this, method, this, options);
return this;
},

Expand All @@ -302,8 +300,7 @@
if (success) success(model, resp);
};
options.error = wrapError(options.error, model, options);
var request = (this.sync || Backbone.sync).call(this, 'delete', this, options);
this.promise = _.isFunction( request.promise ) ? request.promise() : request;
this.promise = (this.sync || Backbone.sync).call(this, 'delete', this, options);
return this;
},

Expand Down Expand Up @@ -516,8 +513,7 @@
if (success) success(collection, resp);
};
options.error = wrapError(options.error, collection, options);
var request = (this.sync || Backbone.sync).call(this, 'read', this, options);
this.promise = _.isFunction( request.promise ) ? request.promise() : request;
this.promise = (this.sync || Backbone.sync).call(this, 'read', this, options);
return this;
},

Expand All @@ -538,7 +534,6 @@
coll.add(nextModel);
if (success) success(nextModel, resp);
};
this.promise = model.promise;
return model.save(null, options);
},

Expand Down Expand Up @@ -1017,7 +1012,8 @@
}

// Make the request.
return $.ajax(params);
var request = $.ajax(params);
return _.isFunction( request.promise ) ? request.promise() : request;
};

// Helpers
Expand Down

0 comments on commit 8f80fb1

Please sign in to comment.