Fork me on GitHub
#shadow-cljs
<
2019-09-17
>
Aleh Atsman07:09:53

Can somebody provide me with example how can I create simple node-script project and start repl sesstion so that I can connect from nvim to it?

thheller07:09:19

npx create-cljs-project foo then cd foo npx shadow-cljs node-repl

thheller07:09:44

dunno about nvim though

Aleh Atsman07:09:25

Yes that’s exactly what I did

Aleh Atsman07:09:23

when I try to execute some form in nvim i get Fireplace: no default ClojureScript REPL

Aleh Atsman07:09:48

I tried to call :Piggieback :app but no results

thheller07:09:11

did you connect to the shadow-cljs server?

thheller07:09:30

no clue. I have never used vim-fireplace

thheller07:09:39

If you are starting nREPL some other way, run :FireplaceConnect host:port.

Aleh Atsman08:09:08

it is connected to nrepl

thheller08:09:30

dunno. if you used shadow-cljs node-repl you'd do :Piggieback :node-repl

Aleh Atsman08:09:57

Tried that too, doesn’t work, can’t execute anything from within the nvim

Aleh Atsman08:09:41

Do I need to add what ever special to config, like dependency, ports, whatever. Or should it work just out of the box ?

thheller08:09:58

depends. how did you connect? do you use lein/deps.edn?

Aleh Atsman08:09:33

I created project using npx create-cljs-project hello-node

Aleh Atsman08:09:37

created one cljs file

thheller08:09:18

and how did you connect? the default random port printed on startup?

Aleh Atsman08:09:28

yes it is connected for sure

Aleh Atsman08:09:42

I did manually typed host:port

thheller08:09:59

I don't know. if I look at this error you might not have provided enough args? https://github.com/tpope/vim-fireplace/blob/master/autoload/fireplace.vim#L512

thheller08:09:03

maybe try :Piggieback (cider.piggieback/cljs-repl :node-repl)?

thheller08:09:20

can't quite decipher what the vim script is doing

Aleh Atsman08:09:42

Ok I started shadow-cljs node-repl, Connected, Runned Piggieback :node-repl and tried to run Eval (+ 1 1) and got Fireplace: session closed

Aleh Atsman08:09:54

The same with :Piggieback (cider.piggieback/cljs-repl :node-repl)

thheller08:09:32

no clue what that means

Aleh Atsman08:09:03

I don’t see nvim section in Editor Section in docs, maybe it is not supposed to work at all

thheller08:09:11

several people use it and it is definitely supported

thheller08:09:35

I just don't know anything about it so I can't add it to the docs

Aleh Atsman08:09:54

I definitely connected to nrepl, I can execute clj, but not cljs

thheller08:09:39

no clue how to debug the fireplace side sorry. does it have a log of some kind?

Aleh Atsman08:09:21

CljEval (shadow/repl :node-repl)

Aleh Atsman08:09:28

And it works now

thheller08:09:11

weird because thats what :Piggieback :node-repl should end up calling

Aleh Atsman08:09:36

i love and hate clj so much 🤯

sb09:09:52

I loaded successfully BlueprintJS with shadowjs. Works at many cases, maybe my poor react knowledge.. could you help me what I forget or how to rewrite to cljs? https://blueprintjs.com/docs/#core/components/popover.dark-theme

(defn PopOver []
 [:> bp/Popover {:content  [:div 
                            [:> bp/Menu {:large false}
                             [:> bp/MenuItem {:text "test1"}]
                             [:> bp/MenuItem {:text "test2"}]
                             [:> bp/MenuItem {:text "Test3"}]]]
                 :enforceFocus false
                 ;:position "Position.BOTTOM_LEFT" ;;error
                 :interactionKind "HOVER"}
  [:> Button {:variant "info"}  "hello"]]
)
and require with ["@blueprintjs/core" :as bp] .. my problem is how to add content section and position part of the code

thheller09:09:47

:content expects a react element but you are passing a cljs vector

thheller09:09:01

do a (reagent/as-element [:div ...])

thheller09:09:57

:position bp/Position.BOTTOM_LEFT

sb09:09:27

thanks!!

sb09:09:01

Works fine, thank you very much 🍻

Dan16:09:21

I'm new to ClojureScript and trying to get my head around how the front-end is set up. We're using ClojureScript, shadow-cljs, Leiningen and Reagent. I am just a bit confused about the dependencies around React. We're using Leiningen for our dependencies and have Reagent and shadow-cljs as dependencies. Do I still need to require React in the package.json file?

thheller16:09:17

JS dependencies are manage by package.json and npm yes

Dan16:09:34

Ok, so in layman terms, there is one version of React used in the app and it's required in one place, package.json

thheller16:09:26

"required" isn't the word I would use, it is only installed based on package.json

thheller16:09:33

what is used in the build is defined by your code

thheller16:09:50

you can have thousands of things in package.json but that wouldn't mean they are actually included in a build

Dan16:09:26

We have some :exclusions in the project.clj file - cljsjs/react etc - I think it's the cljsjs part I don't understand - basically how it's all connected. I come from React/Vue background and am used to just having one package listed

gerred16:09:33

(closure compiler is 👍 about dead code elimination)

thheller16:09:01

those exclusions don't really do much so you can remove them or keep them

thheller16:09:16

shadow-cljs doesn't use them regardless

thheller16:09:36

package.json managed JS dependencies, project.clj managed CLJ/CLJS dependencies

Dan16:09:12

Ok. So if we didn't use shadow-cljs (for example) and just reagent - where would that be pulling React from?

Dan16:09:22

Ok, I thought shadow-cljs replaced cljsjs

thheller16:09:55

it does. but you asked about what happens if you didn't use it

Dan16:09:18

So we can run just Reagent and shadow-cljsjs - I think I was getting confused as we run

[thheller/shadow-cljs "2.8.52"]
                 [thheller/shadow-cljsjs "0.0.20"]

thheller16:09:45

[thheller/shadow-cljsjs "0.0.20"] this you don't include at all

thheller16:09:02

cljsjs is npm packages pre-packed as MAVEN dependencies

thheller16:09:12

CLJS uses maven by default

thheller16:09:22

shadow-cljs skips cljsjs and accesses npm directly

Dan16:09:43

Ok great. So ideal basic setup would be

[reagent "0.9.0-rc1"]
     [thheller/shadow-cljs "2.8.52"]
and then
"dependencies": {
        "react": "^16.9.0",
        "react-dom": "^16.9.0",
    }

Dan16:09:37

Then I can remove all the :exclusions for cljsjs

thheller16:09:39

shadow-cljsjs is about providing compatibility with packages that assume you don't have direct access to npm. described here https://shadow-cljs.github.io/docs/UsersGuide.html#cljsjs

thheller16:09:51

shadow-cljs brings that in by default, you never need it manually

thheller16:09:19

basically don't worry about those at all unless you run into specific problems

thheller16:09:15

you can keep the exclusions or remove them. shadow-cljs doesn't care

thheller16:09:36

if you keep them the dependencies won't be downloaded

Dan16:09:45

Cool. So how does having reagent in lein then access the packages in json - is that what shadow-cljs is taking care of?

thheller16:09:49

if you don't they are only downloaded once and then cached so no big overhead at all

Dan16:09:14

Sorry, my last question, in the documents say it's recommended to run shadow-cljs as a standalone NPM version - but it doesn't say why that is recommended?

thheller16:09:44

more streamlined setup for CLJS

thheller16:09:56

lein is built for clojure and does a lot of stuff CLJS doesn't need

thheller16:09:18

but if you need lein for other reasons that is totally fine

Dan16:09:24

So would be advisable to remove from lein and add to package.json?

Dan16:09:46

We have a lot of stuff in lein - I'm just trying to strip down the front end as it's a bit of a mess

thheller16:09:02

uhm no thats not how that works

thheller16:09:11

you declare CLJS dependencies in project.clj

thheller16:09:20

but you can also declare them in shadow-cljs.edn directly (and skip using project.clj completely)

thheller16:09:41

it is only about :dependencies and :source-paths

thheller16:09:38

we are still managing 2 separate package managers. there is npm for JS and maven for CLJ/CLJS

Dan16:09:55

Ok, makes sense. So for a new project, probably declare it in shadow, but we have quite a few depends in lein so probably best to keep it there for the moment

thheller16:09:03

one is controlled by package.json the othe other by shadow-cljs.edn or project.clj or deps.edn

thheller16:09:31

shadow-cljs uses the exact same dependency resolution library as lein so moving them over would be easy

thheller16:09:40

but you can keep project.clj if its working for you

Dan16:09:56

Ah, OK - well better to have 2 scripts than 3!

Dan16:09:09

Thank you very much for the help - a lot clearer now!

currentoor23:09:01

Is it possible to make shadow-cljs build a release mode in dev with hot code reload? I’m trying to investigate an issue I only see in the release mode.

thheller23:09:28

no thats technically impossible

tony.kay23:09:19

@thheller Just FYI, what we wanted was to resolve to React’s production js file while in dev mode. I used :js-options to map react and react-dom straight to the prod min files. That seemed to work.

thheller08:09:52

oh yeah thats fine. I was referring to the hot code reload part of the question. 🙂

currentoor23:09:05

yeah i figured

thheller23:09:11

whats the issue?

currentoor23:09:09

a component breaks my app in one particular context but not another, I’m on a beta release of fulcro, so it could very well be a bug in fulcro 3, trying to figure out what’s going wrong

currentoor23:09:41

this component is loosing it’s dynamically bound variables

thheller23:09:49

shadow-cljs release app --debug or shadow-cljs release --pseudo-names might provide clues if you are not using that yet

currentoor23:09:06

yup using those, very handy

thheller23:09:27

shadow-cljs check app might be useful but has a lot of false positives

thheller23:09:37

so often more noise than actual help. but maybe 😉

currentoor23:09:45

now that i think about it, i wonder if react’s async render stuff is not compatible with the way fulcro binds dynamic vars

currentoor23:09:51

i’ll check thanks

thheller23:09:12

if you use lazy seqs in render that can be a problem yes

thheller23:09:32

in dev they are "forced" by react's validation stuff but that isn't active in release builds

thheller23:09:41

so lazy seqs aren't eval'd at the correct time