sapui5

What is the "onUI5Init" global event?


Recently I came across the following JSBin. In the 'JavaScript' section, one can notice the initialization happening inside a global onUI5Init listener. This surprised me a bit, because all the demos I've seen use sap.ui.getCore().attachInit or otherwise attachInit call to the core. Moreover, there seems to be no official documentation on this event.

What does this approach do, does it execute before attachInit or does it have any advantages over attachInit? Is there some documentation I'm missing?

Any info is appreciated.


Solution

  • [...] there seems to be no official documentation on this event.

    "onUI5Init" is an event hook that I named, originally in https://jsbin.com/neyagus/edit?html,js,output I think. In the HTML panel of that JSBin sample, you can see that "onUI5Init" is assigned to data-sap-ui-onInit.

    More information about the onInit and its benefits are described in the topic Initialization Process.

    See also the description of "on-init" in the topic Configuration Options and URL Parameters which states currently:

    Type: string | function

    Default value: undefined

    Defines code that has to be executed after the initialization.

    In case a string is provided, this must be either the name of a module indicated by the prefix module: (like module:sap/ui/core/ComponentSupport) or the name of a property within the globalThis object containing a function. The provided module will be loaded and executed after initialization.

    Within globalThis["sap-ui-config"]["on-init"] it is also possible to provide a function directly.

    Caution

    For productive scenarios, only the usage of a module is supported. Functions or function references to the globalThis object are only intended to be used within non-productive scenarios, such as testing, web-based debugging, or sharing minimal samples.