码迷,mamicode.com
首页 > 其他好文 > 详细

SAP UI5 Bootstrap脚本的实现原理

时间:2020-09-15 20:56:39      阅读:38      评论:0      收藏:0      [点我收藏+]

标签:data-   公众   ever   explain   form   原创   else   tail   last   

Can I change the hard code ID?

In SAP help the UI5 bootstrap logic is explained: Bootstrapping: Loading and Initializing SAPUI5 in HTML Pages.

However, I was asked by my colleague about one question: the script id below is hard coded. Can I change its id to any other value like HelloWorld?

技术图片

The answer is yes. For example the id below still works.

技术图片

In order to explain this behavior, we have to understand the UI5 bootstrap process in more detail.

How to find the starting point for research?
Perform global search with the hard coded key word “sap-ui-bootstrap”, set a break point on search result, line 14893 below.

技术图片

Refresh the application and break point is triggered. Through the comment of the function we can know that it is responsible to parse the bootstrap script node we define in index.html to determine the resource root.

技术图片
技术图片

The logic of UI5 framework to determine whether a script tag is a “bootstrap” tag is done by three regular expression evaluation ( see variables reConfigurator, reBootScripts and reResources in below screenshot ).

技术图片

Only if all the three evaluation fail, then framework will compare the script tag id with hard coded id “sap-ui-bootstrap” as last resort.
In my case, although I change the ID to “HelloWorld”, the second regular expression still succeed so resource root is successfully determined, no need to go the last ELSE-IF to compare the ID with hard coded value.

技术图片

How are libraries specified in data-sap-ui-libs loaded by UI5 framework?

Another question is: I have specified all libraries I would like to use in attribute “data-sap-ui-libs” as pure string value, how is UI5 framework able to parse this string and loading library one by one?

技术图片

Since the bootstrap script tag is successfully determined via regular expression, now its attribute are ready for parse.

技术图片

The pure string value for libraries to be loaded is stored in oCfg.libs.

技术图片

The code highlighted below parses the string and convert library name into an array: config.modules.

技术图片
技术图片

Those libraries are loaded by function loadLibrary in line 39294 one by one:

技术图片

要获取更多Jerry的原创文章,请关注公众号"汪子熙":
技术图片

SAP UI5 Bootstrap脚本的实现原理

标签:data-   公众   ever   explain   form   原创   else   tail   last   

原文地址:https://www.cnblogs.com/sap-jerry/p/13598644.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!