Dojo Toolkit – difficult to learn, is it worth it?

Tags:

I’ve usually dismissed the Dojo Toolkit as a difficult, poorly documented JavaScript library.

However, Zend Framework recently decided to choose it as the default JS library to bundle with the framework. It can’t be all bad if that happens, right?

This sparked my curiosity towards Dojo again – Maybe it was time to actually try it for real, armed with patience…

The documentation

This was always the biggest problem I saw in Dojo. Sometime in the past, I had taken a look at it, and it seemed to have some nice UI widgets, but the documentation was really bad. It was confusing and difficult to figure out on my own, so I pretty much ignored it.

So has it gotten any better? Yes, slightly. The documentation on the website is still a bit poor, but it has gotten better, and there’s also another, newer, version of the documentation available at Dojo Campus, which fills many holes. The site also has some more examples on various Dojo-topics.

Still, the manual leaves something to hope for. When Dojo was first adopted to ZF, I had a discussion about it on #zftalk with Peter Higgins, who is the Dojo project leader. He told me they are working on improving the documentation, so hopefully this matter will be getting better in the future.

Getting started

Getting started is actually quite easy. You don’t even need to download anything, as you can include dojo from the AOL or Google CDN’s. Basic functionality is covered pretty nicely in the docs now, and you can easily get underway.

Using Dojo widgets, Dijits, is pretty easy too, though the manual covers the declarative approach in much bigger detail than the programmatic one. Using the declarative approach, you would add dojoType=”something” style markup into your HTML, which I personally don’t like. This caused some delays at first, as I had to figure out how the parameters given in markup translate to programmatic JS-based code. Turns out they are pretty much exactly the same.

Advanced stuff

This is where the problems start. More advanced features don’t seem to have much docs, and it’s easy to stumble here.

For example, I wanted to dynamically load a tree from the server. Show a bunch of nodes, then when you expand a node, it would fetch more from the server… I also wanted the nodes to be selectable with a checkbox. This appears to need a bit of hacking and a lot of research at first, as there is no example of such.

Luckily, the Dojo source code is quite well written, and just like with Zend Framework, it’s quite simple to figure out how things work and how to make them work like you want by reading the source, but unless you’re a JavaScript ninja, or at least a ninja apprentice, this may be a bit daunting.

I did eventually manage to make the tree load with ajax and have checkbox-selectable node (more on that in a later post). I have done something quite similar using the Yahoo UI framework, and I have to say the end result with Dojo was better.

Conclusion

So would I recommend learning Dojo? Yes!

While it is pretty big and scary at first, and it’s like banging your head to a brick wall.. the wall eventually starts to crumble and things get easier.

Dojo isn’t also just for heavy lifting. The Dojo core is quite small, and contains much of what you’d expect from JS libraries such as Prototype or jQuery. And talking about the heavy lifting, the Dijit widgets are some of the best I’ve yet seen – powerful, good looking and most of all, easy to extend, which is an important point to me.