TypeScript: defining a top-level function

Month: March 2017

TypeScript: defining a top-level function

I use Lift as a web framework. Lift allows to generate JavaScript code and than to execute it on the page. I needed to execute a JavaScript function from that generated code. Since I use TypeScript for frontend development, I faced a problem here: How to create a global scoped function? Something like: window.myFunction = function(){ // … }   Fortunately, I found a trick. Behold: ;( <any> window).myFunction = function():void { // … }   For TSX: ;( window as any).myFunction = function():void { // … }   Now you can call this function from JavaScript inside <script> tags

Continue Reading

Let’s create a Slider. Again…

Let’s create a Slider. Again…

There have been three posts about creating a Slider with Scala.js already. The first post was about how to do it in principal. The second post was about the ScalaCSS library in general and how one could use it with our Slider in particular. The third post was about how to use a JSON object with our Slider. Now it’s time to compare Scala.js with its closest alternative: I mean TypeScript (a typed superset of JavaScript that compiles to plain JavaScript). It’s fun: the first version of this Slider was written in CoffeeScript. It took me about 3 hours. I

Continue Reading

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