Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala PlayFramework and Angular JS - too much effort in terms of duplication and mixing concetps

I tried to write an application on playframework + scala + Angular JS. The purpose was to create an web app that would work either good when JavaScript is OFF or ON in the browser. This is usual requirement when one writes Public Site (which should be good for people and for Google that would index it)

So I ended up with ~50% code written in JavaScript, having two(2) folders named "controller" - one for Scala code, one for JS code (since AngularJS uses controller concept as well).

Also, since JS code is supposed to use Ajax calls, I had to create one more scala-controller that returns json, but not html back to client's request. And.. this all I do not like. This seems as too much effort.

On playframework template side, I should think how to combine Scala with JavaScript, passing parameters from one language to another. Using some tricks like showing that when JS would be processed, showing that when it is supposed to be off.

This all makes my template less understanable, and one day, when I have huge code base, I may come up with a solution to duplicate my templates as well (js templates + scala templates) - to use proper template when JS is off/on. Then amount of JS code could rise up to 60%..

And then it seems that I'm going to duplicate everything, like having two different application - for Google and for people. What would be common (only) is my data themselves in my database, I have not to duplicate data. But.. there we might have a different issue with a format of that data (and most likely would be json-based [because I do not wasting processor time to do table-object transformation], but not table based - NoSQL.. then again we come to JS like DB - like to MongoDB), and JS works very good with Json, natively.

Then question, why not use 100% of JS for simple things like: request-response, forming a page, layouts. Server side JS controller could form my templates - then I do not need to switch from one language to another and be even more productive in this sense.

Question: Do you have any suggestions? Best practices about this? I'm not that guy who want to end up using NodeJS to useJavaScript as ONE languages for everything - for server and client. But let's speak about productivity and business needs.

There is an example (not mine) of AnjularJS controllers, how much JS I have to write: https://github.com/tastejs/todomvc/tree/gh-pages/architecture-examples/angularjs/js

and just imagine that I have to keep PlayFramework controllers along with that - for HTML and AJAX calls, mixing things in scala/playframework templates with JavaScript.

like image 442
ses Avatar asked Sep 13 '13 15:09

ses


1 Answers

I would like to share the receipt used in the eventual seed (https://github.com/angyjoe/eventual):

  1. Write your HTML. Doing so, please feel free to use as many JavaScript frameworks and libraries as you wish (the seed is AngularJS though).

  2. Decide your Play models from which the controllers follow.

  3. Decide the operations (only those you need!) for each of controller (list, create, show(id), update(id), delete(id)). Implement these operations as Scala actions.

  4. Insert a Play route to serve each implemented action to the client framework.

  5. Insert one (and only one!) Play route to serve your styled HTML to the client framework.

  6. Spend the rest of your development time and effort on the client-side...

like image 135
user2845946 Avatar answered Nov 09 '22 23:11

user2845946