Fork me on GitHub
#beginners
<
2019-09-30
>
Dan11:09:02

If I define a button component like so:

(defn button [props & children]
  [:button {:type props} children])
And then render the button like so
[button {:type "button"} "Button"]
The rendered HTML is type="[object Object]" - what am I doing wrong?

delaguardo11:09:25

because you are passing {:type "button"} as a props into component. this end up with {:type {:type "button"}}

delaguardo11:09:59

and then renderer converting provided type into string. in JS world trying to stringify object will give you that string "[object Object]"

manutter5111:09:15

You want [:button (:type props)...

šŸ‘ 4
Dan11:09:18

This is the same even with Reagent?

Dan11:09:17

This is working for me [:button (assoc props) children]

delaguardo12:09:39

(assoc props) ;; => props

delaguardo12:09:25

if you are making a component that is using props passed as an argument - you can leave it as is: (defn button [props & children] [:button props children]) but I can not see any reason to do that)

solf12:09:12

Quick question: is it idiomatic to use a map as first argument of remove? Like this: (remove {:foo 42 :bar 50} [:foo :hello :bar]) ;; => (:hello) I thought it was, but clj-kondo highlights that as an error

borkdude12:09:36

@dromar56 That's probably a false positive in kondo

delaguardo12:09:39

this is idiomatic since map is a function in clojure: ({:foo 1} :foo) ;; => 1

solf12:09:57

Okay thanks, that's what I thought but I had my doubts

solf12:09:02

I was thinking, now that I've finally internalized that sets and maps are functions in clojure, I'm trying to shoe horn them everywhere šŸ˜›

borkdude12:09:23

@dromar56 I'm make an issue for this. Thanks for reporting

borkdude12:09:16

huh wait, I don't get a false positive with this:

$ clj-kondo --lint - <<< '(remove {:a 1} [:a :b])'
linting took 25ms, errors: 0, warnings: 0

borkdude12:09:16

So not sure why you are getting one.

borkdude12:09:22

@dromar56 Can you give me a reproduction?

solf12:09:58

I can't seem to find a smaller case that reproduces the error

solf12:09:21

So here's the actual function where it happens:

borkdude12:09:24

Can you test this from your command line and then past that here?

solf12:09:28

clj-kondo --lint - <<< '(defn crawler [url results] (let [data {:foo 42} results (assoc results url data)] (if (seq data) (let [links (remove results (:links data))] (reduce (fn [results url] (if-not (get results url) (crawler url results) results)) results links)) results)))'

solf12:09:43

I do get

<stdin>:1:119: error: Expected: function, received: associative collection.
linting took 9ms, errors: 1, warnings: 0

borkdude12:09:32

I see the issue now. Thank you.

borkdude12:09:59

This is a small repro of it: (remove (assoc {} :a 1) [:a])

solf12:09:21

Yes indeed. Also, I'm in the middle of watching your recent talk and decided to install clj-kondo before even finishing. So far it's great!

borkdude12:09:48

Cool! I made an issue here: https://github.com/borkdude/clj-kondo/issues/479 It will be fixed in the next release, I'm pretty sure.

šŸ‘ 4
borkdude14:09:09

If you're interested in a binary with a fix, let me know. You can also build it yourself from master.

tdantas15:09:34

hey, design question, should my repository namespace validate ( using spec ) the params which is going to DB or service layer should do that ?

borkdude15:09:55

Personally I would do it as close to the storage for which you're validating as possible. If possible even inside the db itself.

tdantas15:09:29

yeah, sometimes I think to validate on my system boundaries ( http handler ) , other on database layer assuming that my code ( service layer ) gonna produce the proper data to be inserted

tdantas15:09:01

@borkdude so your http handler do not validate nothing ? you pass to database namespace to handle ?

borkdude15:09:09

That could also work. You can also validate extra stuff only in dev, just to get some extra sense of what's going on

borkdude15:09:35

The classical answer to these kinds of questions is: it depends.

tdantas15:09:42

yeah šŸ˜„

tdantas15:09:51

agree 100%

borkdude15:09:59

We do validate/coerce incoming data from http. For storing fields to a SQL db we use HugSQL which errors on absent keys, for jsonb blobs I usually do a select-keys to ensure no extra crap gets saved beyond what I'm interested in

borkdude15:09:32

On the DB level we have non-nillable fields which also protects you from stupid errors.

borkdude15:09:39

I think I had some extra spec checking on the DB level just to ensure things didn't break when I changed anything to my code. But that's turned off in prod

borkdude15:09:16

I think it mostly comes down to what works for you šŸ™‚

tdantas15:09:37

yeah, agree 100% with you .. first time I wrote I had spec on every function, currently Iā€™m conforming/coercing only on http handlers . everything inside Iā€™m leaving without spec ( but yeah, sometimes Iā€™m falling on stupid errors as you said )

walterl15:09:40

from a security perspective: always be validating. i.e. validate at all system (component) boundaries. firstly, the schema of the data provided via http is not always the same as what the db wants. so the validation won't be checking for the same things. if you don't validate both schemas... schema ambiguities/mismatches are where encoding/injection bugs breed. another reason to validate multiple times, is the often false assumption that data will only come from a specific source, like http. i've been bitten by that a few times. e.g. adding a plugin framework to a system bypasses the http api and its validation. now there's a new vector for injecting invalid and unvalidated data into the system. validation at the db would help in that case, but i would still think that's not quite enough. tl;dr: data crossing all boundaries should ideally be validated

zav18:09:59

Hey, whats the most used clojure lib for building a desktop gui? I'm not looking to get into anything crazy, just need a directory input, a file input, and a button that will work on linux and window 7/10

noisesmith18:09:17

three popular gui options are cljs with react in electron, clojure with seesaw (swing), and clojure with fnfx (javafx)

noisesmith18:09:41

I think there might be another good javafx option but the name isn't coming ot me

noisesmith18:09:05

aha, that's the other one, thanks

zav19:09:25

@noisesmith @borkdude thanks guys, I'll check them out

bartuka23:09:40

I just defined a tuple entity in datomic. I'm using the free on-memory spec

{:db/ident :dados/external-id-name
           :db/valueType :db.type/tuple
           :db/tupleAttrs [:dados/external-id :dados/name]
           :db/cardinality :db.cardinality/one
           :db/unique :db.unique/value}
but when I transact to database I got an :db.error/not-an-entity Unable to resolve entity: :db/tupleAttrs

andy.fingerhut23:09:00

There is a #datomic channel that might have more participants able to help you with questions on Datomic.

bartuka23:09:19

thanks @andy.fingerhut I will post it there.