This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2017-11-28
Channels
- # adventofcode (2)
- # bangalore-clj (3)
- # beginners (171)
- # boot (28)
- # chestnut (3)
- # cljs-dev (20)
- # cljsjs (5)
- # clojure (280)
- # clojure-austin (1)
- # clojure-czech (1)
- # clojure-dev (9)
- # clojure-dusseldorf (2)
- # clojure-greece (20)
- # clojure-italy (6)
- # clojure-poland (16)
- # clojure-russia (7)
- # clojure-serbia (4)
- # clojure-sg (1)
- # clojure-spec (18)
- # clojure-uk (153)
- # clojurescript (57)
- # core-async (9)
- # cursive (21)
- # data-science (29)
- # datomic (18)
- # dirac (8)
- # docker (6)
- # duct (1)
- # emacs (50)
- # fulcro (15)
- # hoplon (56)
- # klipse (3)
- # leiningen (14)
- # lumo (1)
- # off-topic (5)
- # onyx (13)
- # other-languages (14)
- # pedestal (1)
- # perun (5)
- # planck (17)
- # re-frame (10)
- # reagent (2)
- # ring (1)
- # spacemacs (51)
- # sql (14)
- # test-check (16)
- # testing (1)
- # unrepl (93)
So, gathered friends… I have managed to “do the thing” in development mode, but when I use advanced compilation my app chucks a gnomic JS error, and my GeoJSON polygons don’t render… They render fine locally in dev mode, but not remotely in prod mode… If you had this problem, where would you start, as I am stumped… (this app is my first serious foray into ClojureScript and if nothing else it has been fun, rewarding and also taught me how little I know about JavaScript)
I highly recommend cljs-oops. https://github.com/binaryage/cljs-oops. It's taken away all my externs woes
externs are the devil's work
they are indeed @mccraigmccraig , but weren't some of the latest versions of supposed to help out here?
I always forget about advanced compilation munging names, and every time something crops up it takes a few hours before I make the connection between "oh - this is only happening in staging/production and only staging/production use advanced compilation"
@danieleneal next time you have a complain here and we'll tell you it's advanced compilation's fault
@maleghast I would personally import cljs-oops and go through all the interop calls (.-init some-thing)
and replace them with ocall
/`oget`
@bronsa can you somehow 'detect' when I am having an advanced compilation problem and then at me. I might not think to ask for help
@danieleneal - Er, thanks… I have NO IDEA what you are talking about, but I am reasonably confident that I will once I’ve read the link(s) and had a think… 🙂
lack of guarantees - the eternal problem with dynlangs
@danieleneal - From a quick speed read, I am not getting a compile warning anywhere, just a JS error after compilation
@maleghast - yes, that sounds like an advanced optimizations issue
I mean, I could__ turn off the optimisations in production - the app is going to be a non-public app, that will change rarely, so JS would be cached…
So - in advanced mode, the google closure minifies function names. However, it might minify name that are defined by third party libraries, so typically you provide "externs" to tell it not to minify those names
This is tedious work
Yeah, I looked into hand-rolling externs for something lately and I decided I’d rather write my own code.
Yeah - the problem with cljsjs is that the externs can be incomplete or unspecified
@maleghast You could make a PR to the cljsjs team to update their externs 🙂
In the short term I might actually turn off the advanced compilation - it’s really a nice-to-have for this use…
The other options are 1) use the new externs inference - I don't have any experience with this but @bronsa might know more 2) use cljs-oops -which is a macro which somehow expands to a call that will work safely under advanced optimizations - I do have experience with this and it works like a charm
cljs-oops doesn't allow things to be optimized away, to my understanding. Which is why I've avoided it.
OK, well I will turn off advanced compilation, for now, and I will start my investigation(s) with the externs for LeafletJS that I am currently using. If that does not help me out then I’ll start thinking about the other options… It does seem likely that there is something missing from the externs that CLJSJS are bundling with LeafletJS.
:thumbsup:
@danieleneal it's advanced compilation's fault
thanks
@maleghast I had to add some more methods to the leaflet externs when I was getting adv comp working
@thomas - There is, yes… I am using the cljsjs package for LeafletJS and the externs look to me (but I don’t really know what I am looking for) to be correct vis à vis the bit of Leaflet that I had not used before that seems to be failing in advanced compilation.
I tried to get the Paho JS package into cljsjs two years ago... and one of the CLJSJS experts had a look at it in the end and came to the conclusion that it was impossible to use the optimised Paho JS build. (so it worked with advanced CLJS compilation, just not with the optimised JS package)
@maleghast try cljs-oops. externs might be better than they used to be, but cljs-oops is simple and - most importantly - local. i.e you don't have to change something in some far-flung file or files to fix your invocation
@mccraigmccraig - OK, will do… Do I have to integrate it with EVERYTHING I do or can I start by using it to wrap up the thing I am pretty sure is the problem (everything else I am doing with Leaflet works seamlessly in advanced compilation, it’s just drawing country boundaries with GeoJSON)
you can just use it for the problematic things
Or I willk have a delve when I’ve finished doing minor updates to the completed work and adding in functionality that was previously not required for this iteration… 😞
@mccraigmccraig - OK, so I got back from the school run, answered a bunch of emails and then I tried to read the cljs-oops README.md… I have no idea how to use this… I KNOW that I am being dumb and / or that my general ignorance of JavaScript (4 years since I really did ANY, and even then I was a very light user) is in play here, but honestly the README reads, to me, like stereo instructions… Do you or indeed does anyone else have an example of wrapping up a call to a well-established JS library with this, as the examples seem to be about accessing data in data structures?
@maleghast (ocall <js-obj> "method-name" arg1 arg2 arg3)
OK, that helps, thanks! (I may email the maintainer and suggest that he puts something like that into the README.md - that makes perfect sense to me, but barely word-one of that README did… (all comments about that being my deficiency notwithstanding)
yeah, it should have some ocall
and oapply
examples as well as the oget
and oset!
examples
you can get him on slack though @maleghast, no need for email
Cheers, might well - I want to see if I can get it working first so that I am saying “Love your library, really helped me get this thing done, but…“, rather than the alternative… 😉
i just moved a bunch of stuff which was giving me advanced-compilation gyp to cljs-oops @maleghast - all went very smoothly
I need to do some tinkering, clearly, as I’ve just wrapped up the call that I am 90% certain that was the problem and it stopped working in dev mode and I have errors…
Ooh, hold on, I have a #js literal as one of the params that I am trying to plug into ocall… That’s not going to work, right?
@maleghast a #js
literal is probably fine as a param to a js fn, as long as it's the right sort of #js
literal
it's a macro which assembles an advanced-compilation safe deref of a js object reference, using goog.object/get
@dominicm
@mccraigmccraig I don't understand how that works? Does it mean that Google closure can't trim out unnecessary parts of the js?
it's for calling libs outside of closure's purview
it doesn't affect closure's operation, it just prevents closure from bollocking up your code by munging names you don't want munged
Failed to load resource: the server responded with a status of 404 (Not Found)
base.js:1357 Uncaught Error: Undefined nameToPath for goog.string
at visitNode (base.js:1357)
at visitNode (base.js:1355)
at Object.goog.writeScripts_ (base.js:1369)
at Object.goog.require (base.js:706)
at dashboard:23
base.js:1357 Uncaught Error: Undefined nameToPath for goog.string
at visitNode (base.js:1357)
at visitNode (base.js:1355)
at visitNode (base.js:1355)
at visitNode (base.js:1355)
at visitNode (base.js:1355)
at visitNode (base.js:1355)
at Object.goog.writeScripts_ (base.js:1369)
at Object.goog.require (base.js:706)
at dashboard:23
This is what happened when I tried to run the same code having done advanced compilation.
@mccraigmccraig - If I understand what you are saying, it’s like making an extern exception for things that you call, but doing it inside your own code?
@mccraigmccraig but I'm not sure that's the full situation. React is managed by closure, but it creates window.React. In this case, I'm not sure how @maleghast is bringing in L on this case, but oops is discussed as an alternative to externs in their entirety.
right, it looks up object properties by their string name, which sidesteps advanced compilation munging
@dominicm there is no problem mixing oops and externs... oops doesn't affect closure or externs
@mccraigmccraig - does that mean I am missing a vital component / library, as that error says something about “Undefined nameToPath for goog.string” or does it mean that google Closure can’t find “geoJSON” as a method of “L”? I mean, even though it worked in dev-mode have I perhaps misunderstood how I need to refer to the various bits of the call inside the (ocall …) form in my code..?
I am doing this:
(ocall
js/L
"geoJSON"
(clj->js (get-in borders [bordername :coords]))
#js {:style (get-border-style (get-in borders [bordername :color]))})
it occurs to me that I might be wanting just “L”, rather than “js/L” or I might be needing something else entirely as the js/L thing is all wrapped up in the cljsjs bundle / package that I am using for all the other Leaflet calls and perhaps I need to use something else..?
that call looks reasonable... try replacing js/L
with (oget js/window "L")
and see where that gets you
excellent 🙂
That last suggestion makes a lot of sense in hindsight, but I really don’t think that I would have got there on my own.
I am definitely going to reach out to the maintainer about an addition to the README.md to explain how to do this kind of thing.
(which I can__ now couch in “Your library is awesomes, but…“, rather than “I can’t make your library work” 😉 )
@maleghast you should generally bet on advanced compilation munging all symbols apart from well-known things like js/window
and js/document
and things declared in extern files... so js/L
will get munged like any other symbol
@mccraigmccraig - Yeah, I’m starting to see that... The externs for LeafletJS are, as far as I can tell, comprehensive so I am not going to retro fit cljs-oops to everything that is already working. Having said that, I am going to bear it in mind going forward!
hmm @maleghast there does seem to be an extern for L.geoJSON
https://github.com/cljsjs/packages/blob/master/leaflet/resources/cljsjs/leaflet/common/leaflet.ext.js#L810
L.GeoJSON
the extern is wrong
it should be L.geoJSON
ah, yeah, ok - in which case there is a missing extern for L.geoJSON
it's been a while since i did any leaflet - it was fun
I will open an issue on CLJSJS after my kids are in bed to let the package maintainer know
I mean, satisfying once I got it working, but I did not get a great deal other than pain out of the journey ;-)
i did this - http://techmap.london/ and this http://www.startuphubs.eu/ - i definitely remember having fun along the way 😬
stuff like producing the o/s boundary paths at different resolutions and dynamically loading and displaying appropriate resolution paths as you pan and zoom was definitely fun
Well, I am glad that it was fun - I might__ have been going for comedy ^^ I have enjoyed my dalliance with leaflet so far… 😉
Those are some cool maps, @mccraigmccraig - Is that Clojure / Clojurescript underneath?
yep, clojurescript, clojure, elasticsearch & postGIS
Nice work @mccraigmccraig
Ah, these were the projects that got you doing PostGIS to LeafletJS projection transformations..?
latterly @minimal too!
Morning
So in mumble mumble years of living on this rock we call home, I have never walked into a glass sliding door. That is until today when I managed to do it in spectacular fashion with my laptop in my hands. It hurt like hell. I'm still not sure if I've permanently damaged my toe.
@yogidevbear - Hope your toe is ok, but how’s the laptop!??!?!
Well I'm on the laptop now so I think it came off better than I did