Re: InedxedDB events : misconception?

Resending from the correct account:

....


FWIW, we had a Chrome IDB bug report where someone used the developer tools
to set a script breakpoint between the open() call and the event handler
assignments. The debugger spins the event loop, so the event was dispatched
before the handlers were assigned. The answer was "so don't do that", but
it's a similar API/platform gotcha leading to developer confusion.

On Mon, Apr 22, 2013 at 10:36 AM, Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 4/22/13 1:31 PM, Tab Atkins Jr. wrote:
>
>> Is there a reason to not pass the success/error/upgradeneeded callbacks
>>> in a
>>> dictionary to open() in this case, so that the request object is born
>>> with
>>> the right bits and the actual reques it not kicked off until _after_ the
>>> side-effects of getting them off the dictionary have fully run to
>>> completion?
>>>
>>
>> Dunno, ask sicking.  But events do have some benefits over passed
>> callbacks.
>>
>
> I don't understand the distinction.
>
> My straw-man proposal here is just that there is a dictionary with the
> three callbacks and then the return value has its onsuccess/onerror/**onupgradeneeded
> set to those three callbacks before the actual request is kicked off and
> the request object is returned.
>
>
> (The right answer is to figure out some way to accommodate IDB's
>> locking semantics in a future.  sicking and annevk have some
>> discussion on this.  Then there's no possibility of event races,
>> because your callback will still be fired even if you lose the race.)
>>
>
> That would be good, yes.
>
>
>
Given the "upgradeneeded" mechanism, it might end up being a hybrid of
passed-callbacks and futures, e.g.

futureSavvyIndexedDB.open(name, ver, {
  upgradeneeded: function(db) { /* upgrade logic */ }
).then(
  function(db) { /* success */ },
  function(err) { /* failure */ }
);

... with "blocked" events wedged in there somehow as future progress
notifications or some such. (I haven't followed the latest on that.)



> Synchronously spinning the event loop is the devil. :/
>>
>
> Well, yes.  ;)
>
> -Boris
>
>
>

Received on Monday, 22 April 2013 20:51:26 UTC