scala.js for large and complex frontend apps

18
Scala.js for large and complex frontend apps by Otto Chrons, 2016-05-26 @ochrons - [email protected]

Upload: otto-chrons

Post on 25-Jan-2017

1.162 views

Category:

Software


0 download

TRANSCRIPT

Page 1: Scala.js for large and complex frontend apps

Scala.js for large and complex frontend apps

by Otto Chrons, 2016-05-26@ochrons - [email protected]

Page 2: Scala.js for large and complex frontend apps

What does this JavaScript do?var xhr = new XMLHttpRequest()

xhr.open("GET", "https://api.twitter.com/1.1/search/" + "tweets.json?q=%23scalajs")xhr.onload = (e: Event) => { if (xhr.status == 200) { var r = JSON.parse(xhr.responseText) $("#tweets").html(parseTweets(r)) }}xhr.send()

Page 3: Scala.js for large and complex frontend apps

Is it actually JavaScript? Look again!var xhr = new XMLHttpRequest()

xhr.open("GET", "https://api.twitter.com/1.1/search/" + "tweets.json?q=%23scalajs")xhr.onload = (e: Event) => { if (xhr.status == 200) { var r = JSON.parse(xhr.responseText) $("#tweets").html(parseTweets(r)) }}xhr.send()

It's strongly typed Scala,really!

Page 4: Scala.js for large and complex frontend apps

What is Scala.js?Write Scala, compile to JavaScript, run in browserFull support of Scala languageStraightforward JavaScript interoperabilityAs fast code as hand-written JavaScriptGenerated JS code is "small enough"Fast edit-compile-run cycle

Page 5: Scala.js for large and complex frontend apps

Live Demo

Page 6: Scala.js for large and complex frontend apps

Everyone wants a better JavaScriptSaferMore modular, expressive, reusable codeOne language across client/serverMore tool-able & better IDE support

All JS libraries should be authored in TypeScript

- André Staltz, author of Cycle.js

Page 7: Scala.js for large and complex frontend apps

Why now?Front end evolution

Stone ageaka

JQuery era

Server-rendered HTML pagesSimple JS animationsAjax calls to serverDirect DOM manipulation

Medieval times

Rise of the Single Page AppHTML template drivenREST APIs

Angular, Backbone, Ember, ...

Renaissance

JS centric complex appsDOM is code-generatedGraphQL, FalcorRise of transpilers: TS, Babel

React, Angular 2, ...

Page 8: Scala.js for large and complex frontend apps

Next generationModern times

Rise of new languages: Scala, Clojure, Elm, TSComplex client-server systems with shared codeJS reduced to a compile target and a platformCross-platform: mobile and web

Page 9: Scala.js for large and complex frontend apps

Large and complex frontend appsDefined by

Large code base, 10+kLoC

All UI functionality defined in JavaScript, a Single Page App using a JS framework like React, Angular2, Ember

Complex interactions with the server: streams, reactive, Falcor, GraphQL

Offline support, sharing business logic code with server

Large development team

Page 10: Scala.js for large and complex frontend apps

ChallengesAdopting a large code base

Finding your way around the code

RefactoringMaking changes without breaking stuff

Client-server communicationKeeping client and server data models in sync

Page 11: Scala.js for large and complex frontend apps

Managing large frontend apps

JavaScript Scala.js

Typing TypeScript, Flow Built-in

Functional React, Flux, Redux, Cycle.js

Built-in

Immutability Immutable.js, Seamless-Immutable Built-in

Tooling Gulp, Bower, Babel, JSX, npm, Webpack, Browserify

SBT

Page 12: Scala.js for large and complex frontend apps

Live Demo

Page 13: Scala.js for large and complex frontend apps

What do JS developers get from Scala.js?Everything in ES6/7 (=>, destructuring, string-interpolation, ...)Everything in TypeScript (types, generics, ...)Everything in Immutable.js (immutable collections)

+Great language, extensive standard library, functional programming, access to all JS libs and peace of mind 😌

Page 14: Scala.js for large and complex frontend apps

Why Scala.js?

Stack Overflow Developer Survey 2016: Most Loved

Page 15: Scala.js for large and complex frontend apps

Why Scala.js?

Stack Overflow Developer Survey 2016: Top Paying Tech

Page 16: Scala.js for large and complex frontend apps

Why Scala.js?Syntax similar to JavaScript, you can get started easilySuperb IDE supportLearning Scala makes you a better JavaScript programmer!Broad and active ecosystemProduction ready

Page 17: Scala.js for large and complex frontend apps

Large Scala.js apps in the wildQuerki - open source online information tool - 9k LoC

Metabolicanalyzer - 14k LoC

App.theseventhsense.com - 9k LoC

Network management GUI - 31k LoC

Finance-tech app - 31k LoC (UI) + 20k LoC (shared)

Page 18: Scala.js for large and complex frontend apps

How to get started?

www.scala-js.org

Gitter room

https://gitter.im/scala-js/scala-js