Builtin Callbacks
init()
Every element implicitly declares an init
callback. You can assign a code block to it that will be invoked when the
element is instantiated and after all properties are initialized with the value of their final binding. The order of
invocation is from inside to outside. The following example will print “first”, then “second”, and then “third”:
Don’t use this callback to initialize properties, because this violates the declarative principle.
Even though the init
callback exists on all components, it cannot be set from application code,
i.e. an on_init
function does not exist in the generated code. This is because the callback is invoked during the creation of the component, before you could call on_init
to actually set it.
While the init
callback can invoke other callbacks, e.g. one defined in a global
section, and
you can bind these in the backend, this doesn’t work for statically-created components, including
the window itself, because you need an instance to set the globals binding. But it is possible
to use this for dynamically created components (for example ones behind an if
):