Fork me on GitHub
#clojurescript
<
2019-01-24
>
Karol Wójcik08:01:20

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

john17:01:02

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 https://clojurians-log.clojureverse.org/clojure/2018-08-08/1533739640.000300 And another example of conditional requires based on what's available in the cljs.analyzer/constant-table: https://clojurians-log.clojureverse.org/cljs-dev/2019-01-08/1546981037.172600

john17:01:52

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])

roman01la09:01:27

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

roman01la09:01:42

so you can’t do conditional require for example

roman01la09: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

roman01la09:01:16

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

thheller09:01:06

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

roman01la09: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)

carocad12:01:33

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 😕

roman01la12:01:42

do you mean actual Response instance?

roman01la12:01:09

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

carocad13:01:35

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

thheller13:01:20

@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

thheller13:01:27

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

thheller13:01:48

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

carocad13:01:41

> 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.

thheller13:01:28

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

carocad13:01:46

> 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

thheller13:01:23

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?

borkdude14:01:47

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

dnolen14:01:50

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

dnolen14:01:03

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

dnolen14:01:07

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!

borkdude14:01:00

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

mseddon22:01:37

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:

darwin14:01:16

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 1
manu17:01:17

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

victorb17:01:40

@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

manu17:01:54

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

ag19:01:54

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.

thheller19:01:57

try shadow-cljs 😉

bhauman19:01:34

@ag you set it to :target :nodejs

bhauman19:01:09

I’d love to hear your troubles

bhauman19:01:36

I haven’t gotten around to the nodejs tutorial yet

bhauman19:01:02

@ag So much to write so little time

ag19:01:31

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.

ag19:01:30

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.

bhauman19:01:34

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

👍 1
bhauman19:01:02

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

ag19:01:47

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

bhauman19:01:33

Not just the docs.

👍 1
😕 1
borkdude20:01:22

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

borkdude20:01:02

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.

ag20:01:38

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

dpsutton20:01:40

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

borkdude20:01:08

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

dpsutton20:01:56

in cursive?

borkdude20:01:48

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

dpsutton20:01:10

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

ag20:01:28

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

borkdude20:01:24

so adding -t node should do the trick

ag21:01:20

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

bhauman22:01:20

Unfortunately that’s not a feature right now.

ag05:01:01

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

john22:01:57

You could maybe canabalize this and print file updates to the repl in a macro https://github.com/stuartsierra/lazytest/blob/master/modules/lazytest/src/main/clojure/lazytest/watch.clj

idiomancy22:01:39

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?

idiomancy22:01:43

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

john22:01:45

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

idiomancy22:01:26

my interest in them is essentially page composition https://micro-frontends.org/#page-composition as described by the micro frontends folks

idiomancy22:01:25

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

john22:01:38

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.

john22:01:52

(as keywords)

thheller23:01:09

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

thheller23:01:20

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

thheller23:01:37

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

✔️ 1
thheller23:01:14

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

idiomancy23:01:11

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

idiomancy23:01:58

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

idiomancy23:01:25

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

john23:01:18

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

john23:01:42

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

idiomancy23:01:39

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

idiomancy23:01:06

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