I have an idea (not new though) to make a compilation scala code to JavaScript. Basically I would like to use Scala where now Coffee Script is used in PlayFramework 2.x.
It seems it is not so hard to make it happen. Let's say I have a file /managed/Foo.js.scala. If something has changed in this file, when I refresh a page it triggers the compilation to js. And then, as result I can see updated assets/javascripts/Foo.js file.
So, the question is: how to trigger complication by browser-refresh event in PlayFramework?
Not necessary the answer but a direction where is the effort to do this. I will play around this.
About Sccla.JS, I guess it might be critical if I develop application that needs to be run on mobile. Several BMs of JS might deal breaker to use Sccla.JS
Related
I'd like to write a simple app to crawl/scrape some web content. The more I delve into the analysis, the more I realize that the instructions I need to give to the app in order to navigate through the site and get the content I wish it to extract, may be very peculiar depending on the target website structure.
The idea was to write some configuration files to define how the app should browse and scrape each specific site, but defining such behaviour could be challenging, unless you write in the configuration file some actual Scala code.
So, the idea is to write some code able to get a scraper object instance reading a file written in the .sbt format and inject some code in it.
First of all, I need to know where to start to achieve such task: what library should I use?
Could it be easier to write some sbt tasks and use sbt as the core of the app instead of writing one from scratch? What should be the limitations in this approach?
I apologize for being so general, but I don't have the slightest idea from where to start. I'd like you to head me to the right direction and post some docs to read.
Consider the app is meant to be a CLI tool, no graphical interface needed, then.
So the question is may I set yadda for ember tests to generate .coffee files instead of .js for steps?
Js is ok, but I have ember-cli with coffeescript so it'll be easer for team use one language instead of two
The whole Ember ecosystem is based around using JS instead of coffeescript. There were some early discussions about making blueprints easier for teams to change by default, but there is nothing like that right now.
I'd suggest considering shifting to Aja's as a team instead if that's doable, you'll save yourself a lot of headaches long term ...
So ClojureScript One is rather incredible looking! You can make updates with your REPL in real time to a SPA.
So something like this is rather impossible in Java where you don't have a REPL but it seems very possible in something like Groovy or Scala. I'm sort of a Lisp bigot (I really shouldn't be but oh well) and wondering if there is a Scala or Groovy like Clojurescript?
Update:
In theory it looks like one could wrap Scala/Groovy around Java's ItsNat. However I have some doubts about that project given it hasn't been updated since 2011 (also they have they ugliest website.. its like they tried to make it ugly). The license is also rather restrictive.
Try http://www.scala-js.org/ a A Scala to JavaScript compiler
There's js-scala, but it seems to be quite experimental at the moment.
ItsNat has come to quit a stable stage, this is why it is inactive. Of course new features and more browser support and testing can be leveraged, but so far, we've had a great experience with ItsNat. We've been with ItsNat since version 0.7 and had very (2) issues, that too, quite rare ones.
If you'd like working examples, I'd be glad to show you as our project is open sourced :-)
Works well with both SEO and SPI.
Demo
If you are looking for SPA scala-gwt. Or you are looking for scala-to-javascript compiler?
we all agree that when we use GWT, we compile our application on the server, several javascript file are created. Normally, when deploying, we would use the obfuscated mode.
Now modifying a javascript file in obfuscated mode is almost impossible. Now what happens if we want to make some modification in our GWT application.
Do we have to go back again in Java, modify the file, compile, and then deploy again??
I'd say yes... If you use a code generator you should avoid modifying the generated code by hand.
No, no, no.
You don't "go back" to the Java code to modify it. You simply debug, test and modify the Java code. You ignore the code in the compiled javascript files except to deploy it. As far as you are concerned, GWT source code is Java code, not javascript, written within the environmental restriction of the browser.
Your question is like asking, "I have a C application that gets compiled to object code. Do I modify the object code or go back to the C code to modify it?" !!!
You simply treat the generated javascript as "native code".
No doubt you can include javascript using jsni, and so can you include assembly code when using C. So except for those assembly code you inject and similarly except the javascript code you include, you leave the "native code" alone.
When you try to modify the object code generated from C, that is called hacking. Hacking is an interesting hobby but when you wish to create an application and your main task is not "hacking", hacking would only be your extra-curricular activity not connected to your main employment or project.
Go back to the beginning: http://code.google.com/webtoolkit/overview.html
...Write AJAX applications in Java and
then compile the source to highly
optimized JavaScript that runs across
all browsers
When you're ready to deploy, GWT
compiles your Java source code into
optimized, stand-alone JavaScript
files that automatically run on all
major browsers, as well as mobile
browsers for Android and the iPhone.
While debugging: if you are running in development mode you may not even have to redeploy while in dev.
Thanks to the GWT developer plugin,
there's no compiling of code to
JavaScript to view it in the browser.
You can use the same edit-refresh-view
cycle you're used to with JavaScript...
I'm coming from a PHP/Python/Javascript background, and recently became very interested in Scala - specifically Akka coming from the web standpoint.
I'm having an extremely hard time though with general workflow, issues compared to interpreted languages such as the ones I described.
In general I tend to code, test results, code and repeat. This comes to a standstill when even changing a single line in a 20 line class takes up to 30secs to compile and run. Is this really normal? Do I need to just build, build, build then go back 30 minutes or an hour later and compile/test?
(I'm using IDEA with SBT) Do I need to specifically learn how to use Maven other than linking to the repos?
Thoughts? Advice?
I think you're on the right track with Idea and SBT. Have you tried
~compile
That will detect changes to your source automatically. For web applications, you can do a
jetty-run
followed by
~prepare-webapp
To continuously compile and redeploy your app to jetty. Makes Scala dev feel a lot like Python web development.
Usually I've found SBT to be very fast when compiling, especially the size file you're talking about. By the time I save my change and go to my SBT prompt, it's done.
Another handy SBT aspect is the REPL which will load your project and its dependencies:
console
You can reload any compiled changes with
:replay
in the scala REPL.
EDIT:
Guess I should mention that you can play around with a simple class with a main method. If you create a file called src/main/scala/Foo.scala that looks like this:
object Foo {
def main(args: Array[String]) {
println("Hello World")
}
}
And a file project/build/Build.scala like this:
import sbt._
class Build(info: ProjectInfo) extends DefaultProject(info) {
override def mainClass = Some("Foo")
}
Then at the sbt prompt, you can do
~run
To continuously compile and run the Foo.main method. You may need to do a 'reload' in sbt first. It seemed to take 2-3 seconds from saving change to seeing output. Then you just edit away, save and see changes. It's a pretty good workflow.
Also, don't forget the REPL - definitely a critical tool for learning Scala. You can learn a ton just playing with it interactively.
IDE Assistance:
With static typing language I find myself doing less of that workflow than I do with dynamic typing, but that was only possible because of excellent IDE assistance (the typing information allows it to detect errors early, and give accurate suggestions while you are editing), so it does save some time in that code-test loop you described.
However Scala IDE support in IDEA isn't yet at the level of Java for example,
both in catching errors while editing (IMHO) and speed of compilation.
REPL/Script support:
Do not forget that you can still use the Scala REPL, the workflow is pretty much like what you would be used to in Python for example.
IDEA + Scala speed :
You can refer to this question for more discussion on IDEA+Scala speed.
I use JRebel plugin with maven. I turn off the NetBeans compile on save feature,(don't know if intellij has similar) and run scala:cc - continuous compilation goal from console. It waits for any changes in source code, so after you make some, the file gets compiled, copied to /target directory and then hotswapped into running virtual machine. The procedure takes units of seconds depending on the size of the file.(I assume you do web development since you mentioned PHP and JavaScript) There is fsc server running in the background, that is also one of the reasons, why the compiling is speeded up.There are some minor disadvantages, you can't change the superclass, which means you can't go from AbstractFunction1 to AbstractFunction2 (which represent anonymous functions) - changing (x) => x to (x,y) => x + y means that you need to restart the server.
Useful links:
scala:cc
jrebel
One of the advantages to statically typed languages is that the type system can catch several types of mistakes/bugs. So, in theory, you shouldn't need to go through the rigmarole quite so often.
Of course there are many changes, especially in the UI, that only eyeballs on screen can check. All I can suggest there is good modularization to keep the compile/build time down. And unit tests. I don't know about the community that you're coming from, but in java/scala, unit tests are highly, highly recommended. You find out if the code worked right much faster that way.
The answer boils down to this: try and avoid having to build and restart to check your work as much as possible.
My Python-like workflow--which leaves me with very little time waiting--usually goes as follows:
Turn what I'm trying to do into a library (stick it in a .jar and add it to the classpath).
Work on the new code in an editor, but paste it into the REPL instead of compiling separately. Once it's working well, add a unit test.
Place the new code into the library. Repeat.
I can do this on a netbook and not wait longer than ~3 seconds for any one step.