Introducing the UI manager

At some point, we will need to have a class that is responsible for the workflow of the user experience. For example, when a user clicks on the Add to cart button, the product has to be added to the cart at the server level and the user interface has to be updated.

The UI manager takes responsibility for managing the workflow of the user experience, handling all communication with the server when needed, and is used as an entry point to start the Scala.js code. This is the main entry point of our client application when the application is executed in the browser.

For communicating with the server, we are going to use jQuery. This JavaScript library is widely used and is a reference in the JavaScript world.

This is one of the advantages of Scala.js. We can use existing JavaScript libraries, such as jQuery, from Scala. To use existing JavaScript libraries, we only need to define an interface, which is called a facade in Scala.js. The facade can be seen as an interface to redefine the JavaScript type and the JavaScript function signature. It means we need a facade for all of the JavaScript libraries we want to use. Fortunately, there are already a number of facades that already exist for the most important JavaScript frameworks. A list of available facades can be found at the Scala website (https://www.scala-js.org/libraries/facades.html).

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset