Commit 16ff4896 authored by Romain Courteaud's avatar Romain Courteaud

wip indexeddb .then

parent 11db1a2f
...@@ -346,15 +346,14 @@ ...@@ -346,15 +346,14 @@
return waitForTransaction(db, ["metadata", "attachment", "blob"], return waitForTransaction(db, ["metadata", "attachment", "blob"],
"readwrite", function (tx) { "readwrite", function (tx) {
var promise_list = [], var promise_list = [];
result;
function deleteEntry(cursor) { function deleteEntry(cursor) {
promise_list.push( promise_list.push(
waitForIDBRequest(cursor.delete()) waitForIDBRequest(cursor.delete())
); );
} }
result = RSVP.all([ return RSVP.all([
waitForIDBRequest(tx.objectStore("metadata").delete(id)), waitForIDBRequest(tx.objectStore("metadata").delete(id)),
// XXX Why not possible to delete with KeyCursor? // XXX Why not possible to delete with KeyCursor?
waitForAllSynchronousCursor( waitForAllSynchronousCursor(
...@@ -367,12 +366,8 @@ ...@@ -367,12 +366,8 @@
.openCursor(IDBKeyRange.only(id)), .openCursor(IDBKeyRange.only(id)),
deleteEntry deleteEntry
), ),
]); ])
return new RSVP.Queue() .then(function () {
.push(function () {
return result;
})
.push(function () {
return RSVP.all(promise_list); return RSVP.all(promise_list);
}); });
}); });
...@@ -393,14 +388,10 @@ ...@@ -393,14 +388,10 @@
return waitForTransaction(db, ["attachment", "blob"], "readonly", return waitForTransaction(db, ["attachment", "blob"], "readonly",
function (tx) { function (tx) {
// XXX Should raise if key is not good // XXX Should raise if key is not good
var result = waitForIDBRequest(tx.objectStore("attachment").get( return waitForIDBRequest(tx.objectStore("attachment").get(
buildKeyPath([id, name]) buildKeyPath([id, name])
)); ))
return new RSVP.Queue() .then(function (evt) {
.push(function () {
return result;
})
.push(function (evt) {
var attachment = evt.target.result, var attachment = evt.target.result,
total_length = attachment.info.length, total_length = attachment.info.length,
promise_list = [], promise_list = [],
...@@ -462,8 +453,7 @@ ...@@ -462,8 +453,7 @@
}; };
function removeAttachment(tx, id, name) { function removeAttachment(tx, id, name) {
var promise_list = [], var promise_list = [];
result;
function deleteEntry(cursor) { function deleteEntry(cursor) {
promise_list.push( promise_list.push(
...@@ -471,21 +461,17 @@ ...@@ -471,21 +461,17 @@
); );
} }
result = waitForIDBRequest( return waitForIDBRequest(
tx.objectStore("attachment").delete(buildKeyPath([id, name])) tx.objectStore("attachment").delete(buildKeyPath([id, name]))
); )
return new RSVP.Queue() .then(function () {
.push(function () {
return result;
})
.push(function () {
return waitForAllSynchronousCursor( return waitForAllSynchronousCursor(
tx.objectStore("blob").index("_id_attachment") tx.objectStore("blob").index("_id_attachment")
.openCursor(IDBKeyRange.only([id, name])), .openCursor(IDBKeyRange.only([id, name])),
deleteEntry deleteEntry
); );
}) })
.push(function () { .then(function () {
return RSVP.all(promise_list); return RSVP.all(promise_list);
}); });
} }
...@@ -512,13 +498,9 @@ ...@@ -512,13 +498,9 @@
return waitForOpenIndexedDB(db_name, function (db) { return waitForOpenIndexedDB(db_name, function (db) {
return waitForTransaction(db, ["attachment", "blob"], "readwrite", return waitForTransaction(db, ["attachment", "blob"], "readwrite",
function (tx) { function (tx) {
var result = removeAttachment(tx, id, name); // First remove the previous attachment
return new RSVP.Queue() return removeAttachment(tx, id, name)
.push(function () { .then(function () {
// First remove the previous attachment
return result;
})
.push(function () {
// Then write the attachment info // Then write the attachment info
return waitForIDBRequest(tx.objectStore("attachment").put({ return waitForIDBRequest(tx.objectStore("attachment").put({
"_key_path": buildKeyPath([id, name]), "_key_path": buildKeyPath([id, name]),
...@@ -530,7 +512,7 @@ ...@@ -530,7 +512,7 @@
} }
})); }));
}) })
.push(function () { .then(function () {
var blob_store = tx.objectStore("blob"), var blob_store = tx.objectStore("blob"),
promise_list = [], promise_list = [],
i; i;
......
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