专栏首页Jerry的SAP技术分享SAP UI5 CRM Reuse Fiori应用 note.js代码审查结果

SAP UI5 CRM Reuse Fiori应用 note.js代码审查结果

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

目录

1. Unused require statement

Line4 could be deleted.

2. Unused code _dateBound = true

Is this _dateBound really still needed? Is it previously introduced for lifecycle issue solution?

Comment by Jerry on 2015-01-23 17:00PM OK I am wrong.

3. Robustness of sap.cus.crm.lib.reuse.controls.Note.prototype.setModel

It is better not to make any assumptions that the consumer will call this method setModel as we expected. Is there any possibility that all the internal reference like _noteTypeItemTemplate is still not initialized. In this case, the method execution will cause javascript error.

4. This.getModel() VS model

Why not use model.getProperty directly? I have verified in debugger, there are exactly the same reference?

5. Naming convention

We can not judge the real content contained in these two variables at a first glance – A little confused about the meaning of noteType and _noteType.

Is it possible to add more information inline to variable _noteType, for example change _noteType To _oNoteTypeSelect, so that the one who reads the source code could immediately know it is a reference for select control?

6. Not necessary to loop the whole data set every time to get language description

It is possible to have an inner buffer and every time we first try if the corresponding language description is already in inner buffer already:

If ( oLanguageDescriptionSet[languageCode] ) {
return oLanguageDescriptionSet[languageCode];
}
else {
// old logic
oLanguageDescriptionSet[languageCode] = <fetched description via loop>
}

Another example is setAggregation implementation by ui5 framework: Get:

Set:

This logic is widely used in ui5 framework:

7. Unnecessary variable isDefault

Previously I assume there is some logic on isDefault like if ( XXX ) { isDefault = true } else { isDefault = false }

But actually it is not. Why not directly pass a true in line 51?

8. Define constant

Can we define some “constant” in init method to avoid resourceBundle call repeatedly? For example, in init method, Var EDIT_NOTE_DIALOG_TITLE = this.oResourceBundle.getText(“EDIT_NOTE_DIALOG_TITLE”);

9. Unnecessary variable

Use return new sap.ui.model.json.JSONModel(oData) instead. Comment by Jerry on 2015-01-23 17:15PM Not necessary to change: 因为发现UI5的框架代码也这样用的:

10. Nested if

A little bit ugly, can we use the following one?

If( changeType === “” ) && ( !this._hasNote(noteType, code)) {
       Languages.push(instance);
}

11. Is jQuery.proxy really necessary?

Haven’t yet measured the overhead of jQuery.proxy.

Some open source framework just use the following approach to avoid the additional jQuery.proxy call:

Also our own ui5 framework implementation: doSo

12. Magic number

Can we use “constant” to avoid this magic number?

13. Better variable name?

After I go through the whole source code, I get to know that for note creation and edit case, we use the same dialog instance, right? So _noteCreateDialog could be used both for create and Edit case? In that case, it is better to rename _noteCreateDialog as _noteOperationDialog?

In the code below, it may confuse reader that the _getDialog can only construct Dialog for creation purpose.

14. Inconsistent naming convention

Sometimes we use prefix o to indicate the variable has object type, sometimes not, e.g noteCreateDialog.

15. Better method name

The below method assembles and finally return a model for given purpose – note creation and update.

Normally, we have two styles below:

Void doSomething() {  
      // do something 
.. } 

<return type> getSomething()  { 
      // prepare something 
 Return something; 
} 

So better name like getCalculatedModel4AddNoteDialog. Comment by Jerry on 2015-01-23 17:14PM Just see a similar usage as ours in JSONModel,js …. , so not necessary to change?

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

我来说两句

0 条评论
登录 后参与评论

相关文章

  • SAP Hybris Commerce功能介绍:Consignment tracking

    This new feature is developed by Chengdu Hybris dev team. When a customer decide...

    Jerry Wang
  • How to suppress the annoying line break error in WebIDE

    This error is very annoying. There are different line break settings in unix ( L...

    Jerry Wang
  • SAP Fiori里的两种锁机制

    This approach is used in SAP CRM Fiori. Suppose user Jerry has opened a given o...

    Jerry Wang
  • Top 5 Business Messaging Announcements at Facebook F8 2019

    Top 5 Business Messaging Announcements at Facebook F8 2019

    Spanz
  • Kit 3D 更新

    Kit3D is a 3D graphics engine written for Microsoft Silverlight. Kit3D was inita...

    用户1172164
  • NestJs 静态目录配置

    由于官方文档没有做详细解释说明,那么我们可以从此框架底层入手: 我们知道,nestjs底层用的是express,那么express是通过什么来完成静态目录构建...

    stormKid
  • 面试官怎么看你的Github profile

    Udacity的Machine Learning纳米学位课程中,关于Github的笔记。 听课范围: Github Profile Git 和 Github...

    杨熹
  • Learn Android Studio 3Android architectureAndroid ComponentsDesign editor.pngKeyboard Shortcuts for

    iOSDevLog
  • GTX 1080+Ubuntu16.04+CUDA8.0+cuDNN5.0+TensorFlow

    GTX 1080+Ubuntu16.04+CUDA8.0+cuDNN5.0+TensorFlow 安装指导

    用户1908973
  • spark的一些小总结

    首先,DAG是MR的迭代模型。其中一个优点是,DAG可以做全局的优化,而Hadoop的MR没有意识到这点。

    哒呵呵

扫码关注云+社区

领取腾讯云代金券