Commit 337621d9 authored by Tristan Cavelier's avatar Tristan Cavelier

add notifications for indexeddb allDocs

parent 56f442e1
...@@ -366,13 +366,13 @@ ...@@ -366,13 +366,13 @@
// XXX doc string // XXX doc string
IndexedDBStorage.prototype.getList = function () { IndexedDBStorage.prototype.getList = function () {
var rows = [], onCancel, open_req = indexedDB.open(this._database_name); var rows = [], onCancel, open_req = indexedDB.open(this._database_name);
return new Promise(function (resolve, reject) { return new Promise(function (resolve, reject, notify) {
open_req.onerror = function () { open_req.onerror = function () {
if (open_req.result) { open_req.result.close(); } if (open_req.result) { open_req.result.close(); }
reject(open_req.error); reject(open_req.error);
}; };
open_req.onsuccess = function () { open_req.onsuccess = function () {
var tx, store, index, index_req, db = open_req.result; var tx, store, index, date, index_req, db = open_req.result;
try { try {
tx = db.transaction("metadata", "readonly"); tx = db.transaction("metadata", "readonly");
onCancel = function () { onCancel = function () {
...@@ -383,8 +383,9 @@ ...@@ -383,8 +383,9 @@
index = store.index("_id"); index = store.index("_id");
index_req = index.openCursor(); index_req = index.openCursor();
date = Date.now();
index_req.onsuccess = function () { index_req.onsuccess = function () {
var cursor = index_req.result; var cursor = index_req.result, now;
if (cursor) { if (cursor) {
// Called for each matching record. // Called for each matching record.
rows.push({ rows.push({
...@@ -392,8 +393,14 @@ ...@@ -392,8 +393,14 @@
"doc": cursor.value, "doc": cursor.value,
"value": {} "value": {}
}); });
now = Date.now();
if (date <= now - 1000) {
notify({"loaded": rows.length});
date = now;
}
cursor.continue(); cursor.continue();
} else { } else {
notify({"loaded": rows.length});
// No more matching records. // No more matching records.
resolve({"data": {"rows": rows, "total_rows": rows.length}}); resolve({"data": {"rows": rows, "total_rows": rows.length}});
db.close(); db.close();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment