Repository navigation
Expand file tree
/
Copy pathcouchdb.changes.js
More file actions
48 lines (45 loc) · 1.91 KB
/
Copy pathcouchdb.changes.js
File metadata and controls
48 lines (45 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
;(function($) {
$.couchdb = {};
$.couchdb.changes = {};
$.couchdb.changes.database = function (database, callback) {
$.getJSON("/" + database, function(db) {
var url = "/_changes?since="+ db.update_seq +"&heartbeat=10000&feed=longpoll";
$.getJSON("/"+ database + url, function(changes) {
if($.isFunction(callback)){
callback.call(this, changes);
$.couchdb.changes.database(database, callback);
}
});
});
};
$.couchdb.changes.document = function (database, docid, callback){
var url = "/" + database;
$.getJSON(url, function(db) {
url += "/" + docid;
$.getJSON(url, function(doc) {
url = "/" + database + "/_changes?since="+ db.update_seq;
url += "&heartbeat=10000&feed=longpoll";
url += "&include_docs=true";
$.getJSON(url, function(changes) {
$.each(changes, function() {
if($.isArray(this)) {
$.each(this, function() {
if(this.id.match(docid)) {
if(!this.changes[0].rev.match(doc._rev)) {
if($.isFunction(callback)){
url = "/" + database + "/" + docid;
$.getJSON(url, function(doc) {
callback.call(this, doc);
});
$.couchdb.changes.document(database, docid, callback);
}
}
}
});
}
});
});
});
});
};
})(jQuery);