startup and postCreate function in Dojo

1.2k Views Asked by At

I am new to Dojo library, I come across postCreate and Startup functions in Dojo and I am getting difficulties to understand these two function in widget life cycle.

I did google and read in dojo documentation but no luck. Can someone explain it with lucid example.

2

There are 2 best solutions below

2
Bourbia Brahim On BEST ANSWER

That's simple , those method come with every widget that extend or inherit the WidgetBase dojo class ,

Dojo widget passes thorough different life cycle method , among those we find the last two method postCreate and 'startup' ,

if you want postCreate comes just before startup in lifecycle , note that postCreate just finished to create your widget but may not yet attached to dom , also its child widget not mounted ,

On the other hand the startup come after widget rendrer with it's child widgets and mounted to dom.

so if you have any layout calculation , or dom related function , you may not use postCreate for this , and should use staartup to ensure widget has finished mounting to DOM

Read more in Doc

0
Nicolas I On

In general, you use postCreate for everything that you want to add to your widget (extra nodes, connect events) before the widget is shown.

startup is used after the widget is placed on the HTML dom and is mainly used when you have layout calculations or other layout widgets in your widget (Tabs, grid, containers, etc) startup usually calls resize function that handles all layout calculations.

resize will be also called if your widget is inside a layout widget.