mirror of
https://github.com/jashkenas/backbone.git
synced 2026-04-30 03:00:06 -04:00
Revert non-model sync commits.
Revert "Allow non-model object as second argument, with test." This reverts commit32743e6b60. Revert "trigger request event only if model extends Backbone.Events, and fix whitespace" This reverts commit6d72e1be35. Revert "add if statement and add passing test" This reverts commit2caf748651.
This commit is contained in:
@@ -1144,9 +1144,8 @@
|
||||
|
||||
// Ensure that we have the appropriate request data.
|
||||
if (options.data == null && model && (method === 'create' || method === 'update' || method === 'patch')) {
|
||||
var attrs = options.attrs || (_.isFunction(model.toJSON) ? model.toJSON(options) : model);
|
||||
params.data = JSON.stringify(attrs);
|
||||
params.contentType = 'application/json';
|
||||
params.data = JSON.stringify(options.attrs || model.toJSON(options));
|
||||
}
|
||||
|
||||
// For older servers, emulate JSON by encoding the request into an HTML-form.
|
||||
@@ -1184,10 +1183,7 @@
|
||||
|
||||
// Make the request, allowing the user to override any Ajax options.
|
||||
var xhr = options.xhr = Backbone.ajax(_.extend(params, options));
|
||||
|
||||
// Only trigger a "request" event if the second argument is a model or collection.
|
||||
if (model && model.trigger === Events.trigger) model.trigger('request', model, xhr, options);
|
||||
|
||||
model.trigger('request', model, xhr, options);
|
||||
return xhr;
|
||||
};
|
||||
|
||||
|
||||
11
test/sync.js
11
test/sync.js
@@ -209,15 +209,4 @@ $(document).ready(function() {
|
||||
strictEqual(this.ajaxSettings.beforeSend(xhr), false);
|
||||
});
|
||||
|
||||
test("#2494 - Backbone.sync allows for non model/collection in second argument", 6, function() {
|
||||
Backbone.sync('read', {}, {url : '/someurl'});
|
||||
equal(this.ajaxSettings.url, '/someurl');
|
||||
equal(this.ajaxSettings.type, 'GET');
|
||||
equal(this.ajaxSettings.dataType, 'json');
|
||||
Backbone.sync('create', {item: 'test'}, {url: '/test-url'});
|
||||
equal(this.ajaxSettings.url, '/test-url');
|
||||
equal(this.ajaxSettings.type, 'POST');
|
||||
equal(this.ajaxSettings.data, '{"item":"test"}');
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user