Saturday, September 6, 2008

jQuery style result sets for OR-Mapper

I implemented a couple shortcuts that enable working with datasets in a jQuery style.

As an example, the sticky note code had a couple lines that looked like this:

Note.selectAll(function (notes) {
notes.each(function (note) {
note.redraw()
note.show()
})
})


The API is inherently asynchronous because that is the only way that is provided by the HTML5 database API.

This can now be written as:
Note.selectAll().draw().redraw().show()


This is pretty dark JavaScript magic going on, because all methods after selectAll won't really be executed until the select has actually been executed.
I like this API style much better, but it has some serious draw backs:
  • In the Gears version you loose the transaction context because evil global vars are involved (in my mock up implementation of the HTML5 api)
  • If there is something coming in the next line, one would expect it to be executed after show() which is not the case.
Post a Comment