Monday, May 12, 2008

Teaching === Learning

I spent most of the 90's teaching various networking technologies to people (Novell's NDS, Microsoft's passive directory, TPC/IP, et.c). And if there's one thing I learned from that experience(except what a challenge some students can be :) is that you just think you know something until you've tried to teach it.

And conversely, after having survived a dozen courses you can finally say that you've mastered the subject (for the level you're teaching, naturally). It's not enough to read the books over and over, and it's not even enough to work with it day in and out (though it's even better). If you're not forced to take one step back and actually formulate a personal theory about how things work, you'll never truly grasp a subject.

There's no magic here, only a specific level of effort and - maybe - will. One always strive to do the least in any given situation. I would classify this as a property tied not to Swedes in general or even humans in general, but to all life, period.

So the trick is to put oneself in a situation where above an beyond call of duty become the least possible effort. That way is to write a book :)

I thought I knew a bit or two about Dojo before i began, but that's nothing compared to what I know now. Unfortunately that's still meager catch compared to what I now see available. Well, I won't die bored, that's for sure.

This weekend I finished chapter three of "Learning Dojo", which would be an overview of how Dijits (Dojo's widgets) work. What struck me was that I found a lot of things that I've been looking for, but have had to hack brute force the last year.

For instance, if you're creating a custom widget (and, let's face it, that's the way you work) you often want to access the DOM nodes in the template for various reasons, from you widget class. I had resorted to misuse the basic template variable substitution in Dojo, which lets you use ${} syntax in the HTML template of a widget to directly insert 'this' level variables. My templates looked a bit like this;

div id="${id}_dialog" dojotype="dijit.Dialog"\>div id="${id}_dialog" dojoType="dijit.Dialog"\>...\/div

This will lead Dojo to automatically insert the id property of the widget into the variable, so that if the id we had given our custom widget was 'foo', this node now had an id of 'foo_dialog', which modularized stuff in a good manner, so as to not collide with other instances of the same custom widget in the page, et.c.

When I started writing about attach points, I realized I was very unsure about how they worked. I re-read the online documentation and couldn't really make heads or tails of it. Finally I started testing ideas of how attach points might work in a small test widget.

What I did was the following;

div dojoAttachPoint="dialog" dojoType="dijit.Dialog"\>...\/div

And then I suddenly had a new property in my widget class called 'dialog', or 'this.dialog'. Strange huh? :) As it turned out attach points was what I had been doing all along, only slicker and truly integrated. They work for ordinary DOM nodes in the templates as well, the property just is a reference to the DOM node instead of the widget.

I learned a lot more things during the course of writing the chapter, but I'll get to them in another post. The attach point conundrum has been bugging me or quite a while, so I just wanted to blog about it for some for chap who like me, really needs it but doesn't grok the online dox :)

No comments: