binaryage / cljs-oops

ClojureScript macros for convenient native Javascript object access.
Other
350 stars 13 forks source link

Make it clear that there is no need to use cljs-oops with goog libraries #5

Closed p-himik closed 8 years ago

p-himik commented 8 years ago

Forgive me if I'm wrong, but using goog libraries in CLJS code is still a JS interop, and technically falls under cljs-oops intentions. At this point, from the README it's not clear that one must not use cljs-oops with goog libraries as they're included in Google Closure compiler set and are minimized along with your CLJS code.

darwin commented 8 years ago

You are right. cljs-oops should be used only for interop with code outside your advanced build. goog library code is part of advanced compilation and is fully visible to advanced optimizer, so you must not use oops there.

darwin commented 8 years ago

The docs currently contains

"Simply use string names to access object properties in Javascript (in cases where you would rely on externs)."

which is a correct statement.

But I agree that it would be nice to explain it in more details. Unfortunately this topic is quite difficult to explain without understanding the advanced compilation first. The issue you ran into is not specific to goog libraries only. Any javascript library which is compatible with advanced mode and gets included as part of advanced build should not be accessed by string names (e.g. via oops).

p-himik commented 8 years ago

Maybe it's worthwhile to include a link to http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html - this is used to direct a user to more information on externs at https://github.com/emezeske/lein-cljsbuild/blob/master/sample.project.clj and it's the only source that I've found that quickly helped me to realize what I was doing wrong.

jiangts commented 7 years ago

curious: I'm currently updating a project that used to have absolutely no chance at advanced compilation with cljs-oops. Will there be any problems if I use cljs-oops on google-closure code?

I know that aget and aset will actually break the advanced compile when used on GCL code. I ask because I can easily see myself accidentally converting a JS call to GCL to one using oops. Basically, I worry about "over-converting" code to use oops.

darwin commented 7 years ago

You should not use cljs-oops with google closure library. cljs-oops compiles down to aget and aset, and it does not have any protection for "over-converting" or "under-converting". In short, cljs-oops user has to understand how :advanced mode works and how it applies to his/her code.

https://github.com/binaryage/cljs-oops#faq

darwin commented 7 years ago

One idea comes to my mind. If you are converting a large codebase to be used under :advanced mode, you could try to enable the new externs inference warning system.

https://gist.github.com/swannodette/4fc9ccc13f62c66456daf19c47692799

I don't have experience with it personally, but if this really works, it should mark all places which need to be converted to cljs-oops (or add type hints for externs inference).