atom packages, clojurescript, google closure and dependency management - clojurescript

I'm writing some atom (the editor) package with ClojureScript. And i faced dependency load issue.
When compiled ClojureScript produces file like this (main.js):
goog.addDependency("base.js", ['goog'], []);
goog.addDependency("../cljs/core.js", ['cljs.core'], ...)
goog.addDependency("../clojure/browser/event.js", ...)
Obviously, ClojureScript heavily depends on Google Closure dependency management.
But, to be able to use Google Closure i need to include goog/base.js file.
The only way that i found is to add to goog/base.js:
module.exports = goog
and add to main.js:
require('./goog/base.js')
This is very bad approach, because these files are generated - so they can be overridden.
Also, release compilation will not include these lines.
The question is how can i use both these dependency systems?
Or is it possible to use ClojureScript w/o Google Closure?
Please advice, thanks!

If you set your ClojureScript :optimizations to something other than :none (e.g., :whitespace) then the resulting .js file will include the Google Closure code inlined and you won't have to reference it separately.
(Note that this means you might not be able to use a main function in your ClojureScript code, but you can just put a call to your main function somewhere at the toplevel.)

Related

How do I create a Processing library that adds a new function to the language?

I want to create a Processing library that adds a single function to Processing. A single command. How do I do this?
So I want to be able to write on Processing this:
void setup() {
drawMyCustomShape()
}
In a way that drawMyCustomShape will be on my custom library implementation.
Thanks!
Note: this question is not about creating a new library in processing. Is about creating a library that exports one new command (so you can using without caring of the container class instance).
First of all, are you sure you really need to create an entire library? You could just add that class to your sketch without needing to deploy it as a library. If you're worried about clutter, just put it in its own tab.
If you really need to create a library, then there are three tutorials that you need to read:
Library Overview
Library Basics
Library Guidelines
But basically, you need to create a Java project (in an IDE like eclipse, or with a basic text editor and the command line) that uses Processing as a library. That's where you'd put your MyLibrary class. You'd then export it as a .jar file, and then import that .jar file into Processing. You would then be able to use your class exactly like you can use any other Processing library.
Your proposed setup has some other issues (how are you going to access the sketch variable from the static function?), but I'd suggest treating them as separate questions after you get the basics in place.
It sounds like you are actually looking to create your own extension of the Processing library, as in actually change the core jar file.
You can extend the actual Processing library by forking off of its main branch on Github. By writing your function drawMyCustomShape into the actual core in the forked version, you can then build the Processing Development Environment from your copy of the code. Using that particular copy of the PDE, you could do what you're describing.
Once you compile this build, you could actually distribute this copy of the PDE to your college students. They would be able to use your function as if nothing were changed. (I'm guessing that this is for an intro-level class at the college level, so that's why you would have to hide implementation from your students?)
Here's some links to get you started:
Processing github
Instructions for building the PDE from source
So, finally I found the most adequate answer for my case.
The solution for this is to implement a new Processing Mode that extends the builtin Java Mode. To include static members to the main processing program you will need to add a new static import to the ones that processing adds to your code.
You can do this by forking the Mode Template for 3.0 that #joelmoniz created from #martinleopold:
https://github.com/joelmoniz/TemplateMode/tree/3.0-compatibility
There is a good tutorial here:
http://pvcresin.hatenablog.com/entry/2016/03/17/210135
Why is the most adequate solution? : I think this is the best way to achieve new static methods in processing code and ensure an easy distribution! You just have to set the mode folder in your sketchbook/modes folder. If I were to fork processing it would be a big deal to prepare distributions for all operative systems and also to keep update with main project.
My particular solution:
To add my static imports into Processing I implemented a custom mode where I overrode the PdePreprocessor class which wraps the processing code with all the Java procesing code. So, the idea was to add more imports to the imports that the PdePreprocessor generates on the generated Java source.
In my custom PdePreprocessor I overrode the getCoreImports method to add my custom methods. I did this here because I consider the new imports are part of the core of my custom mode. You could also achieve this by overriding writeImports method.
In order to use my PdePreprocessor implementation I had to overrode the following classes:
Commander
JavaBuild
JavaEditor
JavaMode
JavaEditor
I had to implement a new JavaBuild which preprocesses the Sketch with my custom PdePreprocessor. And also use my custom JavaBuild in all the places where the Processing Java Mode instances the build class. Please share with us if there is a better way to do what I did.
Here is the github for my solution: http://github.com/arypbatista/processing-inpr/

Use a different React version with clojurescript react libraries (reagent,om,rum,quiescent)

How can I use a different React version with Reagent, Om, Rum, Quiescent or Brutha?
Self answer since this is asked frequently:
First you have to tell Leiningen to exclude the cljsjs/react dependencies:
[rum "0.6.0" :exclusions [[cljsjs/react] [cljsjs/react-dom]]]
If you have other dependencies pulling in cljsjs/react you can use a global exclusion:
:exclusions [[cljsjs/react] [cljsjs/react-dom]]
Next you have to satisfy the compiler since it won't find the namespaces cljsjs.react and cljsjs.react.dom. For this create two files that hold these namespaces in your source directory. For instance
- src/cljsjs/react.cljs
- src/cljsjs/react/dom.cljs
Both only need the namespace declaration and can otherwise be empty (ns cljsjs.react).
Now you can include any React version you'd like manually in your HTML file with a normal <script> tag.
Alternative:
You can also use foreign-libs compiler option.

Is it possible to call a ClojureScript module from a jQuery or AngularJS normal webapp?

I have an existing web UI that I would like to be able to call a function written in ClojureScript. The function would be in a separate ClojureScript module (cs_func.js file) that does not need access to the DOM. I can't find any examples on how to do this.
Yes, this is possible (cf. how to use a complex return object from clojurescript in javascript… for instance). As you already figured out, ClojureScript will be compiled to normal JavaScript files (where "normal" varies according to your cljsbuild settings on how aggressive the output will be optimized). This is more a Javascript question on how to access the compiled JavaScript module than anything else.
You should be aware, however, that the output from cljsbuild might get mingled and that you probably want to prohibit this for your entrypoints, cf. the discussion in the section "Exporting ClojureScript functions" in this article on ClojureScript/JavaScript interop and the even more detailed discussion in Luke VanderHarts article on using JavaScript and ClojureScript

Why do my SWC libraries not code hint?

I recently took much of my reusable code and compiled them into SWCs for organization and ease-of-use purposes. Since doing so, none of my documentation has appeared in the code hints that Flash Builder provides. I have searched through project settings and I have been unable to find a setting for such a feature, and I am at a loss as to why it doesn't work anymore.
I compiled the SWCs using Flash Builder's Build Automatically functionality. I have not tried compiling with ANT yet, but will probably try the next time I build. asdocs was able to compile full documentation for all of my libraries with relative ease and the code hinting works if I use the raw AS files themselves, so I do not believe it has anything to do with the way I was writing the documentation. Example:
/**
* <p>Batch adds variables from a generic object using name-value pairs</p>
* #param variables A generic <code>Object</code> that contains name-value
* pairs that will be used as the arguments of the REST request
*/
public function addVariables( variables:Object ):void {}
Any idea why the code hinting no longer works?
Flash Builder uses ASDocs, which are embedded inside the SWC, to provide code hints - unfortunately, FB doesnt include the docs when it builds a SWC.
However, it can be done 'manually' with ANT:
<target name="insertASDocs">
<zip destfile="PATH_TO_YOUR_SWC" update="true">
<zipfileset dir="ASDOCS_FOLDER/tempdita" prefix="docs">
<include name="*.*"/>
<exclude name="ASDoc_Config.xml"/>
<exclude name="overviews.xml"/>
</zipfileset>
</zip>
</target>
PATH_TO_YOUR_SWC is the relative path and swc name (eg: myFolder/mySwc.swc).
ASDOCS_FOLDER is the folder where your generated docs are stored.
The ANT script just adds the ASDocs to the SWC - after this, code hints should appear.
Update:
Forgot to mention that you need to set keep-xml to true when generating the docs (if inserting them into a swc):
<asdoc keep-xml="true" ...

Are Mootools and Google Closure Librarys Compatible?

Anyone have any experience of using Closure js lib and Mootools in the same page?
Conflicts or works ok?
According to google:
The names of all Closure Library
functions and properties begin with a
dot-delimited path that prevents them
from accidentally overlapping with
names defined in non-Closure Library
code. This path is called a namespace.
(http://code.google.com/closure/library/docs/introduction.html)
So there should be no conflicts, also I checked the API documentation and it reaffirms my findings, for example, for array manipulation you have to go through the google namespace (goog):
goog.array.binaryInsert(array, value, opt_compareFn) ⇒
boolean
(http://closure-library.googlecode.com/svn/trunk/closure/goog/docs/closure_goog_array_array.js.html)
This is unlike the MooTools extention of the Array class itself.
Cheers,
Roman