Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added chapter about the init function #100

Open
wants to merge 1 commit into
base: releases/11.0
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion docs/adoc/technicalGuideJS/ScoutJS.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -238,10 +238,26 @@ So if a property is defined as widget property, calling a setter will do the fol

. It checks if the property has changed at all (same as for regular properties).
. If the values are not equal, `_prepareWidgetProperty` is called which checks if the new value already is a widget and if not creates it. It also destroys the old widget unless the property should not be preserved (see `_preserveOnPropertyChangeProperties`). If the value is an array, it does so for each element in the array (only widgets which are not part of the new array will be destroyed).
. If the widget is rendered, the old widget is removed unless the property should not be preserved. If there is a custom remove function (e.g. _removeXY where XY is the property name), it will be called instead of removing the widgets directly. Note that the widget may have already been removed by the destroy function at the prepare phase.
. If the widget is rendered, the old widget is removed unless the property should not be preserved. If there is a custom remove function (e.g. pass:[_]removeXY where XY is the property name), it will be called instead of removing the widgets directly. Note that the widget may have already been removed by the destroy function at the _prepare_ phase.
. The model is updated (same as for regular properties).
. The render method is called (same as for regular properties).

=== Functions

==== _init
When you call `scout.create('Button', model)` to instantiate a new Scout button, obviously the constructor of the Button class is called. But additionally, Scout calls the `init` function passing the given model to the `Widget.pass:[_]init` function. There _all_ properties from the given model parameter are copied to the Widget instance itself. This is true not only for properties defined by the widget, but for custom properties too. Thus, you never have to assign a model-property manually, when you pass a model to `scout.create`. Example:

[source,javascript]
----
var button = scout.create('Button', {
parent: parent,
foo: 'bar'
});
console.log(button.foo); // outputs 'bar'
----

This works for custom widgets too. Simply make a super-call to the `pass:[_]init` function of the Widget class, if your custom widget overrides the `pass:[_]init` function.

=== Events
Every widget supports event handling by using the class `EventSupport`. This allows the widgets to attach listeners to other widgets and getting informed when an event happens.

Expand Down