Visar inlägg med etikett scalajs. Visa alla inlägg
Visar inlägg med etikett scalajs. Visa alla inlägg

2018-09-20

Updated Scala Stack With Angular

News

Updated Scala Stack with Angular and made it cleaner. It uses a servlet with a Scala JS compiler to compile ScalaJS code on the fly!

About

Scala Stack is using Google App Engine, Maven and AngularJS, but only with Scala code! Both backend and frontend is written in Scala. HTML and CSS is generated from Scala code.
Note that no pre-processors or SBT are used. Backend compiles at publish and Javascripts at startup.
You can read more at my earlier blog post:

Repository

Check it out:

2018-01-02

Compiling JavaScript on Serverside With Scala and ScalaJS using Google Standard App Engine

Compiling JavaScript on Serverside With Scala and ScalaJS using Google Standard App Engine 

Since my experience with the JavaScript world and exploration of ScalaJS I felt compelled to move from Node and Grunt and try to fully utilize Scala for both front and back.
I reached a goal with Scala Stack, a concept of creating all web content on serverside using only Scala code. The concept is extended to keep everything in code including configuration to be fully testable.

Obvious Advantages

My main purpose was to skip the JavaScript world but it moved on to something much larger. If all code is shared there are quite a few advantages
  • Single, isomorphic source which ease work and can share logic
  • Share data by keeping it in code. For instance languages could be defined with a Enum type
  • Fully testable code
  • No JavaScript package manager like NPM or WebPack
  • No pre processor like Gulp or Grunt
  • No SBT since the compilation is with a simple Servlet  

Risks

There are some traps though 
  • Security, some code should not be shared between backend and frontend
  • Long term effects, demands an experienced architect 
  • Shared code needs to be ScalaJS compatible and cannot use backend dependencies since it's compiled and used on frontend

Scala Stack

Map of Scala Stack

I've made three implementations using Google Standard Environment with Java 8. Implemented in native JavaScript, jQuery and AngularJS.
Goal is to keep everything in code and to avoid configuration, annotations and settings in Strings.
By only using Scala on serverside, it produce HTML, CSS and JavaScript which is all components for a webpage. 

Scala Stack with Angular

You find links to code and running example below

Servlet Compiler

Scala Stack is using a Servlet compiler with different logging:

2017-06-08

Compiling JavaScript on Serverside With Scala and ScalaJS

Compiling JavaScript on Serverside With Scala and ScalaJS

Since my experience with the JavaScript world and exploration of ScalaJS I felt compelled to move from Node and Grunt and try to fully utilize Scala for both front and back.
I reached a goal with Scala Stack, a concept of creating all web content on serverside using only Scala code. The concept is extended to keep everything in code including configuration to be fully testable.

Future of Internet

If we try to look into the future of internet, I think we see two strong forces: Market and AI.
How will they alter the internet we use today?
  • Market want to extract most of its users and want to create webpages which are fully personalized in an effort to guide the users to their goals. Sites are personlizing the pages by user settings but why shouldn't all content including color and shape be adopted to the user in a effort to please the user as much as possible? 
  • AI and ML is on the uprising and if the server is thinking for itself it could create whatever as a response.

Obvious Advantages

My main purpose was to skip the JavaScript world but it moved on to something much larger. If all code is shared there are quite a few advantages
  • Single, isomorphic source which ease work and can share logic
  • Share data by keeping it in code. For instance languages could be defined with a Enum type
  • Fully testable code
  • No JavaScript package manager like NPM or WebPack
  • No pre processor like Gulp or Grunt

Risks

There are some traps though 
  • Security, some code should not be shared 
  • Long term effects, demands a experienced architect 
  • Shared code needs to be ScalaJS compatible and cannot use backend dependencies since it's compiled and used on frontend

Scala Stack

I've made three implementations using Google Flexible Environment. Implemented in native JavaScript, jQuery and AngularJS.
Goal is to keep everything in code and to avoid configuration, annotations and settings in Strings.
By only using Scala on serverside, it produce HTML, CSS and JavaScript which is all components for a webpage. 
Map of Scala Stack

Servlet Compiler

Scala Stack is using a Servlet compiler with different logging:
I discovered C and JavaScript in school 98-99 and have coded since.
As an individual the first problem is to be creative within the little time that is left of work and social life. Keeping goals through discipline and understand how to be efficient was fundamental. 2012 I discovered Google App Engine and within a single JSP-file kept HTML, CSS, JavaScript and Java with a database connection, I was hooked! This was all I needed to create a site. The PaaS handled publication, dashboard, configuration of services, hosting, logging and have a big library of API for the basic operation, which meant I could spend time on coding.
Mixing code with a subject are my main interests and when creating my first sites I understood that it's impossible to create content driven sites by myself. The solution was to give the users tools to modify the site as they witched and, as a community, create the site they wanted in a democratic way.

2016-07-12

Google Flexible Environment with Virtual Scala JS Compiler

Google Flexible Environment with Virtual Scala JS Compiler

After several months I managed to translate Scala JS Fiddle to Google Java Flexible Environment 

Goal

To create a project with Scala backend which generates JavaScript in a virtual compiler.

Live Demo

The live demo uses a Scala Servlet to generate HTML (Scala Tags) with a JavaScript. A second Scala Servlet is responding to "/javascript.js" and is using a virtual compiler to compile a String with simple Scala JS code to a JavaScript

Environment

It's a Maven project using Google Flexible "Compat" Environment which includes some App Engine features (not used) and Java 8 with Servlet API 3.1.

Source

Check out my Github

2016-04-02

Webapp with HTML, CSS and JavaScript written in Scala

ISO Scala

This is an example of HTML, CSS and JavaScript written in Scala.

Technics

Different parts are written in different ways
  • Backend, Scala implementation of a Java Servlet
  • HTML and CSS, using ScalaTags to generate HTML in a String
  • JavaScript, built with ScalaJS

Two Builds

There are two different builds
  1. Backend, using plain Maven to build and setup the project
  2. JavaScript, built with SBT and using ScalaJS dependencies

Example

View a whole example at

2015-12-06

Infographic of Google Endpoints in both Scala and Scala JS

I'm no expert in infographics, but I'd tried to show how Google Endpoints is implemented in Scala and Scala JS.

Map

So there are three different languages:
  1. Scala
  2. Javascript
  3. HTML

Google Endpoints

When this is implemented in Scala on backend, it will generate Javascript. HTML needs to load the script and call a Javascript function when loaded.

Scala JS

Written in Scala, Scala JS will generate Javascript. When the Google Endpoints script is loaded, it will callback to Scala JS's script which will created either dynamic or facade representations of it.

Shared

Since Google Endpoints is implemented in Scala and frontend Javascripts in Scala JS, it's easy to share common logic with Scala code.

Code Example

A simple implementation can be found here:

2015-12-05

Dynamic and facade implementation of Google Endpoints with Scala JS

Google Endpoints generates Javascript that mirrors all REST calls to backend. With Scala JS, these scripts can be used in two different ways: dynamic or facade.

Dynamic

This is the easiest solution. If you know the names and the parameters to backend I would recomend this approch. All you need to do is to type vars and defs to js.Dynamic and then use them just as Javascript. Example of loading your API:
And to use a method with csv as parameter:
"literal(csv = validatedText)" is like Javascript "{csv : validatedText}"

Facade

This is approch needs more work since you need to mirror the Javascript generated by Google Endpoints, but will give you types and the structure of the Javascript.
Example of loading your API:
This works since you have defined the API in a facade like in this example:
You know which functions are available since you have made a complete facade. Example:
And therefore it's easy make a call with types:

2015-12-04

Scala JS with Angular and Google Endpoints

Finally done with a simple implementation with Scala JS of Angular and Google Endpoints.

Scala

All backend and frontend is done in Scala with shared logic. Made a simple validation of input which is used in frontend when trying to post, and in backend when it receives.

Google Endpoints

A Javascript is generated which mirrors all exposed methods. This is then used by Scala JS to make all requests to backend.

2015-11-17

Google Endpoints + Objectify + Scala + Scala JS + Auth0

Finally created a project with the following combination

  • Google Endpoints with Google App Engine
  • Objectify as abstract layer of the Datastore
  • Custom Auth0 authenticator for Google Endpoints
  • Scala backend
  • Scala JS to share logic between backend and frontend
You can find the project here:

2015-11-09

Google App Engine + Scala + ScalaJS + Objectify

Created a single Maven project combining Google App Engine, Scala, ScalaJS and Objectify.

Description

A Scala implementation of Filter using Objectify, a separate source directory for ScalaJS which is generating JavaScript with SBT.

2015-09-02

Scala JS Target Folder

Scala JS: Set Target Folder for JavaScript Build

Recently I've been interested in  Scala JS. It would be great to share logic on client and server side and to write all code in Scala. But SBT can be a bit tricky and my project setup was divided into two:

  1. One webapp with a Java web container
  2. Scala JS with logic shared between frontend and backend
To get SBT to build the JavaScript from my Scala JS project to my webapp I needed to add the following lines in my root build.sbt file:

val jsDir = "../gae/src/main/webapp"
crossTarget in (Compile, fastOptJS) := file(jsDir)

Project combining Scala JS and Java web container

You can check out my project which uses this build at


2015-06-20

Google App Engine + Scala with Jersey + ScalaJs

Have been interested in ScalaJs for a while and wanted to use it and Scala with Jersey in Google App Engine. This is a first try to combine them.

GitHub Repository