This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-08-27
Channels
- # bangalore-clj (1)
- # beginners (187)
- # braveandtrue (52)
- # calva (7)
- # cider (17)
- # cljs-dev (14)
- # clojure (27)
- # clojure-austin (4)
- # clojure-dev (11)
- # clojure-finland (4)
- # clojure-italy (5)
- # clojure-nl (1)
- # clojure-russia (22)
- # clojure-spec (9)
- # clojure-uk (27)
- # clojurescript (91)
- # datomic (40)
- # duct (4)
- # emacs (14)
- # figwheel-main (36)
- # fulcro (11)
- # hoplon (10)
- # immutant (9)
- # instaparse (4)
- # java (1)
- # jobs (2)
- # off-topic (28)
- # pedestal (1)
- # reagent (15)
- # reitit (7)
- # remote-jobs (6)
- # ring-swagger (3)
- # shadow-cljs (28)
- # slack-help (1)
- # spacemacs (4)
- # specter (1)
- # sql (3)
- # testing (3)
- # tools-deps (24)
@pppaul Some folks have tried various inline css schemes, like https://github.com/roman01la/cljss and https://github.com/Jarzka/stylefy
How is this supposed to look like:
(defn content []
(let [ctx (-> js/document
(.createElement "canvas")
(.getContext "2d" #js {:antialias true}))]
(set! (.-font ctx) "30px Arial")
(let [m ((ctx (.-measureText) "some text here"))]
[:p (str "m:" (.-width m))])))
I just want to find the width of some text using the canvas objectReading
I would expect the last let to be (. .-measureText ctx "some text here")
but I fail at this
well, for others to learn, this works:
(defn content []
(let [ctx (-> js/document
(.createElement "canvas")
(.getContext "2d" #js {:antialias true}))]
(set! (.-font ctx) "30px Arial")
(let [m (.measureText ctx "some text here")]
[:p (str "m: " (.-width m))])))
I've found this function useful for making sure a resource is only created once: https://gist.github.com/pesterhazy/aa1d8dbd43ac4b369e41101daa865525
Especially when reloading with figwheel, you often want to ensure that there's only one resource of a certain type, like a setInterval, and event handler or some kind of stateful object. Often you need to dispose of the resource before creating a new one.
not sure what the right channel for this is, but is there a way to copy files with cljsbuild? I want to copy some styles from a node_module into the directory with the rest of my resources
When using a node library that requires es2015 classes, is there a way I can create them in ClojureScript? Do I need to do some sort of Object/create
magic?
cljs.user=> (def o (reify Object (hello [this] (prn :ok))))
#'cljs.user/o
cljs.user=> (.hello o)
:ok
@pesterhazy I don't think this is actually what I'm looking for. I need to create a new es2015 class that extends a class provided by a library.
@ghopper gotcha
I'm not sure what about the es6 class this library really needs. I'm attempting to replicate it somehow. https://github.com/addyosmani/es6-equivalents-in-es5#classes seems useful
yes, something like that should work
@ghopper check this example https://gist.github.com/pesterhazy/2a25c82db0519a28e415b40481f84554
That looks very promising, thanks! 😄
and especially https://gist.github.com/thheller/7f530b34de1c44589f4e0671e1ef7533#file-es6-class-cljs-L18
@ghopper lmk if that works out for you
Hi, can someone point me to an example of using the :npm-deps
option of the clojurescript compiler in upstream packages? Is it possible to have clojurescript project A use clojurescript library B (via a deps.edn
reference) and then have the compiler download the npm deps required for library B when I compile project A?
Thanks for any tips, just having a bit of trouble wrapping my head around how npm dependencies work when creating a clojurescript library...
@drcode B must declares its dependencies in a deps.cljs
at a source root with just {:npm-deps {"the-lib" "version"}}
that just covers the "download the npm deps part". for the compilation I don't actually know.
@drcode before going down that path I’m assuming you’ve made sure that said library will get through Closure compilation - it’s still a coin toss at this point
OK @thheller I think that explains the piece I was missing, that sounds correct- Let me give that a shot
@dnolen thanks- yes, I hope so. I'm taking some libraries I have that use cljsjs and am trying to get them working with just npm packages, so in theory at least I should be past the compilation hurdle already.
@dnolen good to know 👍 I think I understand there's limitations at this point with externs inference, just personal experimentation right now
@pesterhazy I think I managed to get the prototype extend stuff working, though I never really understood it. Eventually I realized with the library I'm using, I can call the call function directly and it'll work. I though I'd tried that to begin with. :man-shrugging: Thanks for pointing me in that direction.
@dnolen I can (sorta) see that, hopefully with some more learning/experimentation on my part will help me understand these subtleties
but suffice to say you’re not the only person confused about this, and it’s not the user’s fault
still - rewinding a bit - curated CLJSJS libs are still the best way forward for transitive deps for end users
and based on my experience so far with random JS libs - the curation of CLJSJS is actually value
@drcode To clarify, as the cljsjs homepage says: > Since ClojureScript 0.0-2727 the :foreign-libs option provides an excellent way to integrate Javascript into ClojureScript applications. CLJSJS provides Javascript libraries and their appropriate extern files packaged up with deps.cljs. CLJSJS aims to concentrate packaging efforts to make everyone’s life a little easier. i.e. what you get from CLJSJS is a prepackaged foreign-libs declaration along with correct externs. That means that your "advanced compilation" will be [advanced compilation of your code, respecting included externs in the renaming phase] + [JS lib], both in the same file, but without the JS lib ever going through the Closure compiler (though generally you do get a minified version). On the other hand, when you include a library with npm-deps it does go through the full Closure compiler along with the rest of your code. So no externs involved and DCE and all the goodness IF that library happens to be compatible with Closure, but a lot of JS code out there is not compatible with Closure at all and can yield anything from compilation errors to compilation going fine but the resulting code not loading to code running fine under whitespace and simple but completely breaking down in advanced compilation.
I agree that CLJSJS provides actual value but overly optimistic or unaware users could still get ‘Caught in the Pit of Despair’ as explained in this talk by @spinningtopsofdoom: https://www.youtube.com/watch?v=tpXfASdPteI&t=8m10s
I'm not sure where the best place to ask this is, so I will try here first. Say you have a Clojure/ClojureScript app which is bundled into a JAR. The Cljs part is browser based. It has resources for the cljs/js stuff in usual place resources/public/....
Now when this thing is used - deps pull it in and requires (in both Clj and Cljs) make it available - is there a way to add new 'resources' (in the common sense) that augment those in resources...
?? I suppose this is a general web/web-server/browser question...
@jsa-aerial or do you just mean adding more at run time for a certain instance?
Yeah, the 'app' is a lib
hmmm I have some vague ideas on how that could work with the new tools deps system, but not absolutely sure, and would depend on the build tool. For lein I'm not sure. I don't recall trying it.
@U050PJ2EU To be honest, I just don't know enough to have an idea. Thanks for the response though!
But I mean, I'd imagine you could slurp some files and populate some java properties io/resource
I have a couple of React components, in JS, which I'd like to compile alongside my ClojureScript app (using :foreign-libs
). Unfortunately, they're using ES6 imports to import each other, which CLJS doesn't support (reportedly due to Closure not yet supporting it). What are my options for being able to compile these components with CLJS?
I've tried transforming them to CommonJS, with babel, but CLJS still doesn't handle the requires. I've tried combining them, with webpack, but I get back a bundle that does a bunch of eval
calls and, when I require it within CLJS, the ns object I get back is empty. I don't know enough about the JS ecosystem to try much more just yet, so I'm hoping there's a more trodden path.
@jeaye you can try https://shadow-cljs.github.io/docs/UsersGuide.html#classpath-js example here https://github.com/shadow-cljs/examples/tree/master/babel
I'm up for any solutions which work, really, provided I can still use leiningen as well. Looks like shadow-cljs can, but I've never used it.
your bundle is a single foreign lib that can provide whatever you want - and with global exports you get externs inference automatically
Right, as mentioned, I have give this a go and webpack was the only way I could get CLJS to require the JS without issues. However, the object I get back when I require (if I js/console.log
it) is empty.
but anyways - that’s the trodden path - far as I know it’s working for people and I’m using it myself on something for work
This is how I'm using it: https://gist.github.com/jeaye/d607c2aeead2aece13478ddb23bfdef2
Similarly, if I require it from Node, I get an empty object just the same. Is that supposed to be the case?
const dist = require('./dist/bundle');
console.log(dist); // {}
@dnolen Ok, found it. Seems to me like the webpack CLJS guide would need to be updated. https://github.com/webpack/webpack/issues/1625
I needed:
output: {
path: path.resolve(__dirname, 'dist'),
filename: 'bundle.js',
libraryTarget: 'commonjs', // added
library: 'UI' // added
},
Contributing updates to http://clojurescript.org is fairly easy: https://clojurescript.org/community/contributing_site