[Pkg-javascript-commits] [backbone] 97/211: Make it possible to take advantage of jQuery.Deferred with Backbone, without breaking compatibility by changing return values.
Jonas Smedegaard
js at moszumanska.debian.org
Sat May 3 17:00:08 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 ed5a88d4457079a0b91411b1fc2ee14bef4283b9
Author: Paul Uithol <paul.uithol at gmail.com>
Date: Tue Mar 22 17:35:05 2011 +0100
Make it possible to take advantage of jQuery.Deferred with Backbone, without breaking compatibility by changing return values.
Implemented by adding a "promise" attribute to Backbone.Model and Backbone.Collection, set by Backbone.Model's "fetch", "save", "destroy" and Backbone.Collectin's "fetch" and "create".
---
backbone.js | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
diff --git a/backbone.js b/backbone.js
index e0c5fed..63b8e43 100644
--- a/backbone.js
+++ b/backbone.js
@@ -145,6 +145,9 @@
// CouchDB users may want to set this to `"_id"`.
idAttribute : 'id',
+ // A jQuery promise object (set on 'fetch', 'save' and 'destroy')
+ promise: null,
+
// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize : function(){},
@@ -264,7 +267,8 @@
if (success) success(model, resp);
};
options.error = wrapError(options.error, model, options);
- (this.sync || Backbone.sync).call(this, 'read', this, options);
+ var request = (this.sync || Backbone.sync).call(this, 'read', this, options);
+ this.promise = _.isFunction( request.promise ) ? request.promise() : request;
return this;
},
@@ -282,7 +286,8 @@
};
options.error = wrapError(options.error, model, options);
var method = this.isNew() ? 'create' : 'update';
- (this.sync || Backbone.sync).call(this, method, this, options);
+ var request = (this.sync || Backbone.sync).call(this, method, this, options);
+ this.promise = _.isFunction( request.promise ) ? request.promise() : request;
return this;
},
@@ -297,7 +302,8 @@
if (success) success(model, resp);
};
options.error = wrapError(options.error, model, options);
- (this.sync || Backbone.sync).call(this, 'delete', this, options);
+ var request = (this.sync || Backbone.sync).call(this, 'delete', this, options);
+ this.promise = _.isFunction( request.promise ) ? request.promise() : request;
return this;
},
@@ -415,6 +421,9 @@
// This should be overridden in most cases.
model : Backbone.Model,
+ // A jQuery promise object (set on 'fetch')
+ promise: null,
+
// Initialize is an empty function by default. Override it with your own
// initialization logic.
initialize : function(){},
@@ -507,7 +516,8 @@
if (success) success(collection, resp);
};
options.error = wrapError(options.error, collection, options);
- (this.sync || Backbone.sync).call(this, 'read', this, options);
+ var request = (this.sync || Backbone.sync).call(this, 'read', this, options);
+ this.promise = _.isFunction( request.promise ) ? request.promise() : request;
return this;
},
@@ -528,6 +538,7 @@
coll.add(nextModel);
if (success) success(nextModel, resp);
};
+ this.promise = model.promise;
return model.save(null, options);
},
@@ -1006,7 +1017,7 @@
}
// Make the request.
- $.ajax(params);
+ return $.ajax(params);
};
// Helpers
--
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