SAP UI5 view controller lifecycle discussion - onInit

Created by Jerry Wang, last modified on Aug 08, 2014

新建一个view instance:

SAP UI5 view controller lifecycle discussion - onInit


Callstack2: 这个view的实例化会调用下图所示的另一个function ( r["view"] ). 传入function的参数就是上图中的对象字面量,也就是指定的view detail。


SAP UI5 view controller lifecycle discussion - onInit

Callstack3: 进到callstack2 所示的function中去,因为待构造的view类型是JS view,因此进入相应分支:


SAP UI5 view controller lifecycle discussion - onInit

Callstack4: 可以发现JSView constructor是采取lazy load的方式进行加载的:

SAP UI5 view controller lifecycle discussion - onInit



line 9292行会把执行delegate给下一个function r.



Callstack5: this 指向正在初始化的view instance.SAP UI5 view controller lifecycle discussion - onInit

SAP UI5 view controller lifecycle discussion - onInit


可以发现这个_initCompositeSupport function 函数体内会抛一个AfterInit的event。

SAP UI5 view controller lifecycle discussion - onInit

Callstack6: 这里的this就是view instance,this.oController就是view controller instance。

SAP UI5 view controller lifecycle discussion - onInit

把鼠标放在onInit上能观察到我们在Eclipse里写的code。

SAP UI5 view controller lifecycle discussion - onInit

Callstack7: 重用EventProvider的fireEvent方法来raise event:

SAP UI5 view controller lifecycle discussion - onInit

Callstack8: I.fFunction就是controller里实现的onInit方法,oListener就是controller,oListener.oView就是view本身。

SAP UI5 view controller lifecycle discussion - onInit

于是最终call到controller的onInit方法:

<img src="https://user-images.githubusercontent.com/5669954/28253419-77bc105a-6ad6-11e7-8e8b-b4da68d62fea.png)


上一篇:从Eclipse使用team provider上传UI5 application到server的注意事项


下一篇:view controller lifecycle discussion - beforeRendering