This is the bocoup web log with posts from Al, Boaz, Rick, Sam, Nate, Nick & Pete. You should also make sure to checkout code.bocoup.com, where we keep the finished versions of ideas we kick around here.


May 18, 2010

Javascript Web Workers: From Basics to jQuery.Hive, Part III


I’m a jQuery enthusiast. Maybe even an evangelist. So I decided to make workers easy for my fellow jQuery developers – and thus was born the jQuery.Hive. Inititally it began it’s life as PollenJS a jQuery-looking library of functions that were light, useful and thread-safe. This was before the WebKit implementation existed so everything was written with the notion that it would only exist in the Worker. The MOST IMPORTANT goals were and still are:

  • Concise syntax
  • Shallow learning curve for jQuery developers

Not long after I began developing PollenJS, Safari WebKit added Worker support and shortly thereafter Chrome WebKit caught up. Of course then PollenJS was officially broken – it normalized messages into objects to add support for identity from one worker to the other… WebKit sent errant empty messages.


This is when the Hive was born.


… Which was awesome, because it gave me the opportunity to make the main window as easy to manage development with workers as PollenJS had become within the worker. The basic goals were:

  • Simplify the client/main page worker setup API
  • Wrap the Worker constructor and functions in syntax that jQuery developers are familiar with
  • Normalize cross-implementation inconsistencies

jQuery.Hive/PollenJS turbocharge your workers.

Let’s look at the data filter example from above, but in jQuery.Hive/Pollen JS syntax…

It’s important to remember that including ‘jquery.hive.pollen.js’ is REQUIRED, or else you will not get compatibility across implementations. And plus, it’s got rad stuff in it.

Get jQuery.Hive/PollenJS from GitHub – Starter Kit included!

The [In]Complete jQuery.Hive API

The [In]Complete jQuery.Hive.Pollen.js API

Considering it’s youth as a project, the API is subject to change.

*Edit*
In the time since this was originally published, Chrome, Safari & Opera now support complex JSON messages.



Comments:




Please send your questions to this address or call Bocoup at 617-379-2752
This web page is proudly maintained by Bocoup and hosted by (mt) Media Temple
All code on this website is Open Source