Re: [IndexedDB] API feedback

On Mar 12, 2010, at 9:05 AM, Aaron Boodman wrote:

> Looking at just this snip:
>
> function findFred(db) {
>  db.request.onsuccess = function() {
>    var index = db.request.result;
>    index.request.onsuccess = function() {
>      var matching = index.request.result;
>      if (matching)
>        report(matching.isbn, matching.name, matching.author);
>      else
>        report(null);
>    }
>    index.get('fred');
>  }
>  db.openIndex('BookAuthor');
> }
>
> This example is hard to read where the callback is setup before the
> call like this. Without making any API changes, I think you could
> improve things:
>
> db.openIndex('BookAuthor');
> db.request.onsuccess = function() {
>  ...
> };
>
> You just have to make sure that the API guarantees that
> onsuccess/onfailure will always be called in a separate event, which
> is important anyway for consistency.

This seems like a light-weight enough requirement that can improve  
program comprehension.

Received on Saturday, 13 March 2010 09:46:16 UTC