Fork me on GitHub
#clojurescript
<
2019-06-05
>
Olical08:06:59

Has anyone ever managed to set the current line / column / file path of an evaluation from within a ClojureScript REPL? Edit: Maybe self hosting will do the trick? Just worried that'll mean it's not really the same. I presume there's subtle differences between JVM and self host ClojureScript.

fadrian13:06:47

I'm building a simple web app. In order to call a web service, I'm trying to include cljs-http. I've added the appropriate :require and :require-macros (according to the cljs-http github page) for cljs-http and core.async to my .cljs file, and the reference to [cljs-http "0.1.46"] in my project.clj file, but figwheel still gives me a 'No such namespace: cljs-http.client, could not locate cljs_http/client.cljs, cljs_http/client.cljc, or JavaScript source providing "cljs-http.client"' error. Any idea what gives?

Sturm13:06:51

I feel like I'm missing something obvious. My Reagent component is showing up in the browser with an extra 0s transition timing which breaks the transition. Any idea why?

thheller13:06:23

@ben735 the extra 0s is the transition delay it should not break anything?

thheller13:06:32

div {
    transition: <property> <duration> <timing-function> <delay>;
}

Sturm13:06:03

oh, I see you're right - I must be doing something else wrong, thanks!

fadrian13:06:28

I've modified my ns declaration to be this:(ns http://cql-viewer.app (:require-macros [cljs.core.async.macros :refer [go]]) (:require [reagent.core :as r] [cljs.core.async :refer [<!]] [cljs-http :as http]) )

Sturm13:06:49

@thheller ah I see now, I was assuming that changes would animate when figwheel is reloaded, but that's not the case - thanks for the pointer

fadrian13:06:54

but figwheel still can't find cljs-http. Any idea why it can't find this namespace (or the recommended cljs-http/client that also doesn't seem to work)

thheller13:06:53

@fadrian it should be [cljs-http.client :as http]

fadrian13:06:21

Yeah. That was what I meant when I typed cljs-http/client. Fumbly fingers. In any case, the cljs is not finding this package either. Could there be something in my project setup that's causing cljs-http not to be found? (defproject cql-viewer "0.0.1" :description "A viewer for CQL interpreter output." :dependencies [[org.clojure/clojure "1.9.0"] [binaryage/devtools "0.9.4"] [org.clojure/clojurescript "1.10.238" :scope "provided"] [reagent "0.7.0"] [cljs-http "0.1.46"] ] :source-paths ["src/cljs"] :plugins [[lein-figwheel "0.5.16"] [lein-cljsbuild "1.1.7" :exclusions [[org.clojure/clojure]]]] :cljsbuild {:builds [{:id "dev" :source-paths ["src/cljs"] :figwheel {:on-jsload "cql-viewer.core/on-js-reload" :open-urls ["http://localhost:3449/index.html"]} :compiler {:main cql-viewer.core :asset-path "js/compiled/out" :output-to "resources/public/js/compiled/cql-viewer.js" :output-dir "resources/public/js/compiled/out" :source-map-timestamp true}}]} :figwheel {:css-dirs ["resources/public/css"]} :profiles {:dev {:dependencies [[binaryage/devtools "0.9.9"] [figwheel-sidecar "0.5.16"] [cider/piggieback "0.3.1"]] :source-paths ["dev"] :clean-targets ^{:protect false} ["resources/public/js/compiled"]}})

thheller13:06:08

looks fine. did you restart the process after adding the dep?

fadrian13:06:50

Yes. I've been getting this error since yesterday evening when I tried to add the web service. I've cut and pasted directly from the github page for my setup and I'm not even calling any code from the packages yet - it just can't find the package.

fadrian14:06:49

I tried adding http-ajax and got a similar error. I'm beginning to think I'm cursed by the gods of http.

thheller14:06:35

make sure you are restarting the correct process and stuff

thheller14:06:48

maybe you are in a different directory or some process is still running in the background

fadrian14:06:17

Lein's sitting in the project directory. I've been thinking it might be something in my lein configuration. Any idea where that's stored?

thheller14:06:37

in your project.clj

fadrian14:06:37

Are the repo directories hardwired? Because I swear I've seen a config file holding them (but I might be thinking of my emacs config).

fadrian14:06:53

I'm going to shut the whole shebang down and see if a restart does anything.

fergalbyrne14:06:17

cljs-http README has this: (:require [cljs-http.client :as http]

fadrian14:06:28

Well that was aggravating. I had to shut down lein and restart it. Obvious and annoying in retrospect.

fadrian14:06:33

It's working now.

fergalbyrne14:06:31

I think if you change deps lein figwheel doesn’t pick that up.

fergalbyrne14:06:01

I had the same problem with lein test-refresh.

Chris Swanson15:06:47

hey has anyone recently gotten a clojurescript expo project running ? i tried the lein new expo template but the sdk is too old, and i couldn't figure out which versions of what to upgrade to in order to get it all compatible again

Chris Swanson15:06:18

if so' i'd be eternally grateful for your build config , save me hours...

Jay16:06:22

I think I saw somethings a while back on github regarding this, but not 100% sure.

danielneal16:06:36

hey @chrisjswanson just saw your message in expo - you should definitely join the #cljsrn channel too. We have expo + cljs running, but I'm just going home for the day now, you're right there's a lot of things to figure out in order to get everything up to date, We've ended up making some quite significant changes to the whole thing, hopefully will contribute back at some point, but in the mean time can answer Qs

danielneal16:06:11

You might wanna try shadow-cljs and expo, too, I think I'd be tempted by that if I was starting from scratch today

fadrian16:06:52

I have a map:{"C" {"name" "C", "type" "Library", "evaluated" false, "value" nil, "isConst" false, …} , "E" {"name" "E", "type" "Library", "evaluated" false, "value" nil, "isConst" false, …} , "D" {"name" "D", "type" "Library", "evaluated" false, "value" nil, "isConst" false, …} }

fadrian16:06:43

I'm storing it in an atom @processed-cql and trying to add it to a web page with the hiccup [:p (str @processed-cql)]. However, the hiccup prints [Object object]. How can I get the map to display

fadrian16:06:54

I'm assuming it has something to do with the JS toString() operator, but I am a newbie at Clojurescript.

didibus16:06:28

Is it a JavaScript map? Or. ClojureScript one?

didibus16:06:41

(str {:a 12})
"{:a 12}"
(str #js {:a 12})
"[object Object]"

fadrian16:06:08

The map was originally JSON coming as a string from a web server. I converted it to a JS map using JSON.parse and then converted it to a Clojurescript one using js->clj as shown in the js->clj documentation. I've logged and checked all of the intermediate data from the conversion and it looks good. The final map is a Clojurescript map.

didibus16:06:10

If so, you want to wrap it in a call to js->clj

didibus16:06:37

(str (js->clj #js {:a 12}))
"{\"a\" 12}"

didibus16:06:19

You actually don't need to call str if using hiccup

fadrian16:06:31

I've done that. Here's my code that makes the map: (go (let [response (<! (http/get url {:with-credentials? false})) b (:body response) _ (js/console.log b) json (.parse js/JSON b) _ (js/console.log json) m (js->clj json) _ (js/console.log m) ] m))

didibus17:06:27

So, what you're facing is just typical JavaScript. Objects in JavaScript can't be printed out natively. You need to serialize them to a string to do so. You can use stringify on JSON (.stringify js/JSON #js {:a 12}) if you want.

Roman Liutikov17:06:38

how do you put it into hiccup then?

Roman Liutikov17:06:56

go loop is async, you can’t just return a value from it afaik

didibus17:06:27

But, ClojureScript data-structures natively support being serialized as EDN. So converting to a clj data-structure also works. Which you can do with js->clj

fadrian17:06:44

Which is was what I was doing.

didibus17:06:11

Oh, right. Okay, so it might be a different issue.

didibus17:06:36

Ya, could be your Object is actually a goroutine

fadrian17:06:44

That may be.

Roman Liutikov17:06:47

@fadrian if you want to take return value out of go “process” you have to use a callback

didibus17:06:54

Which also prints as Object in ClojureScript

Roman Liutikov17:06:26

(take! chan callback-render-hiccup)

didibus17:06:32

Can you try calling type on your object?

fadrian17:06:11

Gah... That was it. I just read the documentation a bit more closely. I'll do some quick brushing up on core.async and hopefully I can get around this issue.

didibus17:06:19

If you see cljs.core.async.impl.channels/ManyToManyChannel, then @roman01la is probably right about your issue

Roman Liutikov17:06:18

@fadrian One suggestion is to drop core.async if you are not dealing with complex async flows

👍 12
Roman Liutikov17:06:46

it generates lots of code and also tricks you into thinking stuff is executed synchrounously

Roman Liutikov17:06:05

promises are generally enough

Roman Liutikov17:06:45

(-> (js/fetch url) (.then #(.json %)) (.then #(js->clj %)))

Chris Swanson17:06:07

@danieleneal thanks ! I'll definitely join and catch up soon. have a good evening

didibus17:06:02

Also, it was designed first for Clojure, where you can do a synchronous blocking take for that kind of single value use case. But in ClojureScript, you can't. So it make more sense if you're going to be producing a stream. Like say you were grabbing responses and wanted to process them as they are received.

john17:06:30

"But in ClojureScript, you can't." Not technically, but practically, for now.

didibus17:06:20

Hum.. I'm now intrigued

john18:06:41

Well, now we've got js/Atomics and js/SharedArrayBuffers, which brings genuine blocking to webworker contexts https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Atomics/wait

john18:06:17

So, on that, we could feasibly write a genuine blocking take

john18:06:01

And if you're only passing around typed arrays, which may be the case for some high performance application, it's a pretty low-overhead thing. Unfortunately, structures not already backed by typed arrays will still need to be serialized between worker contexts.

john18:06:27

The future is long though, and it's not hard to imagine a lot of things getting converted to being backed by typed arrays, so they can be freely shared between js/wasm isolates

didibus21:06:57

Hum.. I'm too out of touch with JavaScript and browser contexts to keep track of all these changes 😋

didibus21:06:26

I don't even know what worker contexts are, did JS in browser now has support for threads?

fadrian17:06:04

I'll try that, roman01la. It seems pretty simple. didibus - this is just a debugging jig for a thing I'm writing. It would probably never need high enough performance to stream anything, so his solution is better for my needs. What I am writing will need something like core.async in its implementation, but then I first have the fun of shoehorning clojurescript into a standard node.js server environment, with things like express and webpack and many clojurescript/tool interactions that will make my progress halting. So it goes in the modern world of programming.

Roman Liutikov17:06:13

@fadrian for nodejs you'd probably want to look at Macchiato

fadrian18:06:59

Will do that. I think I have it going now. Thanks for the pointers.

plins23:06:40

hello guys Im looking for a simple FE framework that has some integrated mechanism for validating forms with spec.. is there such thing or should I do it manually ?