Wednesday, November 14th, 2007
Dissecting Dijit: Dojo Widgets
One of the best parts of Dojo 1.0 has been how often the team has been blogging of all things. It has been great!
Mike Wilcox has posted about Dijit, the widget platform for Dojo 1.0.
His piece covers dojo.parser, dojo.declare, the widget markup, the lifecycle of widgets, and more. Great stuff.
The lifecycle is very thorough:
preamble()- Originating in dojo.declare, preamble is a new Dojo Core feature. It’s a pre-constructor accessory. By analogy, preamble is to constructor as
postMixInPropertiesis topostCreate. Since preamble gets the same arguments as the constructor, you may extend another object, and jump in front of the constructor and change the arguments. constructor()- Originating in
dojo.declare,constructorhas a new usage pattern. Previously, it fired last, which I didn’t find particularly useful nor accurate. It now fires early in the widget lifecycle, allowing early initialization with the arguments passed into the object. While more common in use, it’s not exactly necessary, as Dijit handles the job of converting your arguments into object properties. postMixInProperties()- Originating in
dijit._Widget,postMixInPropertiesis used more commonly by widget developers. That said, some of its duties are superseded by the addition ofconstructorandpreamble. Its main purpose is firing after the properties have been set, but before the widget has been parsed and created. Pre-creation work on widget properties is typically done in this method. postCreate()- Originating in
dijit._Widget,postCreateis the “heavy lifter” of Dijit. This fires after creation, but before the widget is rendered to the page. At this time in the widget lifecycle, you have access to the widget’s nodes, so additional parsing, connections, styling, or even attaching more widgets is possible. startup()- Originating in
dijit._Widget,startupis somewhat misunderstood.startupdoesn’t fire unless the widget is a child of another widget. And then it only fires after it, and all of its siblings have been created. Then they all fire together.













Leave a comment