Wrapper initialization order, its update and destructor call

To form our application, we need to familiarize ourselves with the order of initialization of the wrapper and its binding to the DOM element.

At the beginning of the HTML, the code is placed in the body of the page, after which the wrapper is created and the fcf.NClient.Wrapper.initialize() method is called asynchronously. This method performs full initialization of the wrapper and, accordingly, when it is overloaded, it is necessary to call the original version from the base class.

During initialization and update, the wrapper performs template binding during which DOM events are bound, nested HTML JavaScript blocks are executed, and nested templates are created and initialized. During this process, the fcf.NClient.Wrapper.attach() method, which can also be overloaded. But when overloading, don't forget to call the base class method.

The template can be updated automatically when the template arguments are updated (if the autoUpdate template option is true) or when the fcf.NClient.Wrapper.update() method is explicitly called. During the update, the DOM tree is replaced, followed by rebinding the template. But it is possible to avoid replacing DOM elements if the merge template option is true. In this case, the DOM elements are merged, which does not lead to their replacement. This mode can be used in particular if the DOM element needs to store internal data.

Destruction of the wrapper occurs automatically when the template DOM element disappears from the page, this is done by the built-in garbage collector or if the template was removed in a rerender event.. Therefore, it is important that the DOM element be on the page as long as the template needs to exist. The actual destruction of the wrapper is performed by calling the fcf.NClient.Wrapper.destroy() method, while the internal flag of the wrapper object _destroy is set to true.