[Pkg-javascript-commits] [backbone] 44/211: Issue #154. Make options.data possible for creates and updates with the default sync.

Jonas Smedegaard js at moszumanska.debian.org
Sat May 3 17:00:00 UTC 2014


This is an automated email from the git hooks/post-receive script.

js pushed a commit to tag 0.5.0
in repository backbone.

commit 4c1bdb46a8aeba6a6fc9803614b074dbca2ec050
Author: Jeremy Ashkenas <jashkenas at gmail.com>
Date:   Thu Dec 30 12:28:55 2010 -0500

    Issue #154. Make options.data possible for creates and updates with the default sync.
---
 backbone.js | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/backbone.js b/backbone.js
index cdbc86d..356405b 100644
--- a/backbone.js
+++ b/backbone.js
@@ -941,20 +941,24 @@
   // it difficult to read the body of `PUT` requests.
   Backbone.sync = function(method, model, options) {
     var type = methodMap[method];
-    var modelJSON = (method === 'create' || method === 'update') ?
-                    JSON.stringify(model.toJSON()) : null;
 
     // Default JSON-request options.
     var params = _.extend({
       type:         type,
       contentType:  'application/json',
-      data:         modelJSON,
       dataType:     'json',
       processData:  false
     }, options);
 
     // Ensure that we have a URL.
-    params.url || (params.url = getUrl(model) || urlError());
+    if (!params.url) {
+      params.url = getUrl(model) || urlError();
+    }
+
+    // Ensure that we have the appropriate request data.
+    if (!params.data && model && (method == 'create' || method == 'update')) {
+      params.data = JSON.stringify(model.toJSON());
+    }
 
     // For older servers, emulate JSON by encoding the request into an HTML-form.
     if (Backbone.emulateJSON) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/backbone.git



More information about the Pkg-javascript-commits mailing list