Fork me on GitHub
#beginners
<
2020-01-13
>
jplfdsilva02:01:10

hi folks, what's a good book/tutorial/course on Reagent? I was thinking about something in the lines of creating an app end-to-end.

zdot10104:01:30

I don't myself but just curious, is there any particular app you'd like to see made? I'd like to perhaps keep it in mind if I ever find the time to write one myself

jplfdsilva13:01:23

thanks @! will look into those.

jplfdsilva13:01:21

@ I prefer tutorials where the goal is to build an app using an specific technology/framework. The more features of the framework are used, the better but the goal is to have an working app at the end. I've seen many tutorials where the authors focus on showing specific features of the framework but they fail on showing the flow/journey of creating an app.

jplfdsilva13:01:50

some of the things I'd expect to see in a beginners tutorial are: 1. set up the environment 2. how to structure your code in terms of folders and files 3. if the tutorial is focusing on the frontend it would still be nice to show a little bit of the backend implementation (even if all endpoints have their responses hardcoded). 4. how to write tests 5. authentication/authorization

carl.waerner19:01:29

@ I agree with you that many tutorials fail to show the entire process in building an app. I'm following this thread, hopefully someone will know! 🙂

jplfdsilva02:01:28

re-frame would be a plus but not required at the moment

ericihli12:01:54

What does ClojureScript do with namespaced keywords? (clj->js {:foo/bar "baz"}) == #js {:bar "baz"} #js {:foo/bar "baz"} == > Failed to read input: clojure.lang.ExceptionInfo: JavaScript literal keys must be strings or unqualified keywords {:type :reader-exception, :line 1, :column 21, :file "repl-input.cljs"} I'm trying to do navigation with ReactNavigation and use keywords as route keys and I'm curious if routes like {:home/settings ...} and {:user/settings ...} will end up conflicting, or if there will be any gotchas, like how do I access those using JS interop rather than directly as a clojure map? It looks like the JS interop just drops the namespace part of the keyword. Wouldn't that create a clash?

ericihli17:01:26

Found the answer to this myself by reading the description of clj->js and js->clj. Can pass an optional function to specify how keywords should be converted to JavaScript. The default function is just name.

mathpunk17:01:18

I'm using macros in anger for the first time and I appear to be holding something wrong---

mathpunk17:01:33

(defmacro defcountquery
      "Counts for things that we index"
      [token-name]
      `(db/defquery ~(symbol  token-name) (str "MATCH (x:" ~token-name ") RETURN count(*)") ))

mathpunk17:01:46

where db/defquery is a macro given to me by the authors of neo4j-clj

mathpunk17:01:57

This will work now:

(defcountquery "User")
    (with-open [session (db/get-session local-db)]
      (User session))

mathpunk17:01:10

But this will not:

mathpunk17:01:13

(let [entity "ValueMap"]
      (defcountquery entity)
      (with-open [session (db/get-session local-db)]
        ((symbol entity) session)))

mathpunk17:01:46

Note: I don't entirely follow why the neo4j-clj library requires you to wrap that string query with their defquery macro

carl.waerner19:01:02

Hello everyone! I am Carl from Sweden and completely new to Clojure(script). I really need HELP! I did web development with PHP many years ago but I kind of stopped around 2010. I've been itching to get back in the game but all the javascript libraries etc etc just makes me really overwhelmed. I then found Clojure and it feels a lot more approachable...I've read and watched tons about Clojure and I really feel that this what I want to learn. However I am struggling to find "a workflow" I really enjoyed the tutorial on figwheel (very clear, and more importantly it doesn't presume that I know stuff that I don't) and I'm up and running with that now. I've decided I want to build a "Contacts" web app as my first project. I know what needs to be done: I need to make an interface where I can input data (name, email, phone number, notes) -> store that data -> read it and display it in the browser. But I'm stuck. I don't even know how to inject html into my website (do I use hiccup dependency?) so my question would be: where do I go from here? Is there any tutorial that you guys know of that I could follow, any book I should read? Or could I just ask all the questions here in Slack? Also, if someone wants to be my mentor until I can stand on my own legs, it would be so appreciated and welcomed! :relaxed:

noisesmith19:01:30

as someone who has worked on multiple end-to-end clojure/cljs webapps for all the domain specific stuff, I recommend this book https://pragprog.com/book/dswdcloj3/web-development-with-clojure-third-edition

noisesmith19:01:55

it makes a bunch of "arbitrary" decisions about libs / techniques to use, and last I checked they are all reasonable defaults

noisesmith19:01:58

it will likely be helpful to get more familiar with Java webapp conventions as you go, but don't dive deep on that, clojure avoids a lot of the Java complexity (Spring etc.) without losing features

papachan20:01:28

when you have something done you can share your code at #code-reviews

pavel.klavik23:01:02

I would start just with a front-end app (keeping everything in memory) and use reagent + re-frame, both have excellent documentation online. For compilation, I would use shadow-cljs since it is really simple to setup. You could even base everything from our sample client made for introducing people to Clojurescript: https://github.com/ReOrgpad/example-client

michael.e.loughlin20:01:09

is there a reduce-right of some form in clojure.core?

ghadi20:01:30

to be honest it never comes up

ghadi20:01:45

you can reduce over a vector backwards with (reduce f init (rseq [1 2 3 4 5]))

michael.e.loughlin20:01:05

I ask because I want the best of both worlds - a seq I can use with assoc-in , but reduce over the last conj'd item first

michael.e.loughlin20:01:13

rseq might do the job, thanks :+1:

ghadi20:01:37

a seq I can use with assoc-in ?

michael.e.loughlin20:01:44

well it doesnt need to be a seq

ghadi20:01:03

can you show some example data?

noisesmith20:01:57

it sounds like a vector plus rseq does what you want from reduce-right (cheap access to the most recent value)

michael.e.loughlin20:01:44

(assoc-in 
         [["blahblah 1" {"my-key" 0}] ["blahblah 0" {"my-other-key" 101}]]
         [0 1 "my-key"]
         "some-value"))
=> [["C:\\temp\\db\\1" {"my-key" "some-value"}] ["C:\\temp\\db\\0" {"my-other-key" 101}]]

ghadi20:01:04

conj to a list goes to the front: (update {:a '(1 2 3)} :a conj 0) => {:a (0 1 2 3)} Another way is ^

michael.e.loughlin20:01:17

but I'd like to effectively push to the start of the vec

ghadi20:01:21

then you can reduce ordinarily

michael.e.loughlin20:01:38

which I understand is not possible

michael.e.loughlin20:01:20

I'll be performing assoc-in 99% of the time, and reduce the other 1%

noisesmith20:01:33

in that case, you could use a fully indexed representation (eg. hash-map with numbers as keys) and use sort-by key / map val in the reduce step

ghadi20:01:04

assoc-in with positional things is uncommon too

ghadi20:01:36

you may want to consider @noisesmith’s suggestion to rework the representation

michael.e.loughlin20:01:33

I'd like to try and be idiomatic with Clojure standards, so I'll try reworking it

hiredman21:01:32

you could also rewrite your reduce to be commutative so foldr and foldl would preduce the same results

hiredman21:01:32

you could also rewrite your reduce to be commutative so foldr and foldl would preduce the same results

andy.fingerhut21:01:34

Should that be associative instead of commutative? Not finished with my first coffee of the day yet, so I could be off there.

hiredman21:01:28

better be safe and make it both 🙂