[extensions-web] review: Use Deferred.pipe



commit 0836a0b98ddf86104662b2ef5c08456c27326710
Author: Jasper St. Pierre <jstpierre mecheye net>
Date:   Tue Feb 7 14:04:41 2012 -0500

    review: Use Deferred.pipe
    
    This is a shorter way of accomplishing the callback chaining

 sweettooth/static/js/review.js |   20 ++++++--------------
 1 files changed, 6 insertions(+), 14 deletions(-)
---
diff --git a/sweettooth/static/js/review.js b/sweettooth/static/js/review.js
index 0d14134..7688aba 100644
--- a/sweettooth/static/js/review.js
+++ b/sweettooth/static/js/review.js
@@ -31,33 +31,25 @@ define(['jquery', 'diff'], function($, diff) {
     }
 
     function createDiffView(filename, pk) {
-        var req = $.ajax({
+        return $.ajax({
             type: 'GET',
             dataType: 'json',
             data: { filename: filename },
             url: REVIEW_URL_BASE + '/get-file-diff/' + pk
+        }).pipe(function(data) {
+            return diff.buildDiffTable(data.chunks, data.oldlines, data.newlines);
         });
-
-        var deferred = new $.Deferred();
-        req.done(function(data) {
-            deferred.resolve(diff.buildDiffTable(data.chunks, data.oldlines, data.newlines));
-        });
-        return deferred;
     }
 
     function createFileView(filename, pk) {
-        var req = $.ajax({
+        return $.ajax({
             type: 'GET',
             dataType: 'json',
             data: { filename: filename },
             url: REVIEW_URL_BASE + '/get-file/' + pk
+        }).pipe(function(data) {
+            return buildFileView(data);
         });
-
-        var deferred = new $.Deferred();
-        req.done(function(data) {
-            deferred.resolve(buildFileView(data));
-        });
-        return deferred;
     }
 
     $.fn.reviewify = function(diff) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]