webcss / angular-indexedDB

An angularjs serviceprovider to utilize indexedDB with angular
149 stars 99 forks source link

transaction.oncomplete vs request.onsuccess #17

Closed cipconsolacion closed 10 years ago

cipconsolacion commented 10 years ago

I have test cases that do something like:

indexeddb.delete(...).then (function() { indexeddb.insert(...).then(function() { indexeddb.find(...).then(function(data){}; }; };

The result is intermittent. Sometimes 'data' correctly finds the value, but sometimes 'data' is undefined.

I "fixed" this by making sure that the transaction has been completed before resolving the promise:

req.onsuccess = function(e) { store.transaction.oncomplete = function(){ $rootScope.$apply(function(){ d.resolve(e.target.result); }); } };

I don't know the sequence of when transaction.oncomplete and request.onsuccess functions are called. I'm very new to indexeddb (well, and angular) so I'm not sure what the best approach is.

cipconsolacion commented 10 years ago

Nevermind, looks like someone already raised this issue before

lll000111 commented 7 years ago

@cipconsolacion Could you PLEASE link to some previous issue when you mention it?

There even is a cartoon for exactly what you did right here! Somebody (me right now) looks for an issue on Google, finds a ticket -- and the person says "Nevermind, fond the solution" without actually saying what it is!

Because I'm wondering whether I should use the onsuccess handler of the request or use the transaction. The MDN examples all use the request and not the transaction, which seems wrong to me.