Scala.js and unidirectional data flow 2

Scala.js and unidirectional data flow 2

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,

Continue Reading

Scala.js and unidirectional data flow

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

Continue Reading

Designing facades in Scala.js

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

Continue Reading

Slider 2: a JavaScript object instead of case classes

Slider 2: a JavaScript object instead of case classes

Two weeks ago we talked about how to create a beautiful Slider in Scala.js Our Slider works well (See Demo). But there was one thing that worried me. We need to define a Slider property as a Scala case class. It’s not bad, if our Slider is a part of a single Scala/Scala.js application. But what if we need to install our Slider into some HTML page. In that situation we should think how to pass some JavaScript object into the Slider. At first sight this is a frightening problem. It turned out that it is not. All we need

Continue Reading

ScalaCSS. Is it time for using it?

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

Continue Reading

Let’s create a Slider

Let’s create a Slider

I have started to write code on Scala.js half a year ago and I can’t stop doing it. I should say that I love JavaScript and I wrote hundreds of thousands lines of code. But there is one thing that always frustrates me in JavaScript: It hasn’t many useful things that other languages have. You should use some or other framework (I used yui and jquery in the past). I used CoffeeScript a year ago. Today it’s time for Babel. Nobody wants writing plain JavaScript anymore! I choose Scala. See the Demo to this post. A Slider is a program

Continue Reading

Learn You Scala for Great Good! Part 6

Learn You Scala for Great Good! Part 6

Today I want to finish this long talk about Haskell and Scala.  The only thing that  stays in my to-do list is  “A knight’s quest”. Please look at my previous posts: Learn You Scala for Great Good! Learn You Scala for Great Good! Part 2 Learn You Scala for Great Good! Part 3 Learn You Scala for Great Good! Part 4 Learn You Scala for Great Good! Part 5 A knight’s quest Here’s a problem that really lends itself to being solved with non-determinism. Say you have a chess board and only one knight piece on it. We want to

Continue Reading

Learn You Scala for Great Good! Part 5

Scala and Haskell are both good for functional programming. And in some cases their approaches for problems solving are very similar. This is my fifth post of this theme. The idea of writing this series appeared when I was looking for a book about functional programming in Scala. It happened that I found Learn You Haskell for Great Good – the great book about Haskell. I started reading it. Today I want to take some examples from the Higher order functions Chapter of this book Please look at my previous posts: Learn You Scala for Great Good! Learn You Scala

Continue Reading

Learn You Scala for Great Good! Part 4

It’s my fourth post of the series where I told how I started studying Haskell in order to get knowledge in functional programming in Scala. You may see previous posts on this theme: Learn You Scala for Great Good! Learn You Scala for Great Good! Part 2 Learn You Scala for Great Good! Part 3 Today I want to take the three last examples from the Recursion Chapter. zip function It takes two lists and zips them together. zip [1,2,3] [2,3] returns [(1,2),(2,3)], because it truncates the longer list to match the length of the shorter one. Haskell zip ::

Continue Reading

String calculation effect in JavaScript

In one of my posts I wrote about the Strong-Password Plugin. The secret of its attractiveness lays in usage of interesting effect: a new password is being calculated on the eyes of the visitor. Let’s discuss how to create such an effect. We need a function that will generate our effect of “string calculation”.  I named it generate. var generate = function(str, result, from, delay) { // Our code will be here…. } Our function takes four parameters, the first two are required. str – it’s a string that  will be shown at the end (the result of calculations) result

Continue Reading