How to make your generated widget’s DOM IDs reflect their AMD module

In the new AMD world, it’s suggested that we omit the specification of a “declaredClass” in our custom widget’s declare() call, like so:

define(["dijit/_WidgetBase"], function(_WidgetBase) {
    return declare([_WidgetBase], { 

    })
});

However, in this case, _WidgetBase doesn’t have a specified value for declaredClass, and uses the declaredClass from an appropriate parent class to automatically generate a DOM ID.

I’ve worked around this so far by using a pattern like this:

define(["module", "dijit/_WidgetBase"], function(module, _WidgetBase) {
    return declare(module.id, [_WidgetBase], { 

    })
});

Hopefully we’ll see some fixes from Dojo here to make this easier in future.

Dojo widget property setters and attributeMap’s replacement

As we create widgets to accomplish a task, we often need to contain other widgets. Creating a simple way to configure contained widgets via the containing widget’s API is often accomplished using custom _setXXXAttr functions.

However, Dojo provides alternative methods to achieve this. It provides the attributeMap feature, though this is deprecated and shall be removed in version 2.0. Since version 1.7, Dojo has provided a new syntax for _setXXXAttr that allows usage of attributeMap-style configurations.
Continue reading