Fork me on GitHub
#clojurescript
<
2016-07-28
>
renan00:07:38

hi, i'm using Figwheel, my question is how using external library/JavaScript file in Figwheel? but i tried the key ':externs' but the repl/clojurescript not load the library, this is js file http://waveformjs.org/waveform.js and for create extern file, i used Extern Generators (http://jmmk.github.io/javascript-externs-generator/)

borkdude12:07:28

what is the fastest/easiest way to get a library like cljs-time running in a repl using node?

borkdude12:07:39

I don't need to watch/compile files

borkdude12:07:42

just a repl session, preferably using a script of just a few lines

borkdude12:07:29

I now have this in a script, which is already quite amazing: boot -d clj-time repl -e "(require '[clj-time.core :as t])", but I wonder if I can cut the startup time using node and clojurescript

borkdude12:07:13

Probably Planck is what I need here

martinklepsch12:07:12

@borkdude: yeah, planck -c path-to-cljs-time.jar

borkdude12:07:46

@martinklepsch: trying to export the classpath with boot, see #C053K90BR 🙂

martinklepsch12:07:00

this works planck -c ~/.m2/repository/com/andrewmcveigh/cljs-time/0.4.0/cljs-time-0.4.0.jar

mfikes12:07:18

@borkdude: If you want to reduce startup time with Planck, add a -K, as in:

planck -Kc ~/.m2/repository/com/andrewmcveigh/cljs-time/0.4.0/cljs-time-0.4.0.jar -e "(require '[cljs-time.core :as t])" -e"(t/plus (t/today) (t/days 100))”
This reduces it from 2.2 s to 0.4 s. There is evidently an odd issue with the printing of the timestamp.

borkdude12:07:38

@martinklepsch: ah, that works indeed. I wonder why "planck -c boot -d com.andrewmcveigh/cljs-time:"0.4.0" show -c" doesn't work...

mfikes13:07:20

@borkdude See http://planck-repl.org/dependencies.html where an example using backticks is shown:

$ planck -c`boot show -c`

borkdude13:07:08

I used the backticks like this:

planck -c `boot -d com.andrewmcveigh/cljs-time:"0.4.0" show -c`
Sorry, some Slack formatting issue 🙂

martinklepsch13:07:19

boot show -c has a bunch of boot stuff, not sure if that might mess with Planck

mfikes13:07:00

(You essentially want to run Boot, but if your goal is outright speed, see the caching portion on that page.) And @martinklepsch is right, minimizing the number of JARs on the classpath will result in Planck finding the deps faster.

borkdude13:07:15

Well, planck -c ~/.m2/repository/com/andrewmcveigh/cljs-time/0.4.0/cljs-time-0.4.0.jar -e "(require '[cljs-time.core :as t])" -r does exactly what I want, so thanks

martinklepsch13:07:20

@mfikes: an option akin to boot's --dependencies that expects jars in .m2 might be a nice affordability 🙂

martinklepsch13:07:34

(i.e. you pass coordinates instead of paths)

mfikes13:07:27

@martinklepsch: Yes, it is tempting to add that. (The key is to only expect the JARs to be there, without actually trying to download them, which is another whole project in and of itself.)

martinklepsch13:07:54

right, check if they exist otherwise throw an exception or something

borkdude13:07:02

so like planck -c com.andrewmcveigh.cljs-time and then just pick the newest?

martinklepsch13:07:05

well, more like planck -d com.andrewmcveighcljs-time:0.4.0 — picking newest might be unexpected because it can't download jars

borkdude13:07:29

yeah agreed

borkdude13:07:02

if cljs-time would have another dependency this wouldn't work right?

borkdude13:07:31

then going the boot show -c route and stripping out stuff would be the easiest?

martinklepsch13:07:16

@borkdude: there are alternative things for boot show -c around that just dump the jars of actual dependencies minus boot stuff

borkdude13:07:26

This worked: boot -d org.clojars.micha/boot-cp -d com.andrewmcveigh/cljs-time:"0.4.0" with-cp -w --file .classpath

borkdude13:07:43

@mfikes: you might want to update the docs with this instead of the default boot show?

mfikes13:07:03

OK… will do

borkdude13:07:38

@mfikes: don't know if the outputted clojure version is affecting planck

borkdude13:07:33

but for me it works as expected

martinklepsch13:07:00

@mfikes: if you update the docs, make sure you mention that the user then needs to pass the contents of the classpath file to the -c option @borkdude

borkdude13:07:19

I think I'll write short blog post about this. It's exciting 🙂

mfikes13:07:22

@borkdude: No. Planck will satisfy dependencies by first finding them in the Planck binary. So, you can’t inadvertently specify an alternative version of ClojureScript, for example. The only real danger would be in somehow obtaining a .clj macro dep from the Clojure JAR, but Planck should be taking care of that in the same way.

mfikes13:07:00

@martinklepsch: Yeah… it appears to be a good way of caching the classpath in one step. As opposed to using tee as is documented in this example:

if [ ! -f .classpath ]; then
  classpath=`lein classpath | tee .classpath`
else
  classpath=`cat .classpath`
fi

planck -c $classpath

borkdude13:07:10

@martinklepsch: can you explain how it's using caching when you're not writing it to a file?

martinklepsch13:07:02

@borkdude: uhm, I'm lost, can you elaborate?

borkdude13:07:52

@martinklepsch: well, calculating dependencies takes time, that is why it's being cached in the .classpath file

mfikes13:07:53

I’m guessing @borkdude that what might help is to point out there are two things that could be cached. (1) The result of building the classpath. (2) The results of compiling the dep.

borkdude13:07:46

@mfikes: how is (2) cached atm?

micha13:07:58

I'll try to push a boot update for the class path show -c bug today too

martinklepsch13:07:24

@micha as in make show -c only return the project classpath? (excl. any boot stuff)

mfikes13:07:46

By passing -K to planck, or, alternatively -k some/directory/to/write/cache. (`-K` creates and writes in .planck_cache)

borkdude13:07:59

@mfikes: thanks, was still using an older version of planck where -K didn't work. Now I tried it

mfikes13:07:29

Cool. Yeah, you should definitely see it speed up. And you should see a .planck_cache dir.

borkdude13:07:38

please check for errors 🙂

martinklepsch13:07:11

I'd suggest using expanded options for something educational

martinklepsch13:07:47

Also just explaining what that boot invocation does might be good, looks kinda overwhelming if you don't know what's going on 🙂

dominicm13:07:34

> invocation I think the word "incantation" is more appropriate at this level 😉

borkdude13:07:36

well, if @micha is going to change show to what this does, it can be simplified

borkdude13:07:12

much better

martinklepsch13:07:30

about that with-cp -w: ¯\(ツ)

mfikes13:07:31

I’ve created a ticket capturing stuff so I can go back in later and update the docs: https://github.com/mfikes/planck/issues/343

martinklepsch13:07:39

@dominicm: had too look that up but yeah, 😂

borkdude14:07:10

@mfikes: I found out that -K and --cache don't work nicely together, probably a warning would be good

hlolli14:07:19

As I think this is cljs related more than om I ask here: after advanced compilation I'm not able to access value of text field by-id. I get Uncaught TypeError: Cannot read property 'Ub' of undefined, may add that these text-fields are generated in sequence, which I believe contributes to this issue. Any ideas for workaround?

martinklepsch14:07:56

@hlolli: the code might help, generally this seems like an externs issue

hlolli14:07:16

ok, but I must point out in the following code, it works in figwheel. And accessing text data in fn (since this is material-design text field), also works in figwheel dev-env.

hlolli14:07:41

ahh doesnt show the sequence, let me try again in a short cut version.

hlolli14:07:06

mapv #(material-ui/text-field :on-change 
(fn []
    (let [id (str "text-field-id-" %)
              input-text (str (.-value (gdom/getElement id)))
             valid? (tax-id-validator input-text)]
  ...etc....))
   (range (:text-field-count (om/get-state this)))

peeja15:07:51

I'm getting an "undeclared Var" warning that seems to be coming from a macro. Is there a way to see the compiler's result after macroexpanding my code?

mfikes15:07:31

@peeja: There’s no direct way, but I’d try (macroexpand ‘(some-form))

peeja15:07:19

I'm not clear where I can actually call that from…

mfikes15:07:13

Oh… try that in the REPL

mfikes15:07:47

Of course, you have to know which form is causing the problem

peeja15:07:27

Shoot. I'm not actually sure how to get this code into a repl.

peeja15:07:10

It's an open Om bug.

danielpquinn17:07:17

So I’m new to clojure and functional programming in general. I feel like I’m creating a mess while attempting to manage state and I’m wondering if you folks have any suggestions for me. I’ll explain my situation in more detail...

danielpquinn17:07:02

I have a form, which has a message that displays information to the user depending on whether the form is valid, an error occurred during submission, submission succeeded etc

danielpquinn17:07:43

I’m using reagent, and I create a message atom when my component is initialized. In order to update the message I have to pass it through several layers of event handler functions

danielpquinn17:07:36

Is this “normal”? I feel like the number of arguments that my functions take is growing as the complexity of my app increases

danielpquinn17:07:52

so the atom gets passed to a submit function, and then the submit function passes that same atom to a handle-success function and so on

mattsfrey17:07:12

@danielpquinn: I'd recommend taking a look at re-frame

mattsfrey17:07:40

reagent alone doesn't really have a state management system

danielpquinn17:07:41

thanks, I’ve taken a brief look and do plan to use it in the future

danielpquinn17:07:54

I’m trying to get to grips with reagent first though

danielpquinn17:07:23

Does reframe have some convention for managing state at a component level? I feel like this becomes necessary when dealing with forms

danielpquinn17:07:39

vs the global state/redux way of doing things

mattsfrey17:07:54

yes, you have a centralized app-db that stores all of your state and you access it via subscriptions in your components where that state is needed

mattsfrey17:07:09

and modify it by dispatching actions that modify that state

danielpquinn17:07:33

So let’s say I have an input component which has a valid state. Does that state move into app-db?

mattsfrey17:07:38

without something like this, then yes you have to pass references to your state atoms to wherever they are needed

danielpquinn17:07:47

gotcha, thanks 🙂

mattsfrey17:07:25

yeah you'd define a section in the appdb to store it such as [:my-input :valid?]

mattsfrey17:07:45

and have a subscription that accesses it in the component that needs it

danielpquinn17:07:23

So I guess multiple instances of components gets tricky then

danielpquinn17:07:28

not sure if I’ll need to do that, just a thought

mattsfrey17:07:10

you can define something such as :form-path as a param if you want

mattsfrey17:07:24

and pass that in where you use an instance of a component with a unique path

danielpquinn17:07:31

Oh interesting, yeah that makes sense

danielpquinn17:07:21

thanks for your help

mattsfrey17:07:48

overall point tho is that reagent is pretty useless on its own, same with react

mattsfrey17:07:56

you need a flux/redux to accompany it basically

mattsfrey17:07:15

re-frame is a cljs analog to redux basically

danielpquinn17:07:14

okay nice, well sounds like I’ll be looking into re-frame sooner than I expected

shaun-mahood17:07:36

@danielpquinn: I learned reagent through using re-frame and it really is a good way to start with it - I knew nothing about react or reagent and it was my first real project using clojure and clojurescript. If you go through the readme and the wiki (including the section on reagent) it should give you a really good start as well as a lot of good info on reagent. There is a #C073DKH9P channel on here as well that is very helpful for when you run into questions.

danielpquinn17:07:58

okay awesome, thanks for the tips

si1418:07:58

are there any downsides of re-frame subscriptions like

(register-sub
 :get
 (fn [db [_ key]]
   (reaction (getx @db key))))

micha21:07:49

@borkdude: i don't think there is an issue

micha21:07:05

if you would like to create one that would be awesome

micha21:07:47

otherwise i hope to have a patch release of boot which will notify in #C053K90BR here on slack and #boot_clj on IRC

anmonteiro21:07:09

I’m searching for a markdown parser, what do people use mostly?

anmonteiro21:07:30

I was looking at marked but it seems it hasn’t been maintained for 1 year

richiardiandrea21:07:47

@anmonteiro: for cljs there is showdownjs

anmonteiro21:07:05

I was trying out showdown but I think it’s missing a feature I need

anmonteiro21:07:25

fenced code blocks with language don’t seem to be supported

richiardiandrea21:07:41

it is kind of robust I found

anmonteiro21:07:45

e.g.

‘’’clojure
(+ 1 2)
‘''

richiardiandrea21:07:54

there is also markdown-clj IIRC

anmonteiro21:07:56

this gets rendered as

clojure (+ 1 2)

anmonteiro21:07:00

@richiardiandrea: that one seems promising, I wonder if it’ll be too much of a perf hit

richiardiandrea21:07:21

we used showdownjs effectively, I don't remember that particular use case now, but you can have a look here: https://github.com/Lambda-X/cljs-repl-web/blob/devel/src/cljs/cljs_repl_web/markdown.cljs

richiardiandrea21:07:46

it's clojurescript.io...I haven't used markdown-clj though

mattly23:07:07

@anmonteiro: anymore I'd recommend MarkdownIt

mattly23:07:53

it's actively maintained, easy to plugin, and provides access to the parser

mattly23:07:58

...if you need that