couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kxe...@apache.org
Subject [25/50] jquery-couch commit: updated refs/heads/import-master to 66dbcbf
Date Tue, 01 Apr 2014 08:52:30 GMT
make jquery.couch.js changes handling more robust

git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@957380 13f79535-47bb-0310-9956-ffa450edef68


Project: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/commit/b6294147
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/tree/b6294147
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/diff/b6294147

Branch: refs/heads/import-master
Commit: b629414755b13b435701256b0d14c9b091ad8cfc
Parents: deaacf0
Author: John Christopher Anderson <jchris@apache.org>
Authored: Wed Jun 23 22:26:21 2010 +0000
Committer: Alexander Shorin <kxepal@gmail.com>
Committed: Wed Jun 23 22:26:21 2010 +0000

----------------------------------------------------------------------
 jquery.couch.js | 40 +++++++++++++++++++++++++++++-----------
 1 file changed, 29 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-jquery-couch/blob/b6294147/jquery.couch.js
----------------------------------------------------------------------
diff --git a/jquery.couch.js b/jquery.couch.js
index e128c22..5f4de8b 100644
--- a/jquery.couch.js
+++ b/jquery.couch.js
@@ -233,7 +233,9 @@
         changes: function(since, options) {
           options = options || {};
           // set up the promise object within a closure for this handler
-          var db = this, active = true, listeners = [], promise = {
+          var timeout = 100, db = this, active = true,
+            listeners = [],
+            promise = {
             onChange : function(fun) {
               listeners.push(fun);
             },
@@ -249,18 +251,24 @@
           };
           // when there is a change, call any listeners, then check for another change
           options.success = function(resp) {
+            timeout = 100;
             if (active) {
-              var seq = resp.last_seq;
+              since = resp.last_seq;
               triggerListeners(resp);
-              getChangesSince(seq);
+              getChangesSince();
             };
           };
+          options.error = function() {
+            if (active) {
+              setTimeout(getChangesSince, timeout);
+              timeout = timeout * 2;
+            }
+          };
           // actually make the changes request
-          function getChangesSince(seq) {
-            var opts = {};
-            $.extend(opts, options, {
+          function getChangesSince() {
+            var opts = $.extend({heartbeat : 10 * 1000}, options, {
               feed : "longpoll",
-              since : seq
+              since : since
             });
             ajax(
               {url: db.uri + "_changes"+encodeOptions(opts)},
@@ -270,11 +278,12 @@
           }
           // start the first request
           if (since) {
-            getChangesSince(since);
+            getChangesSince();
           } else {
             db.info({
               success : function(info) {
-                getChangesSince(info.update_seq);
+                since = info.update_seq;
+                getChangesSince();
               }
             });
           }
@@ -597,7 +606,16 @@
         }
       },
       complete: function(req) {
-        var resp = $.httpData(req, "json");
+        try {
+          var resp = $.httpData(req, "json");
+        } catch(e) {
+          if (options.error) {
+            options.error(req.status, req, e);
+          } else {
+            alert(errorMessage + ": " + e);
+          }
+          return;
+        }
         if (options.ajaxStart) {
           options.ajaxStart(resp);
         }
@@ -605,7 +623,7 @@
           if (options.beforeSuccess) options.beforeSuccess(req, resp);
           if (options.success) options.success(resp);
         } else if (options.error) {
-          options.error(req.status, resp.error, resp.reason);
+          options.error(req.status, resp && resp.error || errorMessage, resp &&
resp.reason || "no response");
         } else {
           alert(errorMessage + ": " + resp.reason);
         }


Mime
View raw message