Fork me on GitHub
#clojurescript
<
2022-06-27
>
Saurabh02:06:09

Does anyone know where this init_BANG_() comes from in this reagent template? https://github.com/reagent-project/reagent-template/blob/master/resources/leiningen/new/reagent/src/clj/reagent/handler.clj#L27 I have tried to search it for on google and the shadow-cljs documentation but can’t find anything about it.

pinkfrog02:06:53

what is _BANG_ ? If it’s exclamation mark, then I’d search init!

Saurabh02:06:25

Do you know why we need the _BANG_ though? What would be wrong with just .core.init!()?

Saurabh02:06:04

Oh, it’s because ! isn’t valid in JS identifiers, so it’s replaced with _BANG_ by the cljs compiler https://groups.google.com/g/clojure/c/jeg3LdDQnaU/m/F51jMVxKia0J

Ernesto Garcia07:06:54

Hi, is there a way to avoid Cursive warn about symbols "cannot be resolved" when calling JS functions/properties from ClojureScript?

p-himik07:06:45

No, it's a known issue.

👍 1
pinkfrog09:06:06

I am encountering the missing key issue in reagent.

[23069:0627/170711.447175:INFO:CONSOLE(451)] "Warning: Every element in a seq should have a unique :key: ([app.view.sidebar_item 3] [app.view.sidebar_item 3])
 (in app.view.panes)", source: js/cljs-runtime/reagent.impl.template.js (451)
the app.view.sider_bar is a form-1 function. Where shall I pass the :key prop?

reefersleep09:06:17

Pass it however you like, just make sure that it’s consistent for the identity of each element. Then use either metadata or a :key in the attributes map, e.g.

(map (fn [my-element-txt]
  ^{:key my-key} [:div my-element-txt])
  my-element-txts)
or
(map (fn [my-element-txt]
  (with-meta [:div my-element-txt] {:key my-key})
  my-element-txts)
or
[:div {:key my-key} my-element-txt]

reefersleep09:06:12

e.g. if you know that my-element-txt is unique for each item above, you can use that instead of my-key

reefersleep09:06:37

but the re-frame guys have probably written an excellent article on the matter, they tend to do that 🙂

pinkfrog10:06:11

Thanks. However your reply is based on :div hiccup form. I have the following questions: 1. What about form-1 function. I am not sure if meta data works on form-1. Also, I didn’t spot any docs related with it on https://cljdoc.org/d/reagent/reagent 2. For the form [form-1-fn {:key my-key} my-element-txt] , does that mean reagent will always take it for granted that the first argument of a function serves as the props map of a react component renderer function?

p-himik11:06:33

The metadata approach works on Hiccup vectors, not components. If the second value in the Hiccup vector is a map, Reagent will check if it has :key. But the metadata takes the precedence. Also, you don't really need keys if you turns seqs into vectors. It doesn't always make sense, but often it does.

Fahd El Mazouni09:06:53

Hey ! what's your favorite forms library ? (do you even use one)

augustl13:06:03

I personally avoid form libraries like the plague 🙂

Fahd El Mazouni13:06:08

Tried rolling my own, but I don't think i have enough experience to get it right, ended up converging on something looking a lot like fork so I think it's a good idea to just use it

augustl13:06:10

I also try to not roll my own, I prefer the fiexibility of just writing the forms by hand and having various tools at hand for doing repetitive tasks. I make little effort to keep forms DRY 🙂

dvingo18:06:10

there's some interesting hook based libs (assuming you're using react) https://github.com/unform/unform https://react-hook-form.com/get-started#Quickstart

Fahd El Mazouni08:07:51

thanks for the suggestions guys !

vlad_poh16:06:19

Is there a clojurescript course/resource that walks you through ui/ux css basics? Typography, colors, structuring a frontend etc

p-himik16:06:33

Why would it be CLJS though? Sounds like it's purely about CSS, and there are tons of materials there.

dvingo16:06:30

Agreed, not sure conflating cljs with those topics makes sense. These two resources are good for cljs though: https://www.learn-clojurescript.com/table-of-contents/ https://funcool.github.io/clojurescript-unraveled/

dvingo16:06:36

the capstone projects in learn-clojurescript might be what you're looking for

p-himik16:06:33

Thumbsdown on the first link. There have already been a few confused people here while trying to go through that book. It expects you to know some concepts without making it explicit. The accompanying code is not great and is just confusing. Those are just the things that I can immediately remember.

dvingo16:06:02

ooh good to know - I have it on my todo list to go through it myself

p-himik16:06:35

It might be alright if you're a somewhat experienced developer. But at that point, that book is probably too basic.

vlad_poh17:06:16

@p-himik agreed that there a ton of resources out there but the clojure way of thinking and doing things has a special allure to me. Alex Miller’s clojure applied or Zach’s Elements of Clojure are nice examples. I would love a David Nolen book on the Elements of Web Design that covers stuff like this.

vlad_poh17:06:16

@p-himik agreed that there a ton of resources out there but the clojure way of thinking and doing things has a special allure to me. Alex Miller’s clojure applied or Zach’s Elements of Clojure are nice examples. I would love a David Nolen book on the Elements of Web Design that covers stuff like this.