Fork me on GitHub
#clojurescript
<
2018-08-17
>
dangercoder06:08:14

Anyone with a link to a good tutorial on how to debug CLJS? I've tried it in dev tools och chrome but I can't set breakpoints everywhere

mikethompson06:08:18

@coderdanger I don't have a tutorial for you but cljs-devtools is an essential tool. Optionally, consider dirac

mikethompson06:08:02

Be sure to compile with source maps. Breakpoints etc, should all work.

restenb07:08:45

What's the preferred syntax for accessing vars in JS objects?

restenb07:08:58

like, object.thing will work, but is there another way?

biscuitpants09:08:40

for CLJS macros, can we use this syntax [cljs.core.async.macros :refer [go]] or do we still need to do require-macros ?

thheller09:08:37

use (:require [cljs.core.async :refer (go)]). the :require-macros is no longer required (assuming you are using a somewhat recent core.async version)

biscuitpants09:08:34

nice that works perfectly. thank you

restenb10:08:23

hm. no such thing as <!! and >!! in ClojureScript?

thheller10:08:44

@restenb no. JS engines can't block.

restenb10:08:21

so I have to use (go (<! instead ?

restenb10:08:32

will it still block execution of whatever form it's in until the take has been completed?

restenb10:08:49

so I can use it inside of let's without much thought

thheller10:08:11

once you go async everything is async. there is absolutely no blocking IO in Browser JS engines.

thheller10:08:13

(go (let [thing (<! ... is fine if you mean that though

restenb10:08:30

so i do need to block until one operation finished before doing the next

restenb10:08:35

would this be the way to do it?

thheller10:08:54

that would be a way to do it yes. what is "best" entirely depends on what you are actually doing and how you program is structured. not something that can be answered simply.

restenb10:08:18

well, I need to wait on (do-async-operation) before proceeding with another async operation which depends on the first

restenb10:08:25

then return the result of the second operation

ClashTheBunny12:08:05

@iagwanderson, on macOS inside of a tmux, you need to do a set-option -g default-command "reattach-to-user-namespace -l fish" to access os resources.

bartuka12:08:34

@clashthebunny thanks! works fine now. o/

restenb14:08:08

yeah don't need the loop so just go is equivalent

馃憤 4
qle-guen14:08:27

Hello, I am looking for a way to import node modules from clojurescript. I'm tried using lein-npm. The node modules are downloaded in the right folder (at the root of my compiled js folder) but I don't know how to import them. Anyone could guide me? Thanks.

restenb14:08:27

@qle-guen Just use (node/require ...) ?

qle-guen14:08:54

Hmm yes I could do that I guess. I was wondering if there was a more clojure idiomatic way.

restenb14:08:11

depends on what you need to do really

qle-guen14:08:25

I was looking into that but it doesn't really play well with lein-npm because it would require another additional field than :npm in the project map

qle-guen14:08:51

besides, I have multiple compilation targets, and it doesn't feel right to use npm-deps for each of them

qle-guen14:08:17

I don't know what macchiato is. I will look into that.

restenb14:08:05

it's a framework for node webapps, just with clojurescript as target language

restenb14:08:34

including a clojure friendly rest api for node's webstack

qle-guen14:08:25

I'm currently using re-frame, not sure it would get along well

restenb14:08:18

if you just want to use a couple of node modules you should just include them as :npm-deps and use (node/require ...)

qle-guen14:08:38

yes you're right

qle-guen14:08:46

seems like the easiest way

restenb14:08:48

if you want a proper Node server with direct clojurescript capability, I would recommend macchiato

qle-guen14:08:48

I'm getting node undefined with (:require [cljs.node as node]) what am I doing wrong?

qle-guen14:08:54

yeah I got :as sorry, I think I would have a compilation error otherwise

restenb14:08:38

it's cljs.nodejs, not cljs.node

qle-guen15:08:14

damn sorry, that's actually what I wrote

qle-guen15:08:38

(ns xxx
  (:require
   [re-frame.core :as re-frame]
   [xxx.subs :as subs]
   [clojure.string :refer [join]]
   [cljs.nodejs :as node]
   ))

qle-guen15:08:58

I have the intuition that that import is valid on a node.js environment

qle-guen15:08:10

but my target is the browser

Karol W贸jcik15:08:13

If you target browser then it鈥檚 not possible to include nodejs

qle-guen15:08:46

but require is available on the browser too? I think

Karol W贸jcik15:08:02

Imo you should include the dependency in the compiler section. Then simply require it from js form

Karol W贸jcik15:08:29

What tool do you use?

qle-guen15:08:43

problem with including it in project.clj is I have multiple builds. It seems to me that I would have to include the deps in every build.

Karol W贸jcik15:08:55

I mean figwheel, shadow, lumo?

qle-guen15:08:12

cljsjs, interesting

qle-guen15:08:19

nvm, the module I need isn't listed there

Karol W贸jcik15:08:34

Ok what Clojurescript version do you use?

Karol W贸jcik15:08:15

There are multiple ways we can actually handle that problem don鈥檛 worry ;)

Karol W贸jcik15:08:40

Project.clj is a normal clj file. You can define you dependencies there then use it in you builds.

qle-guen15:08:03

I've actually tried defining the deps before defproject:

(def npm-deps
  {:react-youtube "7.6.0"})

Karol W贸jcik15:08:27

And what鈥檚 the problem?

qle-guen15:08:41

here is the error I got:

------ Figwheel Configuration Error ------

The key :npm-deps at (:cljsbuild :builds 0 :compiler) has a non-conforming value: npm-deps
It should satisfy one of: Map | false?

/home/void/wp/pasteurdaniel/project.clj:38:20
  33                     :output-to            "resources/public/js/app.js"
  34                     :output-dir           "resources/public/js/out"
  35                     :asset-path           "js/out"
  36                     :source-map-timestamp true
  37                     :preloads             [devtools.preload]
  38                     :npm-deps             npm-deps
                         ^---  The value at key :npm-deps doesn't conform
  39                     :install-deps         true
  40                     :external-config      {:devtools/config {:features-to-install :all}}
  41                     }}
  42 
  43     {:id           "min"

Karol W贸jcik15:08:10

What clojurescript version you are using?

qle-guen15:08:58

@kwcharllie379 [org.clojure/clojurescript "1.10.238"]

qle-guen15:08:22

it works when I manually replace the value

Karol W贸jcik16:08:50

Try ~npm-deps or 'npm-deps

Karol W贸jcik16:08:57

Let me check it

eccentric J16:08:50

I鈥檓 having a bit of trouble using node鈥檚 http.request method, throwing an error that a listener argument is a function (at bottom of snippet). Anyone have experience with the http.request js interop?

mfikes17:08:30

@jayzawrotny In your example, request-params is a ClojureScript map. You probably want to pass a JavaScript object, right?

eccentric J17:08:10

Ooof鈥 that will probably do it!

mfikes17:08:30

Put a #js in front of it, and also in front of the ClojureScript map value for "headers"

mfikes17:08:01

Also @jayzawrotny request appears to take options as its first argument, and a callback as its second argument.

eccentric J17:08:30

Unless I鈥檓 mistaken this call pattern appears to be documented https://nodejs.org/api/http.html#http_http_request_url_options_callback

eccentric J17:08:44

But I鈥檒l try it

mfikes17:08:17

Hrm.

cljs.user=> (require '[http :refer [request]])
nil
cljs.user=> (set! *print-fn-bodies* true)
true
cljs.user=> request
#object[request "function request(options, cb) {
  return new ClientRequest(options, cb);
}"]

mfikes17:08:27

(That鈥檚 in Lumo)

mfikes17:08:13

Maybe not, they appear to have multiple arities鈥

mfikes17:08:48

That鈥檚 a newer Node API right鈥

eccentric J17:08:10

Hmm could be, I鈥檒l try it with the 2 params and see what I get

mfikes17:08:22

Yeah, if you open the history disclosure you can see that that v10.9.0 has 鈥渁llow both url and options to be passed to http.request()` I think Lumo is based on Node 8

eccentric J17:08:52

Interesting, does that mean Lumo has a layer wrapping the node API?

mfikes17:08:35

I don鈥檛 think so. Lumo is Node in a sense.

eccentric J17:08:08

Ah ok, that鈥檚 how I understood it. Though I鈥檓 unclear why it--- Oh. I鈥檓 running Node 9.11.2 馃槥

eccentric J17:08:36

Well it鈥檚 making it to the next step, thanks a ton for the help!

馃憤 4
mfikes17:08:19

But, to be clear, installing Node 10 won鈥檛 change it. Lumo doesn鈥檛 use Node. It is Node in the sense that it is a binary built based on Node 8.

eccentric J17:08:00

I see, that鈥檚 definitely more clear now.

Karol W贸jcik17:08:16

@qle-guen Did you manage to require the react-youtube? I cannot even require it

Karol W贸jcik17:08:34

Tried require also lodash library but I am receiving error module is not defined

Karol W贸jcik17:08:50

It seems that npm-deps should be considered very beta feature

lilactown17:08:27

1. is there a way to start a CLJS repl without a deps.edn file (using -Sdeps)? couldn't get it to work in my ~60s of trying 2. how do I start a rebel-readline CLJS repl?

bhauman17:08:27

clj -Sdeps "{:deps {com.bhauman/figwheel-main {:mvn/version \"0.1.7\"}}}}" -m figwheel.main

bhauman17:08:41

add rebel-readline-cljs to the deps and you are all set

bhauman17:08:22

@lilactown you can get a plain repl with clojure -Sdeps '{:deps {com.bhauman/rebel-readline-cljs {:mvn/version "0.1.4"}}}' -m rebel-readline.cljs.main

lilactown17:08:16

awesome. thanks @bhauman!

lilactown17:08:25

I think the critical thing I was missing is that the dependency map passed to -Sdeps has to be in a top-level {:dep ...} :face_with_rolling_eyes:

lilactown17:08:52

I was also struggling to find the rebel-readline-cljs docs so that's a big help too 馃憤

Karol W贸jcik17:08:19

@qle-guen I'm sorry but I don't know how to help you. Tried everything. I'm more comfortable with targeting nodejs rather then browser.

lilactown18:08:44

@bhauman is there a way to start a browser rebel-readline REPL without figwheel?

lilactown21:08:52

@clashthebunny that starts a Nashorn REPL

dnolen23:08:35

@lilactown do you mean without the building stuff?

dnolen23:08:00

figwheel-main is now pretty cleanly separated into build part / REPL part

dnolen23:08:13

you should be able to use just the REPL part - but I would ask for details in #figwheel-main

lilactown23:08:23

I鈥檓 atm mainly interested in using rebel-readline with a browser CLJS REPL, just like how

clj -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.339"}}}' -m cljs.main
starts one

lilactown23:08:13

I can鈥檛 tell if rebel-readline requires the figwheel-main REPL as well to function in a browser

lilactown23:08:53

@bhauman am I missing something where it explains how to use a Chrome browser runtime instead of Nashorn?

bhauman23:08:59

actually never mind that

bhauman23:08:42

this works how the regular cljs-repl works you pass in a repl env

bhauman23:08:23

@lilactown ^ if you look at the above code and pass a browser repl-env instead of a nashorn repl-env

lilactown23:08:04

would you take a PR that allowed a switch to be passed for --browser or --node?