SAP Cloud for Customer里一个Promise的实际应用场合
发布日期:2021-06-30 14:20:23 浏览次数:3 分类:技术文章

本文共 2253 字,大约阅读时间需要 7 分钟。

There are lots of about promise in the internet.

Recently I am studying the frontend code of SAP Cloud for Customer and I come across a real example of how promise is used there.

Below is the Passcode logon view.

Once Passcode is entered, suppose I have already entered the system url and frontend user name in the past, they will be directly retrieved from browser storage.

Currently I use Chrome to access C4C and Web SQL is used as browser storage, where the system url and logon user name could be found from Chrome development tool.

The corresponding database initialization and table read is done by code below in file AppStatusService.js.

The series of callback functions are chained by promise API “then()” which are expected to be executed sequentially:

(1) _createTable() could only be executed after database initialization is done.

(2) _getApplicationStatus could NOT be executed unless the database table which stores Application status is available – this is ensured by _createTable.
(3) After application status is read from database table, _createDefaultEntries could be called to render the default value in Passcode logon view.

All above three steps are organized by promise to achieve the asynchronous execution mode.

In order for me to understand how the above code works, I write a simplified version for illustration:

Open the html page with Chrome, and you can find that a database with name mydb and a table user is created with one record inserted.

In order to achieve the simulation that each step of webSQL is a time-consuming operation, I wrap the real logic into setTimeout with a certain time delay.

I scheduled function work to simulate the main work to do and the database related job are done in an asynchronous way organized within function module setupDB() by promise API.

The console output proves that the database operations are really executed asynchronously in exactly the same order as they are scheduled via then API of promise.

Note

Not all browsers support WebSQL and the specification of WebSQL is no longer in active maintenance.

Even in C4C frontend framework code we can see more and more usage on IndexedDB instead:

See the comparison on these two techniques from this link .

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

转载地址:https://jerry.blog.csdn.net/article/details/105947779 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:SAP CRM WebUI, CRM Fiori和C4C里的Direct Navigation
下一篇:SAP UI5和Vue的双向绑定比较

发表评论

最新留言

不错!
[***.144.177.141]2024年04月22日 13时04分41秒