Fork me on GitHub
#shadow-cljs
<
2018-07-28
>
eoliphant00:07:04

yep that works. Ive only done it with the full lein integration prevously

thheller08:07:34

@schpaencoder yes that is accurate. lacking a lot of details but accurate.

thheller08:07:29

@eoliphant sorry I didn't get to it yesterday. I'll see if I find some time today

thheller08:07:50

the idea with :npm-module would be to compile to <project>/material-dashboard-react/src/cljs and then in the src/index.js to require("./cljs/your.main").start()

thheller08:07:09

ie. calling (ns your.main) (defn start [] ...)

thheller08:07:47

from CLJS you can then require the (:require ["components/...."]) but the downside with this is that you can't require using relative paths

thheller08:07:55

since that would make shadow-cljs try to import them

thheller08:07:06

its probably not much cleaner than the other way

Schpaa08:07:30

> yes that is inaccurate. lacking a lot of details but accurate. Which is it?

thheller08:07:52

yes. that is accurate. šŸ˜›

thheller08:07:55

just woke up

thheller09:07:18

fixed. šŸ˜‰

thheller09:07:01

why are you asking? any issues?

eoliphant12:07:16

hey @thheller no probs, no idea how you manage to keep this going and presumably have a life and what have you lol Iā€™ll play around with it some. Iā€™m admittedly a little weak with this stuff, more of a backend middleware guy, so usually just beat up on my ui guys to get the toolchains working, when I needed to do UI stuff lol. But man, the js spec folks, really need to figure something out. Iā€™m definitely a big fan of ā€˜practicalā€™ and organic standards like say spring in the java world. But when one is looking at some .js code and says something like ā€˜oh, thatā€™s a webpack importā€™, whereā€™s , we may have issues lol. I think the whole transpilation thing was a good idea thatā€™s gone haywire.

eoliphant13:07:24

hey #theller i canā€™t get that transform-input-paths plugin to work. babel keeps saying it canā€™t find it, based on the authors notes, it looks like it mightbe targeted at v7 or something. gonna try the root-imports plugin that it alludes to

eoliphant13:07:24

would dumping all this crap into an NWB project, and creating an exporter index.js potentially be a way around this? https://github.com/insin/nwb/blob/master/docs/guides/ReactComponents.md#libraries

lilactown15:07:35

is there a trick to embedding shadow-cljs in a clojure project?

lilactown15:07:23

Iā€™m trying to start the server and watch from my CIDER REPL. server starts, but when I run a watch it starts complaining about cljs/tools/reader

lilactown15:07:36

compile works fine

eoliphant15:07:46

Well, iā€™m both annoyed and a little pleased lol. I sent a note to those guys, about the need to have this packaged properly and got a response that theyā€™re working on it. So as I was starting to try to setup my own repo, discovered that thereā€™s already an NPM distro, for the free/lite one. So I just installed that and it seems to work. Now just having an issue with the styles/options. the default appearance is what youā€™d expect, nice and material, so the css is sort of working. but it doesnā€™t seem to be honoring the options that are passed in

[reagent.core :as r]
            ["material-dashboard-react/components/CustomButtons/Button" :default Button]
            ["material-dashboard-react/assets/jss/material-dashboard-react/components/buttonStyle" ]))

(def mui-button (r/adapt-react-class Button))

(defn render [ctx]
  [:<>
   [:div [mui-button {:color "info"} "Hi There"]]
   [:div

   [:button {:on-click #(<cmd ctx :update :dec)} "Decrement"]

lilactown15:07:46

Iā€™m guessing itā€™s a transient dependency thing

eoliphant15:07:16

i use it with cursive. I start the watch from the command line, attach to it, then select to flip over to cljs

lilactown15:07:45

yeah, thatā€™s how I do it at work. my website is already a clojure project tho so I was hoping I could have it all in one REPL

lilactown15:07:47

@eoliphant so it shows ā€œHi thereā€ but isnā€™t respecting ā€œcolorā€?

eoliphant15:07:40

ah yeah, i found it to be clunkier to run even though it was ā€˜betterā€™ integrated

eoliphant15:07:48

yep, itā€™s really weird

eoliphant15:07:48

So renders as it should in the material style

eoliphant15:07:51

I know reagent does it for you, but I also tried {"color" "info"} and clj-jsing it as well

lilactown15:07:06

grabbing at straws, but try using :> Button {:color "info"} "Hello"

eoliphant15:07:33

yeah good point was thinking about that

eoliphant15:07:45

as you learn in science, only vary one thing at a time lol

eoliphant15:07:09

so, I was doing this, and switching over to keechma

thheller15:07:35

@eoliphant the default .babelrc shipping with the material-dashboard stuff worked after all. the transform-import-paths wasn't required.

eoliphant15:07:43

and hadnā€™t updated my :after-load directive

šŸŽ‰ 4
thheller15:07:48

so just running babel in the directory worked fine

thheller15:07:02

@lilactown it complains about tools.reader how? that might just be dependency conflict

lilactown15:07:14

lilactown.core> (shadow/watch :client)
[:client] Configuring build.
[:client] Compiling ...
:watching
lilactown.core> [:client] Build completed. (132 files, 2 compiled, 2 warnings, 1.72s)

------ WARNING #1 --------------------------------------------------------------
 File: cljs/tools/reader/edn.cljs:121:36
--------------------------------------------------------------------------------
 118 |                    (recur (inc i) (+ d (* uc base)))))))
 119 |            (js/String.fromCharCode uc))))))
 120 | 
 121 | (def ^:private ^:const upper-limit (int \uD7ff))
------------------------------------------^-------------------------------------
 cljs.core/bit-or, all arguments must be numbers, got [string number] instead
--------------------------------------------------------------------------------
 122 | (def ^:private ^:const lower-limit (int \uE000))
 123 | 
 124 | (defn- read-char*
 125 |   [rdr backslash opts]
--------------------------------------------------------------------------------

------ WARNING #2 --------------------------------------------------------------
 File: cljs/tools/reader/edn.cljs:122:36
--------------------------------------------------------------------------------
 119 |            (js/String.fromCharCode uc))))))
 120 | 
 121 | (def ^:private ^:const upper-limit (int \uD7ff))
 122 | (def ^:private ^:const lower-limit (int \uE000))
------------------------------------------^-------------------------------------
 cljs.core/bit-or, all arguments must be numbers, got [string number] instead
--------------------------------------------------------------------------------
 123 | 
 124 | (defn- read-char*
 125 |   [rdr backslash opts]
 126 |   (let [ch (read-char rdr)]
--------------------------------------------------------------------------------

lilactown15:07:33

if I trigger a re-compile this turns into an error

thheller15:07:18

warning looks legit

lilactown15:07:29

[:client] Compiling ...
[:client] Build failure:
------ ERROR -------------------------------------------------------------------
 File: jar:file:/Users/will/.m2/repository/org/clojure/tools.reader/1.0.0-alpha4/tools.reader-1.0.0-alpha4.jar!/cljs/tools/reader/edn.cljs:121:1
--------------------------------------------------------------------------------
 118 |                    (recur (inc i) (+ d (* uc base)))))))
 119 |            (js/String.fromCharCode uc))))))
 120 | 
 121 | (def ^:private ^:const upper-limit (int \uD7ff))
-------^------------------------------------------------------------------------
Can't redefine a constant at line 121 cljs/tools/reader/edn.cljs
--------------------------------------------------------------------------------
 122 | (def ^:private ^:const lower-limit (int \uE000))
 123 | 
 124 | (defn- read-char*
 125 |   [rdr backslash opts]
--------------------------------------------------------------------------------

thheller15:07:55

1.0.0-alpha4 that is defniitely the wrong version

thheller15:07:01

we are up to 1.3.1 I think

eoliphant15:07:21

ok, but that still needs to get commonjsā€™ed or whatever right? Iā€™m poking trhough the npm version of the free one, and say the button class, has all the stuff fixed up that we discussed.

...
var _withStyles = require("@material-ui/core/styles/withStyles");

var _withStyles2 = _interopRequireDefault(_withStyles);

var _Button = require("@material-ui/core/Button");

var _Button2 = _interopRequireDefault(_Button);

var _buttonStyle = require("../../assets/jss/material-dashboard-react/components/buttonStyle");
...

eoliphant15:07:42

I was thinkign of just dumping the pro source

thheller15:07:45

@eoliphant yeah thats the code I get by running babel

thheller15:07:06

in the checkout directory

eoliphant15:07:06

let me try it agian

thheller15:07:13

npm install and then npx babel src -d out

eoliphant15:07:22

ah but in the free one

eoliphant15:07:33

yeah thatā€™s it

eoliphant15:07:44

iā€™m gonna drop this pro code

thheller15:07:46

check the .babelrc of the pro version

eoliphant15:07:47

on top of ti

thheller15:07:00

it its different for some reason copy the free version over

eoliphant15:07:01

but yourā€™re saying only babel is required

eoliphant15:07:08

if thatā€™sthe case

thheller15:07:18

well webpack is still sort of required for the Dashboard stuff

eoliphant15:07:19

then Iā€™ll just move the babelrc over

thheller15:07:22

since that has an image import

eoliphant15:07:27

right because of that

thheller15:07:35

dunno about the pro stuff

eoliphant15:07:38

iā€™m less concered about thouse

eoliphant15:07:50

iā€™m probably gonna just recreate that in cljs

lilactown15:07:21

so when I run lein deps :tree Iā€™m seeing this:

Possibly confusing dependencies found:
[org.clojure/tools.nrepl "0.2.12" :exclusions [org.clojure/clojure]]
 overrides
[thheller/shadow-cljs "2.4.24"] -> [org.clojure/tools.nrepl "0.2.13"]

Consider using these exclusions:
[thheller/shadow-cljs "2.4.24" :exclusions [org.clojure/tools.nrepl]]

eoliphant15:07:35

though yeah.. Iā€™m just gonna move all the build crap over to the pro dir.. Then I should just be able to point to the build dir as a local repo in my actual projects package.json right?

lilactown15:07:50

I donā€™t have tools.nrepl in my project.clj <_<

lilactown15:07:11

nor profiles.clj afaict

thheller15:07:12

@lilactown thats always added. but look for tools.reader

thheller15:07:29

lein itself depends on nrepl

thheller15:07:51

@eoliphant the pro version doesn't have a .babelrc?

lilactown15:07:06

reader only appears once and itā€™s 1.3.0

eoliphant15:07:22

uses all the create-react-app defaults i guess

lilactown15:07:25

trying this one more time, I just cleared out some unused deps

thheller15:07:49

@lilactown that can't be. the alpha4 must come from somewhere

thheller15:07:08

remember the profiles in project.clj maybe something in there is responsible. or a plugin.

eoliphant15:07:58

given that they have this working for the free one, I guess they were trying to figure out how to handle the paid version, but seems like that would just be a private npm repo, and give you a login when you pay or something

thheller15:07:06

just need the .babelrc and the package.json really.

thheller15:07:15

bower stuff etc is irrelevant

eoliphant15:07:00

yeah will diff the package scripts since the pro has more deps and the lib build stuff isnā€™t in the pro

eoliphant15:07:25

gonna be a little annoyed if this just works lol, this could have been couple lines in the readme lol

lilactown15:07:33

Iā€™m afraid itā€™s cider-nrepl middleware

thheller15:07:08

hmm that should really be using a more recent version

thheller15:07:25

when in doubt just add clojurescript and tools.reader to your deps in case you don't have that

lilactown15:07:51

Iā€™m on a slightly older version of CIDER. the latest uses 1.1.1

thheller15:07:16

thats still really old

lilactown15:07:25

I hadnā€™t added clojurescript or tools.reader to my deps yet

lilactown15:07:35

I figured shadow-cljs would handle those for me

thheller15:07:40

yeah gotta be a bit more careful with deps in project.clj

thheller15:07:08

it should work if you list shadow-cljs first

lilactown15:07:53

šŸ™ƒ I just put tools.reader in my deps and it worked

lilactown15:07:08

FML. that was like an hour of my morning šŸ˜‚

lilactown15:07:35

should have just ran shadow-cljs from my terminal. oh well, now I know

thheller15:07:10

yeah thats why I don't recommend using lein. just too many things you need to watch out for šŸ˜›

lilactown15:07:38

I should switch to deps.edn

lilactown15:07:47

is that any less painful?

thheller15:07:10

well .. not really ... just different pains

chazu19:07:17

i was trying to find the best way to eval some code on server mode startup last night, and I saw that a config option to run a worker was added for server mode, but it seems to have been removed. Whats the best way to do some eval on server startup?

chazu19:07:27

šŸ‘‹ @iam

šŸ‘‹ 4
eoliphant19:07:04

any one using shadow- with keechma?

eoliphant19:07:41

iā€™m having some weird problem with the hot reload

eoliphant19:07:21

shadow-cljs is calling the reload func

chazu19:07:49

@lee.justin.m thanks! šŸ˜„ Iā€™ll get to it!

eoliphant19:07:55

but the ui isnā€™t updating

justinlee19:07:25

the only thing is that those hooks will run even when you are just compiling (as opposed to running a server), so you might have to do some detection of the environment

chazu19:07:41

yeah thats alright with me, a little bit of overhead is fine

thheller19:07:46

see the section below with {:shadow/requires-server true}

thheller19:07:39

@eoliphant thats probably not related to shadow-cljs but what you do in your reload func

thheller19:07:59

maybe the re-render you are calling just decides to no re-render or stops early

eoliphant19:07:52

well I just noticed something that Iā€™m working to reproduce, it appears figwheel is pushing one more file than shadow does prior to the reload getting called

eoliphant19:07:18

iā€™m setting up shadow on the keechma default template app

thheller19:07:51

never looked at keechma but if you have some code I can look at it would help

eoliphant20:07:16

ok yeah just reproduced it. You want the whole project zipped up? but in short, in their template ui/main namespace, thereā€™s a render function. say changing a bit of text in it, causes the following in figwheel

Figwheel: loaded these files
15:27:21.506 utils.cljs?rel=1532803397043:71 ("../keech_proj/ui/main.js" "../keech_proj/ui.js" "../keech_proj/core.js")
and the following in shadow.
shadow-cljs: load JS keech_proj/ui/main.cljs
15:59:49.184 browser.cljs:25 shadow-cljs: load JS keech_proj/ui.cljs
15:59:49.185 browser.cljs:25 shadow-cljs: call keech-proj.core/reload
ui refs ui\main and as you can see the reload func itself is in core

thheller20:07:30

I'm gonna need the full code

thheller20:07:15

<mailto:[email protected]|[email protected]> or some git repo is fine

eoliphant20:07:21

sent to your email. Just jacked shadow into it. Has a shadow-cljs.edn, package.json, etcand changed the name of the .js in the index.html everything else should be more or less as it was generated

thheller20:07:12

whats the lein command to run the figwheel version?

thheller20:07:26

(defn reload []
  (let [current @running-app]
    (println "RESTART" (true? current))
    (if current
      (app-state/stop! current start-app!)
      (start-app!))))

eoliphant20:07:46

should just be lein figwheel

thheller20:07:53

this might not be correct?

thheller20:07:01

if current version is running, stop it

eoliphant20:07:04

and you have to change thename of the .js

thheller20:07:16

so the first call of reload just stops everything but never restarts it?

eoliphant20:07:19

in index.html

eoliphant20:07:50

yeah read weird to me too, but it works in figwheel

thheller20:07:57

I don't know anything about keechma but that looks suspicious to me

thheller20:07:33

ah nvm, the extra start-app! is probably called once stop finishes

eoliphant20:07:54

yeah that makes sense

thheller20:07:58

where is this shadow-cljs.edn config from?

eoliphant20:07:01

i just copied it over from antoehr one of my projects and stripped the extraneous stuff out

eoliphant20:07:39

added the deps to match the project.clj etc

thheller20:07:09

ok then go to your other project and take out the hud preload

thheller20:07:47

that is really old and not required since forever ago šŸ˜‰

thheller20:07:53

also when copying deps leave out clojure,clojurescript and shadow-cljs itself

thheller20:07:02

they will be ignored anyways

eoliphant20:07:57

ok, yeah Iā€™d migrated from lein, to shadow, to deps, just carried those foward iguess

thheller20:07:49

so far I can't see anything from the shadow-cljs side. everything seems to be doing what it should do

eoliphant20:07:47

yeah the only thing i saw, vs figwheel was that fighwheel was repushing the core

eoliphant20:07:19

in addition to the other 2

thheller20:07:25

ah I think I know

thheller20:07:48

yep thats it

thheller20:07:31

note the def app-definition in .core. that holds a reference to ui which is a map of the components

thheller20:07:53

since core is never updated the re-render doesn't change

thheller20:07:05

core is nore reloaded because its not directly dependent

eoliphant20:07:20

Yeah I was wondering if it had something to do with the way it does dependencies

thheller20:07:55

if you instead turn the def into defn everything works again

eoliphant20:07:58

I see your ^:dev/once option, is there like a ^:dev/always?

thheller20:07:07

(defn app-definition []
  (-> {:components    ui
       :controllers   controllers
       :subscriptions subscriptions
       :html-element  (.getElementById js/document "app")}
      (dataloader/install datasources edb-schema)
      (forms/install keech-proj-forms/forms keech-proj-forms/forms-automount-fns)))

(defonce running-app (clojure.core/atom nil))

(defn start-app! []
  (prn "START-APP!")
  (reset! running-app (app-state/start! (app-definition))))

eoliphant20:07:09

ok even better

thheller20:07:23

shadow-cljs doesn't reload ALL dependents like figwheel seems to do

thheller20:07:42

because that can get reaally slow and shouldn't be required

thheller20:07:02

unless you do something like that where one namespace holds global state from another

thheller20:07:30

could add a reload-all or something setting but no way I'm making that the default šŸ˜›

eoliphant20:07:45

yeah that makes more sense

thheller20:07:10

seems to work just fine if you just change it to a defn

eoliphant20:07:18

I was thinking more for cases like this, that perhaps couldnā€™t be solved as youā€™ve done it here

eoliphant20:07:33

exceptions not rules lol

thheller20:07:44

you are the first to report such a case

thheller20:07:57

and yes there is a ^:dev/always you can put on the ns

eoliphant20:07:04

lol well then I do feel special lol. Gonna drop a note in their channel as well

eoliphant20:07:06

and thanks for the help on that material ui stuff. good lord. lol, literally a like 2 sentence readme would have made most of that avoidable

thheller20:07:10

ah I made a test repo for that btw

eoliphant20:07:06

gotta shoot them a noteā€¦ so they can add it for the pro or whaever

eoliphant20:07:32

yeah Iā€™ve gotten a page or so done looks prettty fine