SAP Cloud for Customer框架是如何使用JavaScript Promise的

简介: SAP Cloud for Customer框架是如何使用JavaScript Promise的

There are lots of tutorials 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.image.pngOnce 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.image.pngCurrently 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.image.pngThe 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.image.pngAll 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:image.pngimage.pngimage.pngOpen 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.

image.pngIn 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.image.pngThe 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.image.pngEven in C4C frontend framework code we can see more and more usage on IndexedDB instead:image.pngSee the comparison on these two techniques from this link Migrating your WebSQL DB to IndexedDB.



image.png








image.png

相关文章
|
1月前
|
开发框架 JavaScript 安全
js开发:请解释什么是Express框架,以及它在项目中的作用。
Express是Node.js的Web开发框架,简化路由管理,支持HTTP请求处理。它采用中间件系统增强功能,如日志和错误处理,集成多种模板引擎(EJS、Jade、Pug)用于HTML渲染,并提供安全中间件提升应用安全性。其可扩展性允许选用合适插件扩展功能,加速开发进程。
|
1月前
|
前端开发 JavaScript
如何处理 JavaScript 中的异步操作和 Promise?
如何处理 JavaScript 中的异步操作和 Promise?
15 1
|
1月前
|
前端开发 JavaScript
在JavaScript中,什么是promise、怎么使用promise、怎么手写promise
在JavaScript中,什么是promise、怎么使用promise、怎么手写promise
25 4
|
1月前
|
前端开发 JavaScript 开发者
JavaScript 中的异步编程:Promise 和 Async/Await
在现代的 JavaScript 开发中,异步编程是至关重要的。本文将介绍 JavaScript 中的异步编程概念,重点讨论 Promise 和 Async/Await 这两种常见的处理异步操作的方法。通过本文的阐述,读者将能够更好地理解和应用这些技术,提高自己在 JavaScript 开发中处理异步任务的能力。
|
13天前
|
JavaScript 前端开发 API
框架分析(3)-Vue.js
框架分析(3)-Vue.js
|
18天前
|
安全 UED 开发者
SAP Commerce Cloud 配置项 refreshWithLock=false 的作用介绍
SAP Commerce Cloud 配置项 refreshWithLock=false 的作用介绍
18 0
|
18天前
|
Java BI API
SAP Cloud for Customer 里如何通过 ABSL 二次开发方式消费 SAP S/4HANA 系统的 API
SAP Cloud for Customer 里如何通过 ABSL 二次开发方式消费 SAP S/4HANA 系统的 API
14 0
|
1月前
|
前端开发 JavaScript
js开发:请解释Promise是什么,以及它如何解决回调地狱(callback hell)问题。
Promise是JavaScript解决异步操作回调地狱的工具,代表未来可能完成的值。传统的回调函数嵌套导致代码难以维护,而Promise通过链式调用`.then()`和`.catch()`使异步流程清晰扁平。每个异步操作封装为Promise,成功时`.then()`传递结果,出错时`.catch()`捕获异常。ES6的`async/await`进一步简化Promise的使用,使异步代码更接近同步风格。
19 1
|
1月前
|
前端开发 JavaScript 机器人
详解《基于 javascript 的流程图编辑框架LogicFlow
详解《基于 javascript 的流程图编辑框架LogicFlow
62 0
|
1月前
|
存储 设计模式 数据库
SAP ABAP 框架如何判断一个类是 AMDP 类
SAP ABAP 框架如何判断一个类是 AMDP 类
25 0