Deferred Support for AmplifyJs

amplify Mar 11, 2013

Working with AmplifyJs has been great, It reduces a lot caching headaches, We are using amplifyjs in conjunction with Durandal, and durandal uses jQuery deffereds and the logical step would be to have amplify requests to be deffereds,
As Amplifyjs was built with the intention of not having jQuery as a Dependency, the deferred support is not included out of the box, but to introduce that is very simple,

Put this in before the making a request and you are good to go

(function (amplify, $, undefined) {
	var properties = [ "types", "resources", "define", "decoders" ];
	amplify.request_original = amplify.request;
	amplify.request = function(resourceId, data) {
		var dfd = $.Deferred();

			resourceId: resourceId,
			data: data,
			success: dfd.resolve,
			error: dfd.reject

		return dfd.promise();

	$.each( properties, function( index, key ) {
		amplify.request[ key ] = amplify.request_original[ key ];

and you can make request like

 ).then(function(response1, response2) {
     //do Something with

Source :