Opened 15 years ago

Closed 15 years ago

#1350 closed enhancement (invalid)

Calling addChild directly on container widgets

Reported by: [email protected] Owned by: bill
Priority: high Milestone: 0.9
Component: Widgets Version: 0.3
Keywords: Cc:
Blocked By: Blocking:


In 0.31 the parser adds children to the children array of the parent via a method separate from the widget's addChild method.

So if the widget wants to do validation or anything on it's children, it has to do something like this:

postCreate: function() {

var childBuffer = this.children; this.children=[]; dojo.html.removeChildren(this.domNode); dojo.lang.forEach(childBuffer, dojo.lang.hitch(this,"addChild"));


Would it make sense for the parser to call addChild directly on the widget?

I assume isContainer: true means that the widget has children / is allowed to have children. So if the widget is allowed to have children, then maybe Widget or HtmlWidget? could have the minimum addChild functionality necessary to add the kids to the children array and then if additional processing is necessary, like validating the child's type, it could be added like this.

addChild: function(widget) {

Pre processing on the potential child if (widget.widgetType!='aSpecificWidgetType')

throw InvalidWidgetException?

parent.addChild(widget) This actually adds it to the list


This would enhance performance as the widget list would only be processed once per widget creation.


  • Ole

Change History (3)

comment:1 Changed 15 years ago by dylan

Component: GeneralWidgets
Milestone: 0.5
Owner: changed from anonymous to bill

comment:2 Changed 15 years ago by [email protected]

Widget Tracking Note:

Suppose I have a widget that tracks information about other widgets.


For example if whenever addChild is called on a widget (someWidget), addChild also calls trackWidgetReference.trackingSum =+ widget.getContainerWidth();


has to return an accurate number, so the sent document has to be parsed and child widgets/elements of the widget created and their css properties initialized (If html).

So this has to be taken into account if addChild is called directly during widget parsing.

Perhaps this is why dojo does it the way it does it.

comment:3 Changed 15 years ago by bill

Resolution: invalid
Status: newclosed

Given the way the parser has been rewritten, addChild() isn't really called at all, but there is a startup() method where you can do processing on your children. In any case you shouldn't have to call removeChild()/addChild().

Note: See TracTickets for help on using tickets.