Fork me on GitHub
#clojurescript
<
2019-11-21
>
MorongÖa10:11:46

I have just added a new library(taoensso/tempura ) to my Clojurescript project. In advanced compilation I get a warning with 'unreachable-code'. Do I need to write an 'extern' for this?

Karol Wójcik11:11:35

Such updates on Clojurescript make me smile (1.10.520 1,857,158 bytes -> 1.10.597 1,779,276 bytes). 👍

Mario C.18:11:28

I am using Semantic UI in a Reagent/Re-frame project. I have a data list that I would like to put inside an accordion component. An accordion is composed of a series of [:> Accordion.Title "First Title"] [:> Accordion.Content "First content"] inside a [:> Accordion ...]The issue I am having is that when I am mapping over the data set. Using map-index I'd have to wrap those two components in a [:div] to prevent the mapping from only returning the last element. Doing so prevents the accordion from working. How can I go about this?

Derek Passen18:11:18

Seems like you want a React fragment. I assume reagent has support for emitting those

👍 4
Mario C.19:11:48

Exactly what I was looking for! Thank you

Aleks Abla20:11:46

Hey folks, hope your thursdays are going great -- I am continuing to work on my re-frame project. I've ran into a tricky problem -- I am struggling to figure out how to dispatch marked selections into db. Here is how the app looks and code is below. The idea here is that a user selects attributes, from which the pull data button will slurp a csv out of the db based on their seleciton.

Aleks Abla20:11:08

the idea here is that after selecting a one (or multiple) headers, the app db gets updated. each column has its own map in db. so for the above marked example, the end resulting db would be. not sure where to attach the dispatch function in this case.

{:firm-type {"sellside"}
:firm-info {"shorthand"}
:user-info {"full-name"}
:visibility {"not-visible"}
:focuses {"asset-class"}}

p-himik21:11:11

So, what is the problem?

Aleks Abla21:11:17

I am not sure where in my code should I register the dispatch so it maps values in db.

Aleks Abla21:11:42

[:select {:multiple "multiple"} (for [val focuses] [:option val])]]

Aleks Abla21:11:07

I assume we would have a dispatch here but i can't seem to make it work

Aleks Abla21:11:39

will do, thanks zhenya 🙂

p-himik21:11:50

Also, your for loops that create options will likely generate a React warning about them missing keys.

Aleks Abla21:11:07

yes they do, nice!!

p-himik21:11:51

Since the lists of all the options are short, just use into:

(into [:select {:multiple "multiple"}]
  (map #(vector :option %))
  options)

Aleks Abla21:11:08

from here, where would I attach the :on-click dispatch event?

p-himik21:11:33

You don't need on-click per option, you need on-change for the whole select. So, near :multiple. It also probably won't hurt to read through Reagent documentation and examples.

Aleks Abla21:11:34

awesome i'll give it a shot.. yea I am very new not only to anything clojure, but also software dev.. yikes

Aleks Abla21:11:45

appreciate the help a lot!

p-himik21:11:26

No problem. You've made the right choice by deciding to go with Clojure. :)

ec20:11:10

Why do li gets wrapped in seq? (map-to-html-list {:NESTED {:LIST [1 2]}}) returns [:ul ([:li :NESTED [:ul ([:li :LIST [:ul ([:li 1] [:li 2])]])]])]

dpsutton20:11:21

for returns a collection

👍 4
dpsutton20:11:54

(for [x (range 3)] [:li x]) #_ -> ([:li 0] [:li 1] [:li 2])

dpsutton20:11:28

(into [:ul] (for [x (range 3)] [:li x])) #_ -> [:ul [:li 0] [:li 1] [:li 2]]

Nima G22:11:28

Hello everyone, sorry if this has been answered a bazilion times but what's the quickest way to integrate npm dependencies into an existing leiningen/figwheel project? I found https://github.com/RyanMcG/lein-npm but I know some people are using shadow-cljs with lein. (I would like to add fullpage.js [https://github.com/alvarotrigo/fullPage.js] to an app i'm building)

p-himik10:11:09

Yep, I switched to shadow-cljs+deps quite some time ago, haven't looked back since.

👍 4
p-himik10:11:00

Given what a friend shows me sometimes (he's a pure JS developer), working with shadow-cljs and NPM is even easier than it's in the JS world.

alekszelark22:11:37

Hi! I’m trying to catch an exception with try-catch block, but it’s failing. Here is a code

(defn on-navigate [new-match]
  (when new-match
    (let [params (try
                   (reitit.coercion/coerce! new-match)
                   (catch :default _
                     {}))
          new-match' (assoc new-match :params params)]
      (rf/dispatch [:set-current-route new-match']))))
Can someone help?

lilactown22:11:13

trying changing :default to js/Object?

lilactown22:11:25

otherwise, it might be that it’s not throwing inside of coerce! but somewhere else?

alekszelark22:11:43

yes, it didn’t help

dpsutton22:11:30

what convinces you that this code is what is throwing the error/

alekszelark22:11:26

The exception type :reitit.coercion/request-coercion.

alekszelark22:11:56

And if I throw the coercion away, everything is ok.

dpsutton22:11:43

can you get a stack trace?

dpsutton22:11:43

is it possible there's a lazy seq in your new-match' and that's forced later outside of this try/catch?

dpsutton22:11:51

can you try this at the repl?

alekszelark22:11:14

Yes I tried it in the repl, it works

alekszelark22:11:39

Don’t know why but it points to re-frame.router

thetalogn22:11:46

Hey, how can I embed javascript code in hiccup, for example the google analytics code?

Nima G22:11:04

hiccup.page/include-js might be what you're looking for

👍 4
thetalogn22:11:33

not exactly what I'm looking for

Nima G22:11:54

[:script {:src ...} "your-js-code"]? 🤪

thetalogn23:11:06

I've got something like this: window.dataLayer = window.dataLayer || []; function gtag () { dataLayer.push(arguments); } gtag('js', new Date()); And putting it in a string didn't work

Nima G23:11:30

Maybe put that code into it's own .js file (in assets or something), then do hiccup.page/include-js

thetalogn23:11:53

@UQP5ZFTD2 thanks, haven't thought about that

john-shaffer23:11:16

[:script "..."] should work. What HTML do you get?

thetalogn23:11:49

gtag(&#x27;js&#x27;, new Date());

john-shaffer23:11:41

What version of hiccup are you using?

thetalogn23:11:11

@UQ5EVP2LW I am using this library https://github.com/roman01la/uix, which uses it, I can't find the version though

john-shaffer23:11:01

Okay, it's using Hiccup syntax but very likely not the actual Hiccup library, so it's behavior is a little different and it probably auto-escapes by default for security reasons

john-shaffer23:11:38

This will probably work

john-shaffer23:11:15

[:script {:dangerouslySetInnerHTML {:html ".....your javascript..."}}]

john-shaffer23:11:14

It's based on Rum apparently. This is what I use for Rum:

john-shaffer23:11:32

(defn raw-html ([s] (raw-html :div nil s)) ([tag s] (raw-html tag nil s)) ([tag attrs s] [tag (assoc attrs :dangerouslySetInnerHTML {:html s})]))

💯 4
thetalogn23:11:34

great thanks, sorry about the confusion

alekszelark22:11:24

And the exception comes from coerce!

Jakub Zika08:11:38

Hi, is this an Emacs? I have never seen similar stacktrace. What setup so you use?

alekszelark19:11:14

Hi! It’s just dev tools console in google chorme.

Jakub Zika21:11:05

Nice, I should try CLJS more. Thanks!

alekszelark22:11:24

routes=> 
(try (reitit.coercion/coerce! (rt/match-by-name router :campaign {:id "b"})) (catch :default e "heh"))
"heh"
routes=> 

alekszelark23:11:10

and

routes=> 
(on-navigate (rt/match-by-name router :campaign {:id "b"}))
nil

alekszelark23:11:25

So there is no exception from the repl

alekszelark23:11:15

Yeah, it turned out the exception is throwing from another place.