This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-12
Channels
- # adventofcode (6)
- # beginners (148)
- # boot (5)
- # calva (1)
- # cider (10)
- # cljdoc (10)
- # cljs-dev (8)
- # cljsrn (10)
- # clojure (180)
- # clojure-dev (24)
- # clojure-europe (2)
- # clojure-finland (1)
- # clojure-italy (32)
- # clojure-losangeles (1)
- # clojure-nl (40)
- # clojure-spec (10)
- # clojure-uk (44)
- # clojured (4)
- # clojurescript (88)
- # community-development (33)
- # core-async (7)
- # cursive (19)
- # datomic (98)
- # duct (3)
- # events (1)
- # figwheel-main (10)
- # fulcro (62)
- # leiningen (23)
- # luminus (18)
- # off-topic (19)
- # pedestal (6)
- # re-frame (46)
- # reagent (21)
- # ring (17)
- # ring-swagger (3)
- # shadow-cljs (94)
- # slack-help (9)
- # spacemacs (14)
- # sql (1)
- # testing (4)
- # tools-deps (14)
👋 Hi - could anyone point me towards the docs (or a guide) for clojure.browser.dom
?
(coz I'm really not succeeding in making an element at the moment and it's making me a bit sad 😞 )
(or should I just be using goog.dom
?)
Yeah, iirc, clojure.browser.dom is a vestigial artifact of history. Better to just use goog.dom
Oh thank goodness I thought I was going mad 😄
so I guess me next question is... any good places to get started with goog.dom
?
hahahaa
That's great - as long as I'm not missing anything obvious I'll just have some fun hacking and exploring
Yeah, mostly googling. And the google closure docs for goog.dom. I mostly use a mix between goog.dom and direct js interop, for sometimes a one-off .getElementById
etc
Here's a nice utility
(defn $>
([child]
(if (map? child)
(let [{:keys [el tag class]} child]
($> el tag class))
($> child nil)))
([child class]
($> child nil class))
([child tag class]
(gdom/getAncestorByTagNameAndClass child tag class)))
I have clojurescript question. I have Clojure function:
(defn re-pos-map [re s]
(loop [m (re-matcher re s)
res {}]
(if (.find m)
(recur m (assoc res (.start m) (.group m)))
res)))
which returns position of the match and match itself.
However re-matcher
is not in class core.
How would one achieve solve this? Any ideas?you probably have to restructure it to use the Javascript Regex library with interop.
@gypsydave5 this is the API documentation for goog.dom
: https://google.github.io/closure-library/api/goog.dom.html I find this mostly nice to work with but YMMV
Re: yesterday’s discussion about code size. Not sure about cljs size transfer in the “normal” case. There is one area where I think it makes cljs impractical/harder to sell, which is making cljs libs for JS consumption.
Yes, many of them. Some like typescript would work (I think). Clojure has some facilities since 1.6 ( https://clojure.org/reference/java_interop#_calling_clojure_from_java ) although the situation is admittedly trickier in JS-land.
yeah clojure is ultimately a java library since the beginning. the new stuff added in 1.6 was just convenience, it did work before that.

An example of a CLJS lib meant to be consumed from JS: https://github.com/swannodette/mori
is there an easy way to perform a deep macroexpansion inside a macro targeting clojurescript ?
If you’re using re-frame but you want state that resets when a component is mounted is it acceptable to use atoms or is it recommended to keep it all in re-frame?
I use atoms for state that only one component ever cares about, e.g. “Is the tooltip visible or hidden?” If you need to share state info with any other component(s), I’d say put it in the app-db.
Thanks, that’s exactly the locality and granularity I’m thinking of. Do you have an example of that I can see?
Yeah, https://github.com/manutter51/woolybear/blob/master/src/cljs/woolybear/ad/containers.cljs#L171
I use ratom
not atom
so the component re-renders on state changes, but same basic idea.
I saw that, had no idea ratom
existed until seeing your example. That really simplifies things.
:thumbsup:
hi folks, I get a stubborn null
from an external js library, wanted to convert it to nil
using js->clj
but it doesn’t seem to work
you sure it's not a String
"null"
@nooga?
the problem with creating JS libraries with CLJS is that you have to include the CLJS runtime
this is a problem for any compile-to-JS language with a runtime, e.g. ReasonML/BuckleScript, PureScript, etc.
TypeScript and Flow don’t have to worry about this because they have little-to-no runtime
some co-workers did a POC building a React component for distribution via NPM using CLJS, and I’m having to convince them not to actuallyp use it
@borkdude see above. there was no question on how to do it, rather a statement that it is not ideal.
I know. Just thought I’d mention it since it’s relatively popular, so it shows it is done in practice.
@lilactown to some extent the problem even exists in "simple" modern JS that is transpiled by babel and depend on different versions of the babel-runtime
since people always put the compiled code on npm rather than the uncompiled "standard" JS 😞
there doesn’t seem to be a way to compile CLJS, but elide the runtime (e.g. cljs.core)?
but that would only make things worse as you'd need to depend on an exact version of the runtime with the exact same compiler settings used to generate it
I have two use cases in mind: 1. At work we have a design library that is a collection of React components distributed via NPM. We’d like the ability to write them in CLJS. 2. For https://github.com/Lokeh/punk, I want the ability to allow users to provide custom viewers as additional .js files they load on the page, since the UI application is already compiled and distributed as a single bundle
sounds like (1) is out just because it would be prohibitive to use in a production setting due to bundle size
well shadow-cljs fully supports JS so you can always use that to combine JS + CLJS 😉
😄 well re: (1) we are 💯 using shadow-cljs on our application, but there are some other applications that are “simple” JS/Webpack apps that I don’t want to force another tool on them
btw I'm pretty close to building something like punk directly into shadow-cljs since I have the easy hookups for it everywhere 😛
I’m going to completely redesign the UI pretty shortly. I’m trying to do more research on what other langs are doing, like the common lisp inspector / smalltalk UIs / etc.
can anybody give me a pointer, how do I get so called "bootstrapped compiler" in my clojurescript code? in recent version its already available or do I need to compile with some special flags with compiler api?
@nagarajan you need to include cljs.js
basically
no. bootstrapped must use :simple
for the entire build and will not work with :advanced
How this relates to :bootstrap
option in shadow-cljs? is shadow-cljs bootstrap option built on top of this?
yeah it works a bit differently in shadow-cljs as it can pre-compile library code and such. see https://code.thheller.com/blog/shadow-cljs/2017/10/14/bootstrap-support.html
Thank you kindly for your help. I had an idea to build something similar to codepen for clojurescript. I would probably need to load the libraries on demand dynamically. I am prepared to write the custom loading logic for provided namespaces. So how should I proceed you think?
otherwise you just need to provide the proper functions to load the files. not actually sure how all of that works anymore. self-hosted is complicated 🙂
I have a rough idea how to implement the loading library codes in the browser. Even with js dependencies I have a prototype working., which loads js from npm (through a third-party service) and functions available. I am now kind of hazy on clojurescript cljs.js
part. Can I follow the official doc of the namespace in a shadow-cljs project?
ok. Official doc said macros are supported. Is there any gotchas in your experience on that?
I have no clue. I have never used self-hosted myself in an actual project. macros did require extra work in the :bootstrap
target, not sure how it works if you don't precompile them
ok. So, the :bootstrap target is still required if I plan to use cljs.js
directly in shadow-cljs project?
you must initially "bootstrap" the compiler by loading the analyzer data for the core namespaces
other CLJS compiles just inline that data as code which makes it much larger than it needs to be
envy: a little tool that smooths over importing of :closure-defines
data from a ClojureScript project's cljs.edn
file into an env
var that you can use at runtime - https://github.com/johnmn3/envy
greetings! I can't alias
a keyword/symbol in clojurescript, can I? (except creating and requiring ns file)