Fork me on GitHub
Karol Wójcik08:01:20

Is there a way to require a module outside ns macro?


You could try this hack. I don't remember if I tested in advanced compile mode. It'd be interesting to find out. Parameterizing requires using clojure-defines And another example of conditional requires based on what's available in the cljs.analyzer/constant-table:


But specifically, those hacks are parameterizing the ns declaration, not calling require outside of the ns declaration

Christian Johansen08:01:24

(require '[your.namespace :as yn])

Roman Liutikov09:01:27

yeah but it works only in dev, it won’t compile for production

Roman Liutikov09:01:42

so you can’t do conditional require for example

Roman Liutikov09:01:27

unless using a macro

Karol Wójcik09:01:37

so if i wrap it in macro

Karol Wójcik09:01:46

then it will just work perfectly fine

Roman Liutikov09:01:16

ooooh, wait no, I’m wrong, it won’t work anyway 😄


conditional require is not possible due to how the closure compiler works. if you want to include dev only stuff use :preloads

Roman Liutikov09:01:57

basically require on itself is a dynamic import in cljs which works only in dev (unless you ship the whole compiler into a browser and implement IO layer to make require work) and require in ns form is a static import

David Pham12:01:45

@thheller Hello 🙂 Thanks a lot for your work with shadow-cljs. I wanted to know if there exists a way to define dependencies depending of your build key? For the context, re-frame-debux require two different version depending on the optimization profile (one for dev and one for release)


hey guys, has anyone experience problems with js->clj on Javascript class instances ? I tried to use it on the Request/Response object from fetch api but it couldnt convert the object. My guess is that it is because the constructor is not js/Object but something else 😕

Roman Liutikov12:01:42

do you mean actual Response instance?

Roman Liutikov12:01:09

why not read response body and then apply js->clj?


because the body doesnt contain the http status, and all other header stuff that I would like to check


@carocad js->clj is only really meant for JSON-ish data. it can't properly convert class instances unless you tell it how by implementing the IEncodeClojure protocol for those classes


(defprotocol IEncodeClojure
  (-js->clj [x options] "Transforms JavaScript values to Clojure"))


but it is probably best to just use normal JS interop to transform the obj


> js->clj is only really meant for JSON-ish data hey @thheller , the thing is that those objects are “json-ish”. The hack that I used to solve that was to do (js/JSON.parse (js/JSON.stringify object)). Which does the job but feels wrong as hell.


that is indeed hacky as hell. doesn't make the data any more json-ish though. 5 lines of code that extract the properties you want will definitely make that faster and less error prone


> doesn’t make the data any more json-ish though fair enough. Is there any way to know in advance is an object is json-ish ? So far my understanding was that js->clj would traverse an object the same way that js/JSON.stringify does


it does for JS objects but not for custom classes

Timo Freiberg14:01:18

hey everyone, is there some way to view the available fields/methods of a js object in the cljs repl?


goog.object has some nice functions

Timo Freiberg14:01:48

i can't get a repl (or the debug mode) working in firefox, so i want to explore the objects i'm receiving in my cider cljs repl, but i have no idea how to interact with something like #object[SyntheticEvent [object Object]]

Timo Freiberg14:01:27

hmm, maybe cider isn't perfect for cljs (or the js interop part of it), but i get no autocompletion for goog.object, although the import seems to be successful

Timo Freiberg14:01:27

seems i have to google stuff anyway 😓 simply calling (goog.object/getAllPropertyNames some-event) works, of course


@timo.freiberg also sometimes it's simpler to console.log the thing and inspect in the browser


this is true even for ClojureScript values if you're using Chrome due to cljs-devtools

Timo Freiberg14:01:33

ah true, i forgot that the value inspection feature works with values printed to the console as well as in debug mode


REBL is probably an even better answer in the long run but I think you'll encounter sharp edges at this time

Timo Freiberg14:01:09

i suspect console.log will suffice for now, thanks a lot for the help!


does REBL support clojurescript? I really have to watch that talk soon


There was no explicit mention but Stuart said "I can't wait to see what the ClojureScript people do with this". Read that as you will. :thinking_face:


btw. at some point I’d like to support REBL-like traversing of datafy-ed structures in cljs-devtools (similar to how meta data are offered today), just waiting for this to get some tangible use-cases

aw_yeah 5

Hi! how do you test API responses made by fetch? Thx


@manu usually split up the thing in request and response. Then response usually just calls some other functions that does the parsing/formatting of the data to the right format, and request ends up hitting some endpoint that I start when running the tests, but that's it


@victorbjelkholm429 I would like to simulate the fetch response (so obtain a promise) and handle this promise..


Can someone point me to a barebone example of figwheel-main project that has no browser at all, just nodejs? Honestly - I do understand now when newcomers complain - it can be truly, utterly confusing to start a Clojurescript project from scratch. And I’m not new to Clojure.


try shadow-cljs 😉


@ag you set it to :target :nodejs


I’d love to hear your troubles


I haven’t gotten around to the nodejs tutorial yet


@ag So much to write so little time


Honestly I’m not trying to complain for the sake of it. I’m just trying to be emphatic for people who would like to try something without having to dig through ton of docs.


Landscape of Clojurescript right now could be so confusing for a newcomer. We have lein, we have boot, we have figwheel-lein, figwheel-main, shadow-cljs… And none of them feel like “idiomatic” way of doing things.


I agree. I’d call figwheel-main the idiomatic way of doing things. But you are correct that there has been no written blessing.

👍 5

Are you struggling with setting up a hello world nodejs project?


sigh… I think we just don’t have enough people willing to contribute to the docs. Somehow I think we (Clojurists in general) tend not to care about documentation much


Not just the docs.

👍 5
😕 5

a simple example of how to compile a nodejs project without reloading, just using CLJS:

clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "RELEASE"}}' -m cljs.main -t node -c your.main-namespace


or to get a REPL:

clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "RELEASE"}}' -m cljs.main -re node
and then you can reload your namespace after making changes, like:
(require '[your.namespace] :reload)
This should already get you going.


No, that easy I get it… but once you want to add “reloading” to that… it suddenly becomes a bit more complicated


those things don't have an integration with editors. not sure how that's a realistic thing to try to use in anger


Maybe I’m missing something, but I use this all the time.


in cursive?


for testing code in Node I mean. No, I just open a REPL in a terminal. Edit text in Emacs. Then call :reload in the REPL


ah yeah. i can't imagine 8 hours of development without navigation, completion, and doc


guys… guys… I just need the barebones minimal example of figwheel-main on nodejs. For demonstration purposes. What do I need? - deps.edn file

{:deps {org.clojure/clojure {:mvn/version "1.9.0"}
        org.clojure/clojurescript {:mvn/version "1.10.339"}
        com.bhauman/figwheel-main {:mvn/version "0.2.1-SNAPSHOT"}}
right? so now if I do: clj -m figwheel.main - that thing opens a browser and connects repl to it. I do not need browser


so adding -t node should do the trick


@bhauman Node output being logged to: target/node/dev/node.log how do you change it to go directly to the repl/nrepl buffer?


Unfortunately that’s not a feature right now.


meh… no matter how hard you try - you won’t deter me from using figwheel-main. It’s so fucking awesome


You could maybe canabalize this and print file updates to the repl in a macro


so webcomponenets in cljs. the last library that seemed to deal with them was archived 3 years ago. Only within the last couple months has the webcomponent standard been implemented on all greenfield browsers (not counting edge since its going soon anyway) Am I missing something about why theres not much ecosystem support for this kind of thing? is it all just really easy to implement with regular interop? do web components suck? has just no one gotten around to building a library for it?


Im asking because I'm not an expert in webcomponents, but they seem pretty legit


Don't webcomponents allow you to use custom element names in your html?


my interest in them is essentially page composition as described by the micro frontends folks


basically, different teams build different products that are exposed via a web ui that can be embedded in other web uis to create a larger, integrated web product


hmmm. I suppose, if you could define webcomponents in cljs, and then just drop their element names in your hiccup forms, it'd probably work.


(as keywords)


> Each team builds their component using their web technology of choice and wraps it inside a Custom Element (e.g. <order-minicart></order-minicart>).


IMHO this line alone tells you why web components are not a good idea


definitely don't want to include 15 different tech stacks in your page since it will be gigantic

✔️ 5

rather settle on one and use it everywhere for which the CLJS community pretty much adopted React


I mean, that hardly seems like a reasonable objection for a strategy of decoupling services


if page load time is a problem, then you can establish conventions for which technologies are to be included in the composed page


personally, I see all the webcomponents in our stack being react based, but there are legacy structures which are not currently react based, and I'd like to be able to replace it one vertical at a time


All I know is, they put many years of effort into that standard... Hopefully it's good for something


I think they advertise it as "like react components but now built into the web" so maybe they're shipping with some extra efficiencies built into the engines and browser code-bases


yeah, ironically, they apparently don't play well with react's synthetic events yet :/


sigh... apparently they work great in vue, lol