Tags: scala.js
Scala.js and Algebraic Data Types
Last time I started the discourse about the place of Scala in front-end development. My point, roughly , is that it should take business logic and leave view rendering to JavaScript. But some difficulties can appear while someone tries to bind both languages together. In my previous post I talked about Scala – JavaScript classes two-way conversion. Today I’m going to make one step further and take an example with Algebraic Data Types. Say, we have to develop an application that helps to deal with stock trading. We will buy and sell assets and our program will keep all records
Scala – JavaScript class conversion example
Scala is a great language. We are lucky to use it not only for back-end development but also in front-end. That’s cool, but it’s an illusion that one can create the whole front-end by solely using Scala.js. Of course, it’s possible. And one could develop the great application. I won’t argue about that. But my point is: we should use the strong parts of Scala in conjunction with strong parts of JavaScript. We all love Scala for many things. If we need to realize business logic, we will choose Scala.js . But what about view rendering, appearance, visual effects, styles,
Scala.js With Monix Example
One of the annoying thing in front-end development is managing long calculations in a browser. JavaScript does things synchronously, and when you want to do something, that needs time for execution, JavaScript resists. Here is an example of such long calculation. At first, I shall demonstrate synchronous code, then asynchronous. Scala has the great library Monix, that works well with Scala.js. I have already told about Monix in some of my previous posts. Of cause, I’m going to use this library in my asynchronous example. My son goes to school. One time he was doing his math homework and he
Scala.js and unidirectional data flow 2
Last time we talked about using Monix as a tool of creating unidirectional data flow in Scala.js applications. The tiny Dispatcher class was made for that purpose. We considered the Counter example, which demonstrated all the power of this approach. Today I intend to widen our horizons and to consider another example: more complex one: which will demonstrate not only usage of the Dispatcher but also usage of Sortable.js with React. But before that I want to add some new methods to the Dispatcher class. Here is the full code of the Dispatcher class: import monix.execution.Ack import monix.execution.Ack.Continue import monix.reactive.{Observable,
Scala.js and unidirectional data flow
During the last two years the one of the most popular subjects for discussion in the JavaScript society is so-called “unidirectional data flow”. Those happy years, when we used JavaScript for organizing of some effect on the page or for loading some widget by Ajax, gone to the past. Today JavaScript is used for building client-side web applications. There are several frameworks for doing such things. I used React in my last projects. It’s a great library. It allows doing everything you want. Except unidirectional data flow. You have to use Flux or Redux for that purpose. But what about
Designing facades in Scala.js
Scala.js builds a bridge from the Scala world to the JavaScript world. Today Scala developers can take all the magic of Scala with many powerful libraries and use it in front-end applications. But after passing the bridge our developer suddenly might find himself in very different environment. Does he know something about transition animation, or about event system on mobile devises? Fortunately JavaScript itself is ready to give a huge bulk of awesome libraries for all cases. All we need to do is to find an appropriate library and write a facade. You can find this in the Scala.js documentation: When
ScalaCSS. Is it time for using it?
I decided to go further with my Slider and to find out whether my styles can be generated by Scala. First of all, I added ScalaCSS library and an extension for Scalajs-react to my dependencies: libraryDependencies += “com.github.japgolly.scalacss” %%% “core” % “0.5.1” libraryDependencies += “com.github.japgolly.scalacss” %%% “ext-react” % “0.5.1” ScalaCSS has two ways of making styles: To make standalone stylesheets (like SASS or LESS) To add css-styles directly to the page by a compiled javascript Standalone stylesheets As it was written in the ScalaCSS manual: Produces static CSS for external consumption. Like SCSS and LESS. There is only one