This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # beginners (25)
- # boot (30)
- # cljs-dev (22)
- # cljsjs (2)
- # cljsrn (1)
- # clojars (4)
- # clojure (223)
- # clojure-boston (1)
- # clojure-dusseldorf (1)
- # clojure-gamedev (8)
- # clojure-italy (5)
- # clojure-russia (122)
- # clojure-sg (3)
- # clojure-spec (26)
- # clojure-uk (42)
- # clojurescript (69)
- # clojuresque (10)
- # core-async (25)
- # cursive (10)
- # datascript (5)
- # datomic (12)
- # emacs (18)
- # garden (1)
- # interop (1)
- # jobs (1)
- # jobs-discuss (10)
- # leiningen (2)
- # liberator (1)
- # lumo (21)
- # nyc (2)
- # off-topic (210)
- # om (11)
- # om-next (3)
- # onyx (1)
- # pedestal (6)
- # re-frame (10)
- # rum (9)
- # specter (38)
- # uncomplicate (1)
- # vim (23)
- # yada (22)
So - I am using moment.js wrapped by cljsjs and in writing a small wrapper, I've realised I'd like to actively check that an incoming argument is a moment.js object - in Clojure I could write something like: [^String arg] or write a precondition check. What would I do in ClojureScript ?
@hlolli cool 🙂 that solves my current predicament, but I'm actually also interested in the general case, what do we do ? JS uses 'typeof' for such checks, is there a decent way of writing such code in ClojureScript in general ?
yes you can use a cljs/clj function
type. You can create your own types. You may want to look into clojure.spec too.
you can use externs from cljsjs and is most likely going to be a faster process using cljsjs than struggling to add externs yourself, otherwise if you set up :foreign-libs right with externs, there's no advantage, same effect.
well, adding that they alsa minify and uglyfy for advanced compilation, you'd have to do that yourself (giving that the lib in question doesn't provide .min.js version)
@urbank bingo, along with some other types of goog.closure compilations, tough Im mostly familiar with :advanced.
@urbank can't say I have much experience, but ease of use I think. Anything cljsjs wrapped is as easy as adding the dependency to your
project.clj if you're a lein-heathen :P), then adding the require line somewhere in a cljs file and you're basically off to the races.
Ok, thanks guys! And yeah @pseud , currently a lein-heathen, not opposed to using boot though. Mostly just glad when it compiles, so I can leave that config file alone (for now) 😛
@thheller I figure it's better that I learn how to do that myself, for when something isn't already packaged or goes out of date
@urbank that argument could be made for substituting libraries for your own code, and languages for your own, and so on 🙂 It's up to you to decide what becomes an abstraction and how many problems you want to solve yourself 🙂
@pseud True, but I feel like encountering a library that hasn't been cljsjs-fied or is out of date is bound to happen 🙂
@urbank you could also take a look at the closure library date stuff. it pretty much provides everything moment does but integrates way better and supports
what's the point of clojure spec's fdef ? If I check against my specs using pre & post-conditions, I will get failures at the point of invocation, but having defined a function spec doesn't really prevent the function returning a non-compliant value (and I assume the same is true for providing wrong input)
There is #clojure-spec @pseud
(copying a question from the http://expo.io slack channel, because it’s probably a generic clojurescript thing)
hey, clojurescript people: I started tinkering around with the default project that results from
lein new exponent and this is my first look at expo, react, re-frame, and clojurescript. If I add
[cljsjs/socket-io "1.6.0-0"] to my dependencies and restart everything including the simulator, emacs, cider, figwheel, and exp — and then try to
(require 'cljsjs.socket-io) I get the error
goog.require could not find : cljsjs.socket_io. Clearly I don’t understand this tooling (and the downside to lein templates is that one doesn’t get the learning experience of putting it all together). Any clues? what am I missing?
(require 'cljsjs.socket-io) being tried in the repl or on a cljs file?
In the repl
In the cljs.user namespace
@gonewest818 the exponent stuff may be a red herring, probably worth checking in chestnut 🙂
@dominicm alas, until I actually understand things, it’s just trading one kind of magic for another…
@gonewest818 chestnut is a standard cljs setup (for the browser). I'd try socket-io there. If it still errors, the problem is with the pkg, otherwise it's with exponent.
I'd go through the quick start first (https://clojurescript.org/guides/quick-start) if this your first look at clojurescript
fair enough, rtfm
Here's a guide through some clojurescript basics (https://github.com/magomimmo/modern-cljs)
@gonewest818 getting the clojurescript compiler options right can be tricky, which is exactly why people like to start with something like Chestnut. Yes it deprives you of a certain learning experience, but at least it prevents people from getting so frustrated they drop off before achieving anything
reading the quick-start is a great starting point to get your essentials down. I would also try generating a chestnut project separately and copy over the :cljsbuild stanza from
No arguments. As a newcomer, I had hoped exponent would play that role in my ramp-up experience, but perhaps not.
I'm not familiar enough with exponent to comment on that... to give you some useful feedback at least, the error you're getting could be due to a missing/wrong
if you really want to grok those compiler options and if you have a few dollars to spare I can heartily recommend this Lambda Island episode on the subject https://lambdaisland.com/episodes/clojurescript-compiler (shameless plug)
@plexus - thanks, perhaps someday. I’ll start from the clojurescript guides and the modern tutorials as suggested.
@dominicm Using chestnut I can add the project dependency and
(require 'cljsjs.socket-io) in the browser repl. Suggests the packaging is okay.
@gonewest818 If you're getting into this to learn, I will mention that exponent is a pretty new area afaik, so things may still be a little wonky. I'd recommend building up a cljs app from scratch 🙂.
:refer-clojure :rename work in CLJS? I'm still getting warnings when compiling.
@tech_hutch should work. which version of CLJS are you using? https://anmonteiro.com/2016/08/clojurescript-require-now-supports-rename/
I'm using the latest or close to the latest version.
oh you mean
I don’t recall if I implemented that
The article says it should work
yeah looking at the source it should be there
Okay. I'll try updating CLJS real quick.
(I haven't set up my project with lein yet, so I'm just downloading the jar file manually.)
there might be a bug somewhere
although there’s a test for it https://github.com/clojure/clojurescript/blob/master/src/test/cljs/cljs/ns_test.cljs#L10
@anmonteiro I'm still getting the warnings.
Wait, never mind.
I just compiled again, and there aren't any.
When doing a compilation with
optimizations :advanced, I end up with a 300 kb js file. My deps are cljs and reagent. I know I’m pulling in React, but the final file size still sounds a bit large to me?
[org.clojure/core.async “0.2.395” :exclusions [org.clojure/tools.reader]] was supplied by the figwheel template. Is it needed for anything? And if not, is it automatically removed by the advanced compilation?
No, I wasn’t aware. In that context 300k does not seem like a lot. And you’re right, it’s gzip’ed. It’s just not obvious in Chrome’s devtools
Ah, nginx wasn’t configured for gzipping anything but html. Now it went down to ~80k. Thanks for the pointers 🙂