zoukankan      html  css  js  c++  java
  • 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:

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

  • 相关阅读:
    [BZOJ1934][Shoi2007]Vote 善意的投票[最小割]
    [BZOJ1066][SCOI2007]蜥蜴[最大流]
    [BZOJ2818][P2568]Gcd[欧拉函数]
    [BZOJ2208][P4306][JSOI2010]连通数[bitset优化floyd]
    [BZOJ1877][SDOI2009]晨跑[最大流+费用流]
    [BZOJ1040][P2607][ZJOI2008]骑士[树形DP+基环树]
    [BZOJ5347]冒泡排序[思维]
    [BZOJ2875][Noi2012]随机数生成器[等比数列求和+取模]
    [bzoj2809] 派遣
    [bzoj1965] 洗牌
  • 原文地址:https://www.cnblogs.com/sap-jerry/p/13540507.html
Copyright © 2011-2022 走看看