I've been a dojo (core) user for a few years now. Building my own widgets atop the dojo space; neglecting dijit and dojox. Working in my own world. That had it's advantages, but I kept having the feeling that I'm reinventing the wheel while building yet another tabbed panel, carousel or dialog box. So I've decided to use dijit.
With my own widgets, I've set some basic rules:
- A widget must degrade gracefully [when no js is loaded] for accessibility and SEO
- There should be no redraws after the js is loaded (which is always included on the page after all html, just before the body end-tag)
- No inline JS (scripts must be separate from HTML)
Problem:
Dijit has two ways of being instantiated: declaratively and programmatically. Either way seems to break one of the rules.
a. Declarative instantiation:
Looks either something like:
<div dojoType="MyFirstWidget">
<ul>
<li dojoAttachPoint="counter">0</li>
<li><a dojoAttachEvent="_updateCounter" href="#">Update</a></li>
</ul>
<script type="dojo/connect" event="onClick" args="evt">
console.log("This will execute after of the Button dijit's onClick method has been called.");
</script>
</div>
As you can see, this clearly breaks the 3rd rule (no inline js).
b. Programmatic instantiation:
dojo.require("dijit._Widget");
dojo.require("dijit._Templated");
dojo.declare("MyFirstWidget", [dijit._Widget, dijit._Templated], {
templateString: "<div class='awesome'>0</div>",
postCreate: function() {
console.log("postCreate");
}
});
(new MyFirstWidget()).placeAt(dojo.body());
And this way, rules 1 & 2 are broken. (1) No accessibility or SEO value (2) Once the template is set, the browser will need to redraw the entire page.
Question: is it possible (and practical) to use dijit, and still follow the rules?