简体   繁体   中英

closure compiler externs for Dojo toolkit and dgrid

Does anybody have to share a file for extern definitions for dojo and dgrid ?

I am trying to include those in my clojurescript project and to use even 'simple' clsure compiler optimization option.

At the moment I have found dgrid and dojo toolkit incompatible with Clojurescript compilation process. In other words it is not possible to a) include dojo or dgrid with :foreign-libs option and then leverage the closure compiler to create a 'minified release using closure compiler :advanced or even :simple option

b) it is also not possible to include the dojo or dgrid libraries with :extern option because for that one has to create a list of extern definitions (which does not come in dojo/dgrid releases).

I am pretty sure option ( a ) is a dead-end, because for it to work dojo team needs to make changes to the toolkit, and it is probably low priority. I have read Stephen Chung's 50+ pages document of how to modify dojo to work with google-closure, but it is well beyond my capabilities to re-implement for Dojo 1.9 and above.

I am thinking ( b ) might eventually work, but for that I need to find the externs library. Hoping somebody has done it for dojo 1.9 and the latest dgrid.

Prior to posting here I had checked the repository of currently available 'externs' for the closure compiler,and dojo is not there https://code.google.com/p/closure-compiler/source/browse/#git%2Fcontrib%2Fexterns

I had also found a online extractor of externs http://www.dotnetwise.com/Code/Externs/index.html

and http://www.dotkam.com/2013/07/15/clojurescript-use-any-javascript-library/

However, I am not even sure what dgrid/dojo files to do this for.

Therefore looking if anybody has created these externs already.

You can use their own source file as the externs definition. Obviously this means that the compiler can't optimize the library, but if as you say, you don't need that, it's a good working option.

I am not experienced with dojo/dgrid in ClojureScript but I've used several javascript libraries with ClojureScript already.

The best way to use complicated libraries with ClojureScript is just not to touch them, and not run Google Closure on them. (what you call (b)). Therefore, you will need to put very few externs definitions in externs.js Only for the specific vars/functions which you access from your ClojureScript code. You don't need externs.js for EVERYTHING they declare. The Google Closure compiler will run only on your code, not the external js library. You need to put externs only when you: 1. Call your cljs function from js code (to avoid calling a munged function name that is not what you have in your js) 2. Call the js library function from your cljs code (to avoid having munged the function name in the function call).

So there's no prior work that needs to be done, you need to put a small externs file exactly for the specific calls you make.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM