clojurescript

ClojureScript, a dialect of Clojure that compiles to JavaScript http://clojurescript.org | Currently at 1.10.879
John Doneth 2021-02-08T02:42:08.049700Z

Does anyone have code coverage working with ClojureScript?

hindol 2021-02-08T05:54:51.051800Z

Hi! I am trying to follow the official Webpack guide here: https://clojurescript.org/guides/webpack On this command, clj -m cljs.main -co build.edn -v -c -r, I am getting the following error,

{:cmd
  59   │    ["npx"
  60   │     "webpack"
  61   │     "out/index.js"
  62   │     "-o"
  63   │     "out/main.js"
  64   │     "--mode=development"],
  65   │    :exit-code 2,
  66   │    :stdout "",
  67   │    :stderr
  68   │    "[webpack-cli] [Error: ENOTDIR: not a directory, open '/home/<user>/Code/<project>/out/main.js/main.js'] {
       │ \n  errno: -20,\n  code: 'ENOTDIR',\n  syscall: 'open',\n  path: '/home/<user>/Code/<project>/out/main.js/mai
       │ n.js'\n}\n"}
I tried removing main.js from this line in build.edn, :none ["npx" "webpack" "out/index.js" "-o" "out/main.js" "--mode=development"], but that did not help. Any ideas?

hindol 2021-02-08T07:04:09.052100Z

Okay, it worked after prefixing all relative paths with ./ and removing main.js from -o. Example,

:bundle-cmd {:none ["npx" "webpack" "./out/index.js" "-o" "./out" "--mode=development"]

hindol 2021-02-08T07:17:55.052300Z

Submitted a PR to the site - https://github.com/clojure/clojurescript-site/pull/370/files

Fredrik Andersson 2021-02-08T08:43:55.065500Z

So I have dived into ClojureScript and Reagent for a brief time now and I have a couple of questions/concerns that I wish to have opinions on from you experienced clojurists. First: Atoms - I realize that they really solve a problem. But they seem to be used somewhat too easily. Especially when looking at Reagent I feel that it's totally fine to scatter ratoms around. I have read that projects tend to collect the atoms over time up to one major atom, but that seems to be problematic regarding to performance, forcing rendering of the whole tree? I can't find any good explanations or recommendations of how to reason about this. Second: Maps and identifiers - Because that's how anyone structures state. {:myidentifier data} with get-in seems to be the way to access state. However I tend to (def my-deep-data [:myidentifier :substructure :name]) then access a value using (get-in mystate my-deep-data) just to make sure that I get compiler errors everywhere whenever i change my data structure. Third: I use Firestore backend. Which I successfully use thanks to shadow-cljs. The challenge I face is managing long term subscriptions to the server. Turning on and off subscriptions based on different states. Is there any good way to handle this?

phronmophobic 2021-02-08T08:48:35.065800Z

have you taken a look at re-frame or fulcro? both of these libraries are aimed at supporting writing more complex user interfaces. if you're already familiar with reagent, re-frame is built on top of reagent and may be easier to get started with

phronmophobic 2021-02-08T08:50:04.066100Z

your second point seems to be similar in spirit to re-frame's subscriptions

phronmophobic 2021-02-08T08:50:37.066300Z

re-frame also has a story around answering your first question

phronmophobic 2021-02-08T08:52:20.066600Z

http://day8.github.io/re-frame/FAQs/DoINeedReFrame/

tvirolai 2021-02-08T09:04:53.067200Z

It doesn't make a difference whether you store all your state in a single or multiple ratoms, as changes to it only trigger a re-render to the affected subtree, not the whole DOM.

Fredrik Andersson 2021-02-08T09:23:53.067400Z

@smith.adriane i looked at reframe and wasn't totally convinced by the subscription solution because it was still "soft" pointers with strings

Fredrik Andersson 2021-02-08T09:26:06.067600Z

@tvirolai I don't understand how that could work? I thought that the ratoms where the guides where in the tree re-render needed to be done? Or is it diffing the whole vdom and swapping out the changed bits?

tvirolai 2021-02-08T09:39:53.067800Z

Correct me if I'm wrong, but I've understood that since Reagent is basically an interface to React, the vdom diffing stuff is delegated to React, which optimizes what needs to be re-rendered.

Fredrik Andersson 2021-02-08T09:41:19.068Z

I think that you are probably right. I just wanted to make sure that it's vdom-diffing that is the technology used.

Fredrik Andersson 2021-02-08T10:25:11.068400Z

i have a question regarding delay

Fredrik Andersson 2021-02-08T10:28:37.069700Z

sorry, i understand the problem now

🙌 2
Francis Hitchens 2021-02-08T22:11:22.076600Z

Hi, this is giving me a headache and any advice would be appreciated. I'm trying to use cljs-node-io {:mvn/version "1.1.2"} in my deps.edn. I got a warning that said this was deprecated and I should use cljs-node-io/cljs-node-io {:mvn/version "1.1.2"}which I did and the warning went away, My source file has this requires in it, (:require [cljs.reader :as reader]            `[cljs-node-io.core :as io :refer [slurp spit]])` but the slurp and spit functions are not defined (nil). What am I missing here? I did see the node-io dependency get downloaded. I get the same error if I try and use it in the repl Execution error (TypeError) at (<cljs repl>:1). Cannot read property 'call' of undefined

p-himik 2021-02-08T22:12:56.076700Z

And what is the problem?

Francis Hitchens 2021-02-08T22:32:58.077Z

the slurp and spit functions are not getting created in my namespace and I can't figure out what I am doing wrong. It does not work in the repl either... (require '[cljs-node-io.core :as io :refer [slurp spit]]) (def data [{:foo 42} {:foo 43}] (spit "data.edn" data) Execution error (TypeError) at (<cljs repl>:1). Cannot read property 'call' of undefined

p-himik 2021-02-08T22:37:32.077400Z

Ah, I see that you have updated the OP. That shouldn't have anything to do with the way you add cljs-node-io to your dependencies. Both cljs-node-io and cljs-node-io/cljs-node-io are absolutely equivalent. As to why slurp and spit are not defined - no idea. If you can't figure it out, create an MRE and I'll take a look. Just in case - the "Cannot read property 'call' of undefined" error can come from within spit. It doesn't necessarily mean that spit is undefined. Have you tried logging the values of spit and slurp?

Francis Hitchens 2021-02-08T22:39:06.077600Z

cljs.user=> (println (type println)) #object[Function] cljs.user=> (println (type slurp)) nil

p-himik 2021-02-08T22:44:38.077800Z

I cannot reproduce it at all in a clean NodeJS REPL:

% clj -Sdeps '{:deps {cljs-node-io/cljs-node-io {:mvn/version "1.1.2"}, org.clojure/clojurescript {:mvn/version "RELEASE"}}}' -M -m cljs.repl.node
ClojureScript 1.10.773
cljs.user=&gt; (require '[cljs-node-io.core :as io :refer [slurp spit]])
nil
cljs.user=&gt; slurp
#object[cljs_node_io$core$slurp]
cljs.user=&gt; spit
#object[cljs_node_io$core$spit]
cljs.user=&gt; 

Francis Hitchens 2021-02-08T22:47:41.078Z

Ah, maybe I'm not instantiating the repl correctly. I'm doing a clj -Sverbose -M --main cljs.main --compile json-diff.core --repl

p-himik 2021-02-08T22:49:48.078200Z

Do you see a browser window opening when you do that?

Francis Hitchens 2021-02-08T22:51:33.078400Z

Yes/

Francis Hitchens 2021-02-08T22:52:02.078600Z

I tried your command and slurp and spit work just fine.

p-himik 2021-02-08T22:53:12.078800Z

> Yes Right, that's because you started a browser REPL. :) But that library is, it seems, designed to be run on NodeJS, in a self-hosted environment.

Francis Hitchens 2021-02-08T22:57:00.079Z

Yes, I have come to that conclusion too. 😳 I'm 4 hours into clojurescript so forgive me please.

Francis Hitchens 2021-02-08T22:58:06.079200Z

Thanks for your help. I wonder how I access file from a browser REPL, with a lot of difficulty I guess.

p-himik 2021-02-08T22:59:15.079400Z

> how I access file from a browser REPL There's no way to do it automatically - security reasons. Otherwise, any website would be able to read all your files. That's why we have &lt;input type="file&gt;.

Francis Hitchens 2021-02-08T23:20:02.079600Z

So if I run a browser repl and have some HTML where I can enter the file or directory name, do you know of a non NodeJS equivalent library to work with the files and directories?

p-himik 2021-02-08T23:21:53.079800Z

As I said - you cannot. There's no way. You have to use &lt;input type="file"&gt;, click on it (I think this step can be automated), and then select a file manually in the popped-up dialog.

p-himik 2021-02-08T23:22:30.080100Z

What is the problem that you're trying to solve that you need to read files in a browser?

Francis Hitchens 2021-02-08T23:37:12.080300Z

I want to write a utility that takes two directory tress with a mass of JSON files in them and does a graphical representation of the differences between them based on this Javascript code https://github.com/zgrossbart/jdd.

Francis Hitchens 2021-02-08T23:37:40.080600Z

I didn't want to have to learn Javascript too much so I thought to wrap it with Clojure