How do you use asynchronous ORMs without huge callback chains?

I use the relatively immature Joose Javascript ORM plugin ( project page ) to save objects in the Appcelerator Titanium ( company page ) mobile project. Since this is client-side storage, the application must check if the database is initialized before running ORM, as it checks the database tables to create classes.

My problem is that this sequence of operations (and if so, other things along the way) requires a lot of callbacks to complete. I jump a lot in the code, which is not obvious to the maintainer, and leads to some complicated call schedules and something else. Therefore, I ask the following questions:

  • How would you asynchronously initialize a database and populate it with seed using ORM, for the schema to work correctly?
  • Do you have any general strategies or links for asynchronous / event-driven programming, and keep the call graph simple and straightforward?
  • Do you have any suggestions for Javascript ORMs / metaobject systems that work with HTML 5 as a data storage mechanism and hopefully are agnostics?
  • Am I just a big newbie and should be able to handle this with ease?

Thanks guys!

+4
source share
2 answers

Try flow.js (https://github.com/willconant/flow-js).

+2
source

Take a look at NarrativeJS :

Narrative JavaScript is a small extension of the JavaScript language that allows you to block the possibility of asynchronous event callbacks. This updates asynchronous code readable and understandable.

Using descriptive JavaScript, a document is selected using XmlHttp as follows:

function handleResponse(responseText) { document.getElementById("myElem").innerHTML = responseText; } fetch("http://www.url.com/", handleResponse); 

:

 document.getElementById("myElem").innerHTML = fetch->("http://www.url.com/"); 

Too bad that the project is no longer active: - (

dojo.Deferred () also seems to implement an asynchronous monad, although the syntax is not as clear as NarrativeJS.

Some work was done to cast asynchronous sugar in CoffeeScript , but it was ultimately not accepted .

RxJS is another one that deals with this.

+1
source

Source: https://habr.com/ru/post/1304316/


All Articles