In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/01 Report--
This article will explain in detail about the actual application of Promise in SAP Cloud for Customer. The content of the article is of high quality, so the editor will share it with you for reference. I hope you will have a certain understanding of the relevant knowledge after reading this article.
Recently, I was studying the front-end code for SAP Cloud for Customer, and I came across a real example of how to use promise there. The following is the password login 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:
Var end;function setupDB () {return this.createDatabase (). Then (createTable). Then (readEntry). Then (printResult);} function createTable () {return new Promise (function (resovle, reject) {console.log ("prepare to create table..." + Date.now ()); this._db.transaction (function (query) {query.executeSql ('create table if not exists user (id unique, user, passwd)') }); setTimeout (_ createTableOK.bind (this, resovle), 1000);} function _ createTableOK (resovle) {console.log ("table created successfully..." + Date.now ()); resovle ();} function createDatabase () {return new Promise (function (resovle, reject) {console.log ("prepare to create database..." + Date.now ()) This._db = openDatabase ('mydb','1.0',' JerryTestdb',1024); setTimeout (_ createDatabaseOK.bind (this, resovle), 1000);} function _ createDatabaseOK (resovle) {console.log ("database created successfully..." + Date.now ()); resovle (this._db) } function insertEntry () {return new Promise (function (resolve, reject) {this._db.transaction (function (query) {query.executeSql ("insert into user values (1 # this, resolve), 1000));} function _ insertEntryOK (resolve) {console.log (" entry inserted to table successfully... "+ Date.now ()) Resolve ();} function readEntry () {return new Promise (function (resolve, reject) {this._db.transaction (function (query) {query.executeSql ('select * from user', [], function (ucharge results) {setTimeout (_ readEntryOK.bind (this, resolve, results), 1000);}) / / end of query.executeSql} / / end of function (query); / / end of this._db.transaction});} function _ readEntryOK (resolve, oResult) {console.log ("entry readed from DB successfully..." + Date.now ()); resolve (oResult);} function printResult (oResults) {for (var I = 0; I < oResults.rows.length) ) {[xss_clean] ln ('id:'+ oResults.rows [I] .id); [xss_clean] ln ('user:' + oResults.rows [I] .user); [xss_clean] ln ('passwd:' + oResults.rows [I] .passwd);} end = true;} function work () {if (end) {clearInterval (handle) } else {console.log ("working..." + Date.now ());}} setupDB (); var handle = setInterval (work, 200)
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:
About the actual application of Promise in SAP Cloud for Customer is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.