Tuesday, April 15, 2014

Control's Life

Today I will explain the life cycle of the redui control.


At this stage control gets all the properties and methods.
Most of the properties will be still empty, but the most important ones: id and the type should be set.

Initialize from model

At this point control model is validated and normalized.
Optional model properties that were not provided are set to their default values. For example, TextBox label, if not provided, is set to "".

Also at this point has a chance to pre-calculate some values. For example, ComboBox options will be retrieved at this moment, packed into objects, stocked into the array and saved on the options property.

At last, it is a moment (and responsibility) of a control to create and initialize its inner controls.

Render to HTML

All the rendering logic is inside the template. If a control has inner controls, they should be rendered through the template.


This is a time to subscribe to DOM events.
One of the most important events is change, which allows databound control to update the object it is bound to.

As with the other stages, the control is responsible to activate every inner control!

Set Value

This will only happen for databound controls.
All control has to do is to apply the passed value to the DOM element. For example, TextBox needs to set the value of its INPUT element.

Get Value

This will only happen for databound controls. Control needs to return the updated value from the DOM element.

No comments:

Post a Comment