Porting from Dojo 0.4 to 0.9
Notes from porting my first widget across to the Dojo 0.9 code base.
Now that the dust has settled somewhat at work from some recent project launches, I finally had a chance to sit down and start my first widget port from 0.4.x code base to 0.9.
Some might think that I’m way behind the curve what with 0.9 being released for ohhhh 2 or 3 whole weeks, but I actually have no immediate rush to get too immersed in 0.9 for a couple of reasons:
- Internally at work we aren’t adopting 0.9 for production work.
- Our clients aren’t adopting 0.9 at all (everyone is waiting for 1.0)
- I’ve been worried I’ll like it too much and not want to do day job 0.4.3 work
- I’ve been worried I’ll hate it and become disenfranchised about my future
But knowing that I will need to start thinking about this in the coming months I figured now was as good a time as any to start the process. I’ll try and document some of my findings over the next couple of days as I get to the work.
Early stuff that you discover
Most of this isn’t rocket science, but I’ve been following and tracking the 0.9 code closely and some of this was a ’surprise’ to me, even after reading the same sorts of findings on other blogs and the official guide, so I’ll share this anyway…
More doesn’t work than you might think
There is a lot of stuff that just won’t work. I had almost assumed that some would work, but nothing worked OOTB moving from 0.4 to 0.9. There are huge chunks (almost all) of the library that has now been moved, refactored or renamed. So 90% of my dojo.require’s didn’t work anymore. In the end I took them all out anyway, I’ll need to revisit that once I get a better feel for what goes where.
The Widget is dead, long live the Dijit Huge amounts of the old code that just defined a widget has gone, it’s much much simpler (which is better, but for someone who is used to the old ways it’s a shock). Everything is familiar yet strangely different. I still need to look more at the Dijit inheritance and what you actually get, most fo my widgets I just converted to..
dojo.declare("my.widget", [dijit._Widget, dijit._Templated],{...
…but I’m sure there are subtleties in there.
Some functions have gone into witness protection Just doing a grep on the 0.9 codebase for the function name didn’t always work. Often I needed to think laterally, “what else could it be called” at worse I would find something that I knew needed to do the same thing and then see what function they used to do the same thing (that seemed easier than randomly trawling through the API docs (although I did that once or twice).
Things like dojo.place and dojo.coords were some sneaky ones, that bear little or no relation to the old function locations or names.
You now have 3 namespaces In hindsight I spent too long trying to work out what the new dojo.widget.byid was, again, coming from 0.4.x where everything starts with a dojo, looking for things starting dijit or dojox is a new muscle memory. Not to mention console.debug. I suppose soon this will all feel natural again.
That’s about it for today, I’ll update with more tomorrow and some actual examples of the porting of code, I’ll also cover some of the conversions of things like IO (which is a biggie).
First published on jpsykes.com.