Permalink
Browse files

Del now returns the number of keys requested to be deleted.

We can't rely on e.target.result to be undefined when a key wasn't deleted as the spec says that the result should always be undefined. So instead we will just return the number of keys requested to be deleted.  Fixes #6
  • Loading branch information...
matthewpblog committed Apr 4, 2012
1 parent 85931c4 commit d304268fd0e2e996f2b09d28bb5e07eea75496f8
Showing with 21 additions and 38 deletions.
  1. +14 −19 build/gazel.js
  2. +1 −1 build/gazel.min.js
  3. +5 −8 src/del.js
  4. +1 −10 test/del.js
View
@@ -404,32 +404,27 @@ Client.prototype.del = function() {
else
args.splice(args.length - 1);
- var keys = args;
+ var keys = args,
+ deleted = keys.length;
this.register('write', function(uuid, cb) {
openDatabase(function(db) {
- var tx = self.trans.pull(db, uuid, IDBTransaction.READ_WRITE);
-
- var os = tx.objectStore(gazel.osName),
- left = keys.length,
- deleted = 0;
+ var tx = self.trans.pull(db, uuid, IDBTransaction.READ_WRITE),
+ os = tx.objectStore(gazel.osName),
+ left = keys.length;
while(keys.length > 0) {
-
(function() {
-
- var key = keys.shift();
- var req = os.delete(key);
- req.onerror = self.handleError.bind(self);
- req.onsuccess = function(e) {
- left--;
-
- if(e.target.result) deleted++;
-
- if(left === 0)
- cb.call(self, deleted);
- };
+ var key = keys.shift();
+ var req = os.delete(key);
+ req.onerror = self.handleError.bind(self);
+ req.onsuccess = function(e) {
+ left--;
+
+ if(left === 0)
+ cb.call(self, deleted);
+ };
})();
}
});
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -8,16 +8,15 @@ Client.prototype.del = function() {
else
args.splice(args.length - 1);
- var keys = args;
+ var keys = args,
+ deleted = keys.length;
this.register('write', function(uuid, cb) {
openDatabase(function(db) {
- var tx = self.trans.pull(db, uuid, IDBTransaction.READ_WRITE);
-
- var os = tx.objectStore(gazel.osName),
- left = keys.length,
- deleted = 0;
+ var tx = self.trans.pull(db, uuid, IDBTransaction.READ_WRITE),
+ os = tx.objectStore(gazel.osName),
+ left = keys.length;
while(keys.length > 0) {
(function() {
@@ -27,8 +26,6 @@ Client.prototype.del = function() {
req.onsuccess = function(e) {
left--;
- if(e.target.result) deleted++;
-
if(left === 0)
cb.call(self, deleted);
};
View
@@ -23,16 +23,7 @@ describe('Del', function() {
return res === 1;
});
});
-
- it('doesn\'t delete non-existing keys', function(done) {
- // Delete it once to clear clutter.
- client.del('unreal', function(first) {
- client.del('unreal', function(sec) {
- done(assert.equal(sec, 0));
- });
- });
- });
-
+
it('deletes multiple keys if given', function(done) {
var keys = [ 'del_one', 'del_two', 'del_three' ];
var mClient = gazel.createClient(),

0 comments on commit d304268

Please sign in to comment.