1
Build your React
component in scala
By Poorva Gokhale & Mushtaq Ahmed
● Catch type related errors early (compile time)
● Types serves as a documentation
● Reliable refactoring
● Better IDE support
● Type systems make code easier to maintain
Why to use type system?
● Typescript - compiles to javascript (same
semantics)
● Flow - type checker
● Scala.js- Cross Platform - compiles to
javascript
● Kotlin - Cross Platform
Ways for Static typing in Javascript
Scala(js) - cross platform language
Compiles to jvm and javascript
● All advantages of static typing
● Shared code
● Interoperability
● Performance
● Access to scala ecosystem libraries
Project Setup
● Setup
● React4s - React wrapper for scala.js
○ Lifecycle methods
○ State
○ Props
○ Emit handler - callback
● Generate js - fastOptJS
● Bundling - webpack and scalajs-bundler
● Css Support
Scala.js - shared code
● Share your code between frontend and backend
● Models
● Shared api
- Serialization logic
- models
Interoperability
Scala.js Javascript
JsExport/SJS-Defined
JsImport
Javascript
Typescript
.d.ts (typescript definition file)
Compiles to javascript
- Scala.js compiler optimizes generated javascript
- Inlining
- Rewrite iterators as while loops
- Dead code elimination
- Comparable performance with handwritten js
application
Performance
● Scala cross compiling libraries
○ Upickle
○ Scala-java-time
● Js libraries for scala.js
○ Scala-js-dom
○ jquery-facade
Access to scala ecosystem libraries
Typescript and scala.js competitors, but coming from
scala background and having rich set of features like
interoperability, available libraries we find scala.js
promising.
Conclusion
● https://www.scala-js.org/
● http://www.react4s.org/
● https://scalacenter.github.io/scalajs-bundler/
References
THANK YOU
Mushtaq Ahmed
Developer, ThoughtWorks
mushtaq@thoughtworks.com
github.com/mushtaq
Poorva Gokhale
Developer, ThoughtWorks
poorvag@thoughtworks.com
github.com/Poorva17

React Component in scala.js

  • 1.
  • 2.
    Build your React componentin scala By Poorva Gokhale & Mushtaq Ahmed
  • 3.
    ● Catch typerelated errors early (compile time) ● Types serves as a documentation ● Reliable refactoring ● Better IDE support ● Type systems make code easier to maintain Why to use type system?
  • 4.
    ● Typescript -compiles to javascript (same semantics) ● Flow - type checker ● Scala.js- Cross Platform - compiles to javascript ● Kotlin - Cross Platform Ways for Static typing in Javascript
  • 5.
    Scala(js) - crossplatform language Compiles to jvm and javascript ● All advantages of static typing ● Shared code ● Interoperability ● Performance ● Access to scala ecosystem libraries
  • 6.
    Project Setup ● Setup ●React4s - React wrapper for scala.js ○ Lifecycle methods ○ State ○ Props ○ Emit handler - callback ● Generate js - fastOptJS ● Bundling - webpack and scalajs-bundler ● Css Support
  • 7.
    Scala.js - sharedcode ● Share your code between frontend and backend ● Models ● Shared api - Serialization logic - models
  • 8.
  • 9.
    - Scala.js compileroptimizes generated javascript - Inlining - Rewrite iterators as while loops - Dead code elimination - Comparable performance with handwritten js application Performance
  • 10.
    ● Scala crosscompiling libraries ○ Upickle ○ Scala-java-time ● Js libraries for scala.js ○ Scala-js-dom ○ jquery-facade Access to scala ecosystem libraries
  • 11.
    Typescript and scala.jscompetitors, but coming from scala background and having rich set of features like interoperability, available libraries we find scala.js promising. Conclusion
  • 12.
    ● https://www.scala-js.org/ ● http://www.react4s.org/ ●https://scalacenter.github.io/scalajs-bundler/ References
  • 13.
    THANK YOU Mushtaq Ahmed Developer,ThoughtWorks mushtaq@thoughtworks.com github.com/mushtaq Poorva Gokhale Developer, ThoughtWorks poorvag@thoughtworks.com github.com/Poorva17