這篇文章將為大家詳細講解有關(guān)SAP Cloud for Customer里Promise的實際應(yīng)用場合是怎樣的,文章內(nèi)容質(zhì)量較高,因此小編分享給大家做個參考,希望大家閱讀完這篇文章后對相關(guān)知識有一定的了解。
成都創(chuàng)新互聯(lián)公司是一家專業(yè)提供通道企業(yè)網(wǎng)站建設(shè),專注與成都做網(wǎng)站、網(wǎng)站制作、H5頁面制作、小程序制作等業(yè)務(wù)。10年已為通道眾多企業(yè)、政府機構(gòu)等服務(wù)。創(chuàng)新互聯(lián)專業(yè)網(wǎng)站建設(shè)公司優(yōu)惠進行中。
最近,我正在研究SAP Cloud for Customer的前端代碼,我遇到了一個如何在那里使用promise的真實示例。下面是密碼登錄視圖。
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.
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:
關(guān)于SAP Cloud for Customer里Promise的實際應(yīng)用場合是怎樣的就分享到這里了,希望以上內(nèi)容可以對大家有一定的幫助,可以學到更多知識。如果覺得文章不錯,可以把它分享出去讓更多的人看到。