Fork me on GitHub
#clojurescript
<
2019-04-04
>
rastandy13:04:17

Hello everyone! Is there a preferred way of starting a ClojureScript Node.js project with figwheel and CIDER support? Something easy to bootstrap like a lein template…

publicmayhem13:04:52

@rastandy Take a look at shadow-cljs which has excellent first class support for node, No figwheel needed as it hot reloads for you. I seem to remember notes on CIDER were also somewhere in the excellent docs

rastandy13:04:50

@robert.law thanks, will take a look at that, but would love to use figwheel because I simply love it

rastandy13:04:07

anyway, thanks for the suggestion, I’ll take a look at that

pez14:04:04

@rastandy, I think Fighweel has closed the gap to shadow-cljs somewhat when it comes to node support, but shadow-cljs is lovely. To start it with CIDER support:

shadow-cljs -d cider-nrepl:0.21.2-SNAPSHOT watch app
(replace app with whatever you name your build).

il-tmfv17:04:59

Hi! I have a really strange js output with cljs 1.10.520 (same for 1.10.516). Part of the form is simply removed after usage of var (in compiled js):

(def init-data
  (if-let [element (.getElementById js/document "cljs-init")]
    (->> (.-textContent element)
         (transit/read transit-reader)
         (merge {:a nil
                 :b nil}))))
and I use it in:
(defn render-app []
  (when init-data
    (swap! initial-state* merge init-data) ; <<<<<< here
    (swap! state merge init-data)             ; <<<<<< here
    (i18n/init state)
    (render-components ".cljs-app-component" components)
    (nav/init!)))

(render-app)
For some reason code after first use (I’ve tried to change order) gets removed in js, but only til the end of render-app fn:
if(cljs.core.truth_(hb.front.entry_points.app.init_data)){ //when part
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3(hb.front.state.initial_state_STAR_,cljs.core.merge,hb.front.entry_points.app.render_app();
// EOF
As you can see swap! is called, but first occurrence of init-data is replaced with render-app call from the end of this file. If I replace init-data with simple (def init-data {}) everything will be fine. Or if I comment all usages. On cljs 1.10.439 build is successful. Any ideas?

mfikes17:04:41

@il.tmfv Do you have :parallel-build enabled? (Perhaps something related to multi-threading is causing the compiler to derail on that code.)

il-tmfv17:04:48

@mfikes I’ve tried to turn it off. There is even less data in js file now 😅:

if(cljs.core.truth_(hb.front.entry_points.app.init_data)){
cljs.core.swap_BANG_.cljs$core$IFn$_invoke$arity$3(hb.front.state.initial_state_STAR_,cljs.core.merge,
it just ends here.

mfikes17:04:24

That's truly bizarre 🙂

dnolen17:04:57

@il.tmfv make sure you're not accidentally running multiple builds

dnolen17:04:06

this is a common mistake I've made multiple times myself

dnolen17:04:38

that's the only cause I've seen for corrupted output files like that

mfikes17:04:40

Yeah, it smells like corruption from multiple writers

dnolen17:04:15

I don't think :parallel-build has anything to do w/ this

il-tmfv17:04:18

I do run it for 2 builds 🙂 But now I’ve tried for only 1 and I have the same result cljs 1.10.439 works great with 1 or 2 builds. I clean folders before each build, just in case

il-tmfv17:04:20

Also i’ve tried to inline (def init-data ...) form to get rid of ->> and if-let Result is the same. Maybe interop stuff is broken?

mfikes17:04:41

Well, if you can, a minimal repro in a JIRA would make it easier to sort out.

il-tmfv18:04:31

Yep, I was thinking about it. Will take a look tomorrow 👍 Just tried to change init-data to

(def init-data
  (merge {:a nil
          :b nil} {})
Output is still broken. But it works for simple (def init-data {:a nil :b nil})

🐿️ 4
upside_down_parrot 4
cch122:04:53

Can anybody point me to the documentation for the js* interop macro/function/special form?

cch123:04:21

I’m trying to invoke the javascript operator <<< and this is my last resort.

cch100:04:59

That’s where I found it, and I thought was able to discern how the substitution works. But, this surprises me: (js* "({} >>> 0)" -319376401)

cch100:04:15

#object[TypeError TypeError: ({} >>> 0) is not a function]

darwin00:04:18

try this in repl: (.toString (fn [y] (js* "~{} >>> 1" y)))

darwin00:04:41

the placeholder is ~{}

mfikes00:04:46

@U0698L2BU Recommend

(bit-shift-right-zero-fill -319376401 0)

cch100:04:33

I ended up using the unsigned version of that: unsigned-bit-shift-right

mfikes00:04:45

Ahh, yes. That one is not deprecated.

cch100:04:19

@U08E3BBST that worked. My ClojureScript fu is not strong enough to understand why the unadorned version did not work.

cch100:04:30

<@U08E3BBST> I see one source of confusion I had: the placeholder is exactly what you said (`~{}`) … I assumed it was `{}` and the `~` was the javascript bit flip.

cch100:04:57

… which I also why I didn’t trust the built-in fn/macros that @mfikes suggested.

cch100:04:12

Turns out the built ins work perfectly and there is no extraneous bit flipping.

👍 8