Fork me on GitHub
#beginners
<
2017-11-25
>
nimblerabit00:11:10

I need to do a visualization of a chess board, placing points within various squares and lines connecting those points. I thought I might use a plotting library for this as it's sorta similar to a line plot, does anyone have any recommendations for a simple library I might use?

lovuikeng02:11:00

don't know if it helps, but this is probably the simplest as you can get for easy charting https://github.com/yfractal/chartkick

swizzard00:11:00

if i wanna spin up a tiny dumb node/cljs command-line app, what's the least painful way to get started?

noisesmith00:11:51

you can install lumo (a self hosted cljs on node) with npm

swizzard00:11:11

i was looking for like a lein template, but lumo seems pretty neat, thanks!

noisesmith00:11:47

lein is a java app

swizzard00:11:02

i've got it installed

noisesmith00:11:21

I'm just saying, i wouldn't expect it to be especially useful for something that's 100% node

swizzard00:11:47

i've used it for clojure stuff before, but haven't done much clojurescript and certainly haven't done any cljs in quite some time

swizzard00:11:00

i'm just trying to dump out another tracery-powered nanogenmo project

swizzard00:11:25

i wanted to add an rnn to generate names

swizzard00:11:51

and got irritated trying to use es6 maps to format training data

swizzard00:11:28

so i figured "why not cljs"

nakiya03:11:52

Hi all, I'm trying to write a simple re-frame app. So, I have code like this:

(defn note-summaries
  []
  (let [items
        (into [] (map #(identity [:li [:p %]])
                      @(re-frame/subscribe [:notes])))]
    [:div
     (if (pos? (count items)
               items
               [:p "No notes!"]))]))
Now, I get error in browser console like this:
Uncaught Error: Assert failed: Invalid Hiccup form: [nil]

(valid-tag? tag)
    at reagent$impl$template$vec_to_elem (template.cljs?rel=1511540933817:302)
    at reagent$impl$template$as_element (template.cljs?rel=1511540933817:329)
    at f (dom.cljs?rel=1511540933878:53)
    at reagent$dom$render_comp (dom.cljs?rel=1511540933878:30)
    at Function.reagent.dom.render.cljs$core$IFn$_invoke$arity$3 (dom.cljs?rel=1511540933878:54)
    at reagent$dom$render (dom.cljs?rel=1511540933878:41)
    at Function.reagent.dom.render.cljs$core$IFn$_invoke$arity$2 (dom.cljs?rel=1511540933878:49)
    at reagent$dom$render (dom.cljs?rel=1511540933878:41)
    at Function.reagent.core.render.cljs$core$IFn$_invoke$arity$2 (core.cljs?rel=1511540934258:75)
    at reagent$core$render (core.cljs?rel=1511540934258:66)
    at ekathuwa$core$mount_root (core.cljs?rel=1511578336868:20)
    at Object.ekathuwa$core$init [as init] (core.cljs?rel=1511578336868:26)
I want to know how to go debugging something like this. I'm quite new to this of course, so I don't really need an answer for this specific bug, but advice on what tools/techniques to use to go about figuring out such a bug. Thanks!

noisesmith03:11:48

@duminda somehow [nil] got passed as a reagent component - that's not valid and can't be rendered

noisesmith03:11:05

but I don't see how the code you showed would create that

nakiya03:11:31

@noisesmith: Figured it out. (if (pos? (count items) line is missing a closing paren. Funny how often I figure out problems immediately after I ask someone else online (Even without help) :thinking_face: But, are there any standard debugging/helper tools I'm supposed to use?

noisesmith03:11:39

@duminda aha! that if is broken

noisesmith03:11:50

you pass too many args to pos?, so the if returns nil

noisesmith03:11:45

@duminda no, my experience is that bugs with data passed to react lead to verbose and completely unhelpful error messages

noisesmith03:11:27

because of the way react sets up rendering, it doesn't have a way to provide info about where the data it is rendering from came from in your code

noisesmith03:11:38

or that's what I am led to believe

nakiya03:11:40

@noisesmith: Yeah, I had quite a few during yesterday. But they are totally useless - I agree.

nakiya03:11:07

Ok, guess I have to live with it

noisesmith03:11:25

one thing that can help a lot is unit testing your components with representative data - at least then you know precisely which thing was being tested when the failure happened

noisesmith03:11:13

you can make a test that mounts just that component to the dom, then makes assertions about the results

noisesmith03:11:23

see also dev-cards, from the guy who made figwheel

noisesmith03:11:45

similarly, it leads you to develop things one working part at a time, which makes it clear where the errors are

nakiya03:11:28

Got it, I tried out spec, I was under the impression that it can sort of auto-generate tests... Anyway, I didn't want to write tests right now because I'm just feeling out how this works. But guess I have no choice now

nakiya03:11:52

As always, thanks for your help @noisesmith

noisesmith03:11:30

you can totally get by without writing tests - but they help, and dev-cards can actually speed up your dev process

noisesmith03:11:48

because instead of building a whole component then rendering your page, you can try out the smaller parts one by one

swizzard15:11:44

so i've gotten started with lumo and i really like it, but i want to pull in specter (https://github.com/nathanmarz/specterhttps://github.com/nathanmarz/specter) and i'm not entirely sure how (best) to do that in the absence of a lein project.clj

swizzard15:11:06

especially in a self-contained/repeatable kind of way

Drew Verlee20:11:28

is there a core function that describes applying a series of clauses where the clause is a [pred f] and f is applied only if the pred passes? e.g

(??? {:age 5 :name "sally"}
       :age (fn [x] (update-in x [:age] inc)
       :name (fn [x] (update-in x [:name] (str "silly-" %)))
=> {:age 6 :name "silly-sally"}

Alex Miller (Clojure team)20:11:12

cond-> is kind of like that

Alex Miller (Clojure team)20:11:35

It’s good for this kind of data structure manipulation

Alex Miller (Clojure team)20:11:16

It threads so you would omit the x on the rhs

Alex Miller (Clojure team)20:11:16

(cond-> m :age (update :age inc) :name (update :name #(str “silly-“ %)))

Alex Miller (Clojure team)20:11:17

Matches don’t stop the threading so the fns are applied for all matching preds

Drew Verlee20:11:07

Yep, that looks like what i want. Thanks alex.

noisesmith20:11:56

also, if you need to see consequences of the previous step in your conditional, you can chain multiple calls to cond-> inside ->, or use as->

Drew Verlee20:11:56

Thanks @noisesmith. Thats what i was doing already for other reasons, but i didn't know that was necessary tell you said as much. minor note, the predict functions of the clauses in cond-> aren't sent the expression. So you need to pass it directly.

(cond-> m
 (contains? m :age) (update :age inc)
 :name (update :name #(str “silly-“ %)))
Otherwise the text expression is just the keyword and thats always true

Alex Miller (Clojure team)21:11:44

Yeah, sorry about that!

noisesmith20:11:33

right, that too 😄

noisesmith20:11:59

so often what I really want is (as-> m (cond-> (contains? m :foo) (update :foo inc)) (cond-> (contains? m :bar) (update :bar dec))) or similar

Drew Verlee21:11:43

I'm i correct that https://github.com/pallet/alembic should allow me to add jar to my project and not need to restart my repl? or i'm i mis-understanding it?

noisesmith21:11:04

yes, it has a function that loads deps from an edited project.clj