专栏首页Jerry的SAP技术分享SAP UI5 Diagnostics工具里一个使用面向切片编程(AOP)的一个例子

SAP UI5 Diagnostics工具里一个使用面向切片编程(AOP)的一个例子

We know that UI5 framework provides a convenient Diagnostics tool for application developer to set breakpoint on a given method of control class. The Diagnostics tool could be launched via Ctrl+Alt+Shift+S.

We can select the control and its methods where we would like to set breakpoint. Once we click “Add breakpoint” button, next time if the corresponding method is called, the breakpoint would be triggered, without application developers’ manual set in Chrome development tool any more.

It looks like a magic? Today my colleague asked me how this feature is implemented, so I have a look at UI5 framework source code. We can again simply use Chrome development tool for research.

For example I would like to set breakpoint on method _bindAggregation:

Here the AOP idea is used.

The hook implementation is simply returning a new function via closure within which the original method is called ( line 521 ) with the new feature injected via keyword debugger.

After the logic is understood, we can practice in our application code.

Suppose I would like to have my button press event handler supported by this mechanism, I can simply write the following pseudo code:

var myButton = new sap.ui.commons.Button("btn",{
   text: "press me~"
  });
var handler = function(oEvent){
   oController.onPress(oEvent);
};
handler = bDebugModeActivated? util.tool.methodHook(handler): handler;
myButton.attachPress(handler);

In the runtime, once I press the button, debugger will be triggered with the following callstack:

Just step into line 36:

and then our event handler could be debugged:

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • 使用Adobe lifecycle Enterprise Service将word文档转换成PDF

    Currently I am working on a customer project regarding the usage of SAP document...

    Jerry Wang
  • SAP UI5的Component-preload.js是啥时候加载的

    版权声明:本文为博主汪子熙原创文章,未经博主允许不得转载。 https://jerry.bl...

    Jerry Wang
  • Angular应用里的Template Reference变量

    Angular应用里的Template Reference Variable,模板引用变量,用于创建一个对模板里DOM元素或者Angular指令的引用。

    Jerry Wang
  • 从MapX到MapXtreme2004[3]-搜索图元Feature

    一、根据名称搜索图元   1、Mapxtreme的架构和Mapx有所变化,Mapx中,Layer包含Features,而Mapxtreme中则不是   2、...

    用户1075292
  • CF思维联系– CodeForces -CodeForces - 992C Nastya and a Wardrobe(欧拉降幂+快速幂)

    Nastya received a gift on New Year — a magic wardrobe. It is magic because in th...

    风骨散人Chiam
  • Injection for Xcode 高效Xcode编译调试插件

    对于iOS开发者来说,XCode有个另人十分难耐的特性——编译时长的问题。也许工作的时候你能够为自己找到一个闲下来喝杯咖啡的正当的借口,然而,多次的调试编译过程...

    freesan44
  • Angular应用里的Template Reference变量

    Angular应用里的Template Reference Variable,模板引用变量,用于创建一个对模板里DOM元素或者Angular指令的引用。

    Jerry Wang
  • Flink是如何kafka读取数据的

    版权声明:本文为博主原创,欢迎转载,转载请标明出处 Blog Address:http://blog.csdn.net/jsjsjs1789 https...

    shengjk1
  • Spring_总结_04_高级配置(二)之条件注解@Conditional

    在上一节,我们了解到 Profile 为不同环境下使用不同的配置提供了支持,那么Profile到底是如何实现的呢?其实Profile正是通过条件注解来实现的。

    shirayner
  • PAT (Advanced Level) Practice 1039 Course List for Student (25分)

    Zhejiang University has 40000 students and provides 2500 courses. Now given the ...

    glm233

扫码关注云+社区

领取腾讯云代金券