关于SAP UI5 CRM Reuse Fiori应用的代码审查

76 阅读1分钟

目录

clipboard1

1. Question about maven build output

clipboard2

If we open the target folder:
What is exactly the usage of these four parts?

下图这四种资源有什么用处?

clipboard3

Reason why I asked: the content between 1 and 2 are the same, 3 and 4 are the same.

2. Useless CSS style

Are these CSS styles still used?

clipboard4

上面的CSS似乎没有用到。

I don’t think so since a pure text search shows no *.js are using them.

clipboard5

3. Why we choose sap.m.panel as aggregation container?

clipboard6

I know the children element contained in the aggregation would also be rendered in the runtime:

clipboard7

包含在这些aggregation的子控件在运行时被渲染。

clipboard8

However, why we choose panel as placeholder but not other one like XXXlayout?

4. Unnecessary require statement about “…NonLogTypeNoteListItem”

clipboard9

clipboard10

clipboard11

5. Duplicate code in two IF branch

clipboard12

6. Unused comment

clipboard13

It could be deleted now

7. Confusing variable name

clipboard14

Should be noteEditDialog instead.

8. Magic number still exists

clipboard15

9. Better constant definition approach

Follow this design:

clipboard16

Use this instead:

clipboard17

10. Hard code text cannot be translated

clipboard18

11. Performance of this.getProperty

Take this code for example:

clipboard19

In the runtime lifecycle, the value of these properties can never change:

clipboard20

clipboard21

Do a performance test on this.getProperty:

在this.getProperty方法加上性能数据的采集:

clipboard22

clipboard23

After clicking add button, there are more than 1200 times getProperty call, actually most can be avoided.

发现随便点击一个Add按钮,会触发一千多次的getProperty调用。而大多数其实都可以避免的。

clipboard24

clipboard25

If we call getProperty on these properties once in init, we can save 1200 * 0.5 = 0.6s

如果我们在onInit里只调用一次getProperty,然后把结果缓存起来,就可以节省1200 * 0.5 = 0.6s的时间。

12. Unused argument

clipboard26

13. Lengthy code

Didn’t try in js yet, can we use “return ( oValue1 – oValue2 )”?

clipboard27

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