Re: IndexedDB, what were the issues? How do we stop it from happening again?

On Sunday, 17 February 2013 at 14:39, Miko Nieminen wrote:

> I quite don't see how to simplify IDB syntax much more.

[1] shows how it can be written using promises. As Jonas Sicking, who is the Editor of the IDB spec, states:
"As you can see, the .then function on DOMFuture/Promises certainly makes the code cleaner and removes a lot of the syntax overhead. But the capabilities are exactly the same."

Relating to DOMRequest, David Braunt writes:

"In my opinion, one of the most absurd example is the DOMRequest thing which 
looks like:
    readonly attribute DOMString readyState; // "processing" or "done"
    readonly attribute DOMError? error;
    attribute EventListener      onsuccess;
    attribute EventListener      onerror;
    attribute readonly any?      result;

Read it carefully and you'll realize this is actually a promise... but 
it has this absurd thing that it has to have both an error and result 
field while only one is actually field at any given point.

Also, these APIs and JavaScript as it they are won't support promise 
chainability and the excellent error forwarding that comes with it 
off-the-shelf. Also, the lack of a built-in Q.all really doesn't promote 
good code when it comes to event synchronization.
Oh yes, of course, you can always build a promise library on top of the 
current APIs, blablabla... and waste battery with these libraries [3].

So it appears there are ways to simplify the code. Getting rid of some of the error/result absurdity would be helpful. 

Marcos Caceres

Received on Sunday, 17 February 2013 15:06:58 UTC